From 05ceac055655fc0823aafa0de60a3dee691955b5 Mon Sep 17 00:00:00 2001 From: Homayoon Alimohammadi Date: Thu, 27 Jun 2024 15:48:11 +0400 Subject: [PATCH] Add disable-config-controller options to k8sd (#511) * Add toggle options for "node-config-controller", "control-plane-config-controller", "feature-controller" and "update-node-config-controller" --- src/k8s/cmd/k8sd/k8sd.go | 30 ++++++++++----- src/k8s/pkg/k8sd/app/app.go | 76 +++++++++++++++++++++++++------------ 2 files changed, 72 insertions(+), 34 deletions(-) diff --git a/src/k8s/cmd/k8sd/k8sd.go b/src/k8s/cmd/k8sd/k8sd.go index 5102bea80..bda425a8b 100644 --- a/src/k8s/cmd/k8sd/k8sd.go +++ b/src/k8s/cmd/k8sd/k8sd.go @@ -7,10 +7,14 @@ import ( ) var rootCmdOpts struct { - logDebug bool - logVerbose bool - stateDir string - pprofAddress string + logDebug bool + logVerbose bool + stateDir string + pprofAddress string + disableNodeConfigController bool + disableControlPlaneConfigController bool + disableFeatureController bool + disableUpdateNodeConfigController bool } func NewRootCmd(env cmdutil.ExecutionEnvironment) *cobra.Command { @@ -19,11 +23,15 @@ func NewRootCmd(env cmdutil.ExecutionEnvironment) *cobra.Command { Short: "Canonical Kubernetes orchestrator and clustering daemon", Run: func(cmd *cobra.Command, args []string) { app, err := app.New(app.Config{ - Debug: rootCmdOpts.logDebug, - Verbose: rootCmdOpts.logVerbose, - StateDir: rootCmdOpts.stateDir, - Snap: env.Snap, - PprofAddress: rootCmdOpts.pprofAddress, + Debug: rootCmdOpts.logDebug, + Verbose: rootCmdOpts.logVerbose, + StateDir: rootCmdOpts.stateDir, + Snap: env.Snap, + PprofAddress: rootCmdOpts.pprofAddress, + DisableNodeConfigController: rootCmdOpts.disableNodeConfigController, + DisableControlPlaneConfigController: rootCmdOpts.disableControlPlaneConfigController, + DisableUpdateNodeConfigController: rootCmdOpts.disableUpdateNodeConfigController, + DisableFeatureController: rootCmdOpts.disableFeatureController, }) if err != nil { cmd.PrintErrf("Error: Failed to initialize k8sd: %v", err) @@ -47,6 +55,10 @@ func NewRootCmd(env cmdutil.ExecutionEnvironment) *cobra.Command { cmd.PersistentFlags().BoolVarP(&rootCmdOpts.logVerbose, "verbose", "v", true, "Show all information messages") cmd.PersistentFlags().StringVar(&rootCmdOpts.stateDir, "state-dir", "", "Directory with the dqlite datastore") cmd.PersistentFlags().StringVar(&rootCmdOpts.pprofAddress, "pprof-address", "", "Listen address for pprof endpoints, e.g. \"127.0.0.1:4217\"") + cmd.PersistentFlags().BoolVar(&rootCmdOpts.disableNodeConfigController, "disable-node-config-controller", false, "Disable the Node Config Controller") + cmd.PersistentFlags().BoolVar(&rootCmdOpts.disableControlPlaneConfigController, "disable-control-plane-config-controller", false, "Disable the Control Plane Config Controller") + cmd.PersistentFlags().BoolVar(&rootCmdOpts.disableUpdateNodeConfigController, "disable-update-node-config-controller", false, "Disable the Update Node Config Controller") + cmd.PersistentFlags().BoolVar(&rootCmdOpts.disableFeatureController, "disable-feature-controller", false, "Disable the Feature Controller") cmd.Flags().Uint("port", 0, "Default port for the HTTP API") cmd.Flags().MarkDeprecated("port", "this flag does not have any effect, and will be removed in a future version") diff --git a/src/k8s/pkg/k8sd/app/app.go b/src/k8s/pkg/k8sd/app/app.go index 51c529859..b3a3af2da 100644 --- a/src/k8s/pkg/k8sd/app/app.go +++ b/src/k8s/pkg/k8sd/app/app.go @@ -30,6 +30,14 @@ type Config struct { Snap snap.Snap // PprofAddress is the address to listen for pprof debug endpoints. Empty to disable. PprofAddress string + // DisableNodeConfigController is a bool flag to disable node config controller + DisableNodeConfigController bool + // DisableControlPlaneConfigController is a bool flag to disable control-plane config controller + DisableControlPlaneConfigController bool + // DisableUpdateNodeConfigController is a bool flag to disable update node config controller + DisableUpdateNodeConfigController bool + // DisableFeatureController is a bool flag to disable feature controller + DisableFeatureController bool } // App is the k8sd microcluster instance. @@ -83,23 +91,36 @@ func New(cfg Config) (*App, error) { } app.readyWg.Add(1) - app.nodeConfigController = controllers.NewNodeConfigurationController( - cfg.Snap, - app.readyWg.Wait, - ) + if !cfg.DisableNodeConfigController { + app.nodeConfigController = controllers.NewNodeConfigurationController( + cfg.Snap, + app.readyWg.Wait, + ) + } else { + log.Println("node-config-controller disabled via config") + } - app.controlPlaneConfigController = controllers.NewControlPlaneConfigurationController( - cfg.Snap, - app.readyWg.Wait, - time.NewTicker(10*time.Second).C, - ) + if !cfg.DisableControlPlaneConfigController { + app.controlPlaneConfigController = controllers.NewControlPlaneConfigurationController( + cfg.Snap, + app.readyWg.Wait, + time.NewTicker(10*time.Second).C, + ) + } else { + log.Println("control-plane-config-controller disabled via config") + } app.triggerUpdateNodeConfigControllerCh = make(chan struct{}, 1) - app.updateNodeConfigController = controllers.NewUpdateNodeConfigurationController( - cfg.Snap, - app.readyWg.Wait, - app.triggerUpdateNodeConfigControllerCh, - ) + + if !cfg.DisableUpdateNodeConfigController { + app.updateNodeConfigController = controllers.NewUpdateNodeConfigurationController( + cfg.Snap, + app.readyWg.Wait, + app.triggerUpdateNodeConfigControllerCh, + ) + } else { + log.Println("update-node-config-controller disabled via config") + } app.triggerFeatureControllerNetworkCh = make(chan struct{}, 1) app.triggerFeatureControllerGatewayCh = make(chan struct{}, 1) @@ -108,17 +129,22 @@ func New(cfg Config) (*App, error) { app.triggerFeatureControllerLocalStorageCh = make(chan struct{}, 1) app.triggerFeatureControllerMetricsServerCh = make(chan struct{}, 1) app.triggerFeatureControllerDNSCh = make(chan struct{}, 1) - app.featureController = controllers.NewFeatureController(controllers.FeatureControllerOpts{ - Snap: cfg.Snap, - WaitReady: app.readyWg.Wait, - TriggerNetworkCh: app.triggerFeatureControllerNetworkCh, - TriggerGatewayCh: app.triggerFeatureControllerGatewayCh, - TriggerIngressCh: app.triggerFeatureControllerIngressCh, - TriggerLoadBalancerCh: app.triggerFeatureControllerLoadBalancerCh, - TriggerDNSCh: app.triggerFeatureControllerDNSCh, - TriggerLocalStorageCh: app.triggerFeatureControllerLocalStorageCh, - TriggerMetricsServerCh: app.triggerFeatureControllerMetricsServerCh, - }) + + if !cfg.DisableFeatureController { + app.featureController = controllers.NewFeatureController(controllers.FeatureControllerOpts{ + Snap: cfg.Snap, + WaitReady: app.readyWg.Wait, + TriggerNetworkCh: app.triggerFeatureControllerNetworkCh, + TriggerGatewayCh: app.triggerFeatureControllerGatewayCh, + TriggerIngressCh: app.triggerFeatureControllerIngressCh, + TriggerLoadBalancerCh: app.triggerFeatureControllerLoadBalancerCh, + TriggerDNSCh: app.triggerFeatureControllerDNSCh, + TriggerLocalStorageCh: app.triggerFeatureControllerLocalStorageCh, + TriggerMetricsServerCh: app.triggerFeatureControllerMetricsServerCh, + }) + } else { + log.Println("feature-controller disabled via config") + } return app, nil }