mirror of
https://github.com/labring/sealos.git
synced 2026-09-01 15:38:06 +08:00
Terminal controller support cors. (#2991)
Signed-off-by: zzjin <tczzjin@gmail.com>
This commit is contained in:
@@ -17,6 +17,7 @@ limitations under the License.
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
apisix "github.com/apache/apisix-ingress-controller/pkg/kube/apisix/apis/config/v2beta3"
|
||||
@@ -32,14 +33,20 @@ const (
|
||||
)
|
||||
|
||||
func (r *TerminalReconciler) createNginxIngress(terminal *terminalv1.Terminal, host string) *networkingv1.Ingress {
|
||||
cors := fmt.Sprintf("https://%s,https://*.%s", r.terminalDomain, r.terminalDomain)
|
||||
|
||||
objectMeta := metav1.ObjectMeta{
|
||||
Name: terminal.Name,
|
||||
Namespace: terminal.Namespace,
|
||||
Annotations: map[string]string{
|
||||
"kubernetes.io/ingress.class": "nginx",
|
||||
"nginx.ingress.kubernetes.io/rewrite-target": "/",
|
||||
"nginx.ingress.kubernetes.io/proxy-send-timeout": "86400",
|
||||
"nginx.ingress.kubernetes.io/proxy-read-timeout": "86400",
|
||||
"kubernetes.io/ingress.class": "nginx",
|
||||
"nginx.ingress.kubernetes.io/rewrite-target": "/",
|
||||
"nginx.ingress.kubernetes.io/proxy-send-timeout": "86400",
|
||||
"nginx.ingress.kubernetes.io/proxy-read-timeout": "86400",
|
||||
"nginx.ingress.kubernetes.io/enable-cors": "true",
|
||||
"nginx.ingress.kubernetes.io/cors-allow-origin": cors,
|
||||
"nginx.ingress.kubernetes.io/cors-allow-methods": "PUT, GET, POST, PATCH, OPTIONS",
|
||||
"nginx.ingress.kubernetes.io/cors-allow-credentials": "false",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -156,7 +156,7 @@ func (r *TerminalReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
|
||||
|
||||
func (r *TerminalReconciler) syncIngress(ctx context.Context, terminal *terminalv1.Terminal, hostname string) error {
|
||||
var err error
|
||||
host := hostname + r.terminalDomain
|
||||
host := hostname + "." + r.terminalDomain
|
||||
switch terminal.Spec.IngressType {
|
||||
case terminalv1.Nginx:
|
||||
err = r.syncNginxIngress(ctx, terminal, host)
|
||||
@@ -466,7 +466,7 @@ func getSecretNamespace() string {
|
||||
// SetupWithManager sets up the controller with the Manager.
|
||||
func (r *TerminalReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||
r.recorder = mgr.GetEventRecorderFor("sealos-terminal-controller")
|
||||
r.terminalDomain = "." + getDomain()
|
||||
r.terminalDomain = getDomain()
|
||||
r.secretName = getSecretName()
|
||||
r.secretNamespace = getSecretNamespace()
|
||||
r.Config = mgr.GetConfig()
|
||||
|
||||
Reference in New Issue
Block a user