From efbda9539f481b5833fe81ff4c444413c9ef3eae Mon Sep 17 00:00:00 2001 From: yy <56745951+lingdie@users.noreply.github.com> Date: Tue, 23 Apr 2024 10:19:19 +0800 Subject: [PATCH] chore: fix controller config lint. (#4702) * chore: fix controller config lint. Signed-off-by: yy Signed-off-by: yy * chore: fix controller config lint. Signed-off-by: yy Signed-off-by: yy * chore: fix controller config lint. Signed-off-by: yy Signed-off-by: yy * chore: fix controller config lint. Signed-off-by: yy Signed-off-by: yy * chore: fix controller config lint. Signed-off-by: yy Signed-off-by: yy * chore: fix license. Signed-off-by: yy Signed-off-by: yy --------- Signed-off-by: yy --- controllers/pkg/config/global.go | 32 +++++++++++++----- controllers/terminal/controllers/config.go | 16 ++++++++- controllers/terminal/controllers/ingress.go | 2 +- .../controllers/terminal_controller.go | 33 ------------------- .../deploy/manifests/deploy.yaml.tmpl | 2 +- controllers/user/controllers/config.go | 14 ++++++++ controllers/user/main.go | 5 +-- 7 files changed, 55 insertions(+), 49 deletions(-) diff --git a/controllers/pkg/config/global.go b/controllers/pkg/config/global.go index 74ccc8107..d6a1d4fcc 100644 --- a/controllers/pkg/config/global.go +++ b/controllers/pkg/config/global.go @@ -1,7 +1,21 @@ +// Copyright © 2024 sealos. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package config import ( - "io/ioutil" + "os" "gopkg.in/yaml.v3" ) @@ -9,29 +23,29 @@ import ( type Global struct { CloudDomain string `yaml:"cloudDomain"` CloudPort string `yaml:"cloudPort"` - RegionUid string `yaml:"regionUid"` + RegionUID string `yaml:"regionUID"` CertSecretName string `yaml:"certSecretName"` } type Kube struct { Version string `yaml:"version"` - ApiServerHost string `yaml:"apiServerHost"` - ApiServerPort string `yaml:"apiServerPort"` + APIServerHost string `yaml:"apiServerHost"` + APIServerPort string `yaml:"apiServerPort"` } type Common struct { GuideEnabled string `yaml:"guideEnabled"` - ApiEnabled string `yaml:"apiEnabled"` + APIEnabled string `yaml:"apiEnabled"` } type Database struct { - MongodbUri string `yaml:"mongodbUri"` - GlobalCockroachdbUri string `yaml:"globalCockroachdbUri"` - RegionalCockroachdbUri string `yaml:"regionalCockroachdbUri"` + MongodbURI string `yaml:"mongodbURI"` + GlobalCockroachdbURI string `yaml:"globalCockroachdbURI"` + RegionalCockroachdbURI string `yaml:"regionalCockroachdbURI"` } func LoadConfig(path string, target interface{}) error { - configData, err := ioutil.ReadFile(path) + configData, err := os.ReadFile(path) if err != nil { return err } diff --git a/controllers/terminal/controllers/config.go b/controllers/terminal/controllers/config.go index 49d719a51..9b9e9a757 100644 --- a/controllers/terminal/controllers/config.go +++ b/controllers/terminal/controllers/config.go @@ -1,3 +1,17 @@ +// Copyright © 2024 sealos. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package controllers import ( @@ -10,5 +24,5 @@ type Config struct { } type TerminalConfig struct { - IngressTlsSecretName string `yaml:"ingressTlsSecretName"` + IngressTLSSecretName string `yaml:"ingressTLSSecretName"` } diff --git a/controllers/terminal/controllers/ingress.go b/controllers/terminal/controllers/ingress.go index 3e341f1f3..5f51091e5 100644 --- a/controllers/terminal/controllers/ingress.go +++ b/controllers/terminal/controllers/ingress.go @@ -78,7 +78,7 @@ func (r *TerminalReconciler) createNginxIngress(terminal *terminalv1.Terminal, h tls := networkingv1.IngressTLS{ Hosts: []string{host}, - SecretName: r.CtrConfig.TerminalConfig.IngressTlsSecretName, + SecretName: r.CtrConfig.TerminalConfig.IngressTLSSecretName, } ingress := &networkingv1.Ingress{ diff --git a/controllers/terminal/controllers/terminal_controller.go b/controllers/terminal/controllers/terminal_controller.go index 2a989e70f..0ad83c324 100644 --- a/controllers/terminal/controllers/terminal_controller.go +++ b/controllers/terminal/controllers/terminal_controller.go @@ -18,7 +18,6 @@ package controllers import ( "context" - "os" "time" "github.com/jaevor/go-nanoid" @@ -372,38 +371,6 @@ func isExpired(terminal *terminalv1.Terminal) bool { return lastUpdateTime.Add(duration).Before(time.Now()) } -func getDomain() string { - domain := os.Getenv("DOMAIN") - if domain == "" { - return DefaultDomain - } - return domain -} - -func getPort() string { - port := os.Getenv("PORT") - if port == "" { - return DefaultPort - } - return port -} - -func getSecretName() string { - secretName := os.Getenv("SECRET_NAME") - if secretName == "" { - return DefaultSecretName - } - return secretName -} - -func getSecretNamespace() string { - secretNamespace := os.Getenv("SECRET_NAMESPACE") - if secretNamespace == "" { - return DefaultSecretNamespace - } - return secretNamespace -} - func (r *TerminalReconciler) getPort() string { if r.CtrConfig.Global.CloudPort == "" || r.CtrConfig.Global.CloudPort == "80" || r.CtrConfig.Global.CloudPort == "443" { return "" diff --git a/controllers/terminal/deploy/manifests/deploy.yaml.tmpl b/controllers/terminal/deploy/manifests/deploy.yaml.tmpl index 8c4d851f6..4ea51114f 100644 --- a/controllers/terminal/deploy/manifests/deploy.yaml.tmpl +++ b/controllers/terminal/deploy/manifests/deploy.yaml.tmpl @@ -350,7 +350,7 @@ data: cloudDomain: {{ .cloudDomain }} cloudPort: {{ if .cloudPort }}:{{ .cloudPort }}{{ end }} terminalController: - ingressTlsSecretName: {{ .wildcardCertSecretName }} + ingressTLSSecretName: {{ .wildcardCertSecretName }} kind: ConfigMap metadata: name: terminal-manager-config diff --git a/controllers/user/controllers/config.go b/controllers/user/controllers/config.go index e21c81d05..8c395285f 100644 --- a/controllers/user/controllers/config.go +++ b/controllers/user/controllers/config.go @@ -1,3 +1,17 @@ +// Copyright © 2024 sealos. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package controllers import ( diff --git a/controllers/user/main.go b/controllers/user/main.go index 3c1504db0..f05f10258 100644 --- a/controllers/user/main.go +++ b/controllers/user/main.go @@ -176,8 +176,5 @@ func setConfigToEnv(cfg controllers.Config) error { if err := os.Setenv("SEALOS_CLOUD_HOST", cfg.Global.CloudDomain); err != nil { return err } - if err := os.Setenv("APISERVER_PORT", cfg.Kube.ApiServerPort); err != nil { - return err - } - return nil + return os.Setenv("APISERVER_PORT", cfg.Kube.APIServerPort) }