forked from labring/sealos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: optimize user && terminal config. (#32)
* chore: optimize terminal config. Signed-off-by: yy <[email protected]> Signed-off-by: yy <[email protected]> * chore: optimize user && terminal config. Signed-off-by: yy <[email protected]> Signed-off-by: yy <[email protected]> * chore: optimize user && terminal config. Signed-off-by: yy <[email protected]> Signed-off-by: yy <[email protected]> * chore: optimize user && terminal config. Signed-off-by: yy <[email protected]> Signed-off-by: yy <[email protected]> * chore: optimize user && terminal config. Signed-off-by: yy <[email protected]> Signed-off-by: yy <[email protected]> --------- Signed-off-by: yy <[email protected]>
- Loading branch information
Showing
13 changed files
with
165 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package config | ||
|
||
import ( | ||
"gopkg.in/yaml.v3" | ||
"io/ioutil" | ||
) | ||
|
||
type Global struct { | ||
CloudDomain string `yaml:"cloudDomain"` | ||
CloudPort string `yaml:"cloudPort"` | ||
RegionUid string `yaml:"regionUid"` | ||
CertSecretName string `yaml:"certSecretName"` | ||
} | ||
|
||
type Kube struct { | ||
Version string `yaml:"version"` | ||
ApiServerHost string `yaml:"apiServerHost"` | ||
ApiServerPort string `yaml:"apiServerPort"` | ||
} | ||
|
||
type Common struct { | ||
GuideEnabled string `yaml:"guideEnabled"` | ||
ApiEnabled string `yaml:"apiEnabled"` | ||
} | ||
|
||
type Database struct { | ||
MongodbUri string `yaml:"mongodbUri"` | ||
GlobalCockroachdbUri string `yaml:"globalCockroachdbUri"` | ||
RegionalCockroachdbUri string `yaml:"regionalCockroachdbUri"` | ||
} | ||
|
||
func LoadConfig(path string, target interface{}) error { | ||
configData, err := ioutil.ReadFile(path) | ||
if err != nil { | ||
return err | ||
} | ||
err = yaml.Unmarshal(configData, target) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package controllers | ||
|
||
import ( | ||
"github.com/labring/sealos/controllers/pkg/config" | ||
) | ||
|
||
type Config struct { | ||
config.Global `yaml:"global"` | ||
TerminalConfig TerminalConfig `yaml:"terminalController"` | ||
} | ||
|
||
type TerminalConfig struct { | ||
IngressTlsSecretName string `yaml:"ingressTlsSecretName"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,13 +73,10 @@ const ( | |
// TerminalReconciler reconciles a Terminal object | ||
type TerminalReconciler struct { | ||
client.Client | ||
Scheme *runtime.Scheme | ||
recorder record.EventRecorder | ||
Config *rest.Config | ||
terminalDomain string | ||
terminalPort string | ||
secretName string | ||
secretNamespace string | ||
Scheme *runtime.Scheme | ||
recorder record.EventRecorder | ||
Config *rest.Config | ||
CtrConfig *Config | ||
} | ||
|
||
//+kubebuilder:rbac:groups=terminal.sealos.io,resources=terminals,verbs=get;list;watch;create;update;patch;delete | ||
|
@@ -90,15 +87,6 @@ type TerminalReconciler struct { | |
//+kubebuilder:rbac:groups="",resources=events,verbs=get;list;watch;create;update;patch;delete | ||
//+kubebuilder:rbac:groups=networking.k8s.io,resources=ingresses,verbs=get;list;watch;create;update;patch;delete | ||
|
||
// Reconcile is part of the main kubernetes reconciliation loop which aims to | ||
// move the current state of the cluster closer to the desired state. | ||
// TODO(user): Modify the Reconcile function to compare the state specified by | ||
// the Terminal object against the actual cluster state, and then | ||
// perform operations to make the cluster state reflect the state specified by | ||
// the user. | ||
// | ||
// For more details, check Reconcile and its Result here: | ||
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile | ||
func (r *TerminalReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { | ||
logger := log.FromContext(ctx, "terminal", req.NamespacedName) | ||
terminal := &terminalv1.Terminal{} | ||
|
@@ -172,7 +160,7 @@ func (r *TerminalReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c | |
|
||
func (r *TerminalReconciler) syncIngress(ctx context.Context, terminal *terminalv1.Terminal, hostname string, recLabels map[string]string) error { | ||
var err error | ||
host := hostname + "." + r.terminalDomain | ||
host := hostname + "." + r.CtrConfig.Global.CloudDomain | ||
switch terminal.Spec.IngressType { | ||
case terminalv1.Nginx: | ||
err = r.syncNginxIngress(ctx, terminal, host, recLabels) | ||
|
@@ -417,10 +405,10 @@ func getSecretNamespace() string { | |
} | ||
|
||
func (r *TerminalReconciler) getPort() string { | ||
if r.terminalPort == "" || r.terminalPort == "80" || r.terminalPort == "443" { | ||
if r.CtrConfig.Global.CloudPort == "" || r.CtrConfig.Global.CloudPort == "80" || r.CtrConfig.Global.CloudPort == "443" { | ||
return "" | ||
} | ||
return ":" + r.terminalPort | ||
return ":" + r.CtrConfig.Global.CloudPort | ||
} | ||
|
||
func NewCache() cache.NewCacheFunc { | ||
|
@@ -443,10 +431,6 @@ func NewCache() cache.NewCacheFunc { | |
// 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.terminalPort = getPort() | ||
r.secretName = getSecretName() | ||
r.secretNamespace = getSecretNamespace() | ||
r.Config = mgr.GetConfig() | ||
return ctrl.NewControllerManagedBy(mgr). | ||
For(&terminalv1.Terminal{}). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package controllers | ||
|
||
import ( | ||
"github.com/labring/sealos/controllers/pkg/config" | ||
) | ||
|
||
type Config struct { | ||
config.Global `yaml:"global"` | ||
config.Kube `yaml:"kube"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.