Skip to content

Commit

Permalink
Add disable-config-controller options to k8sd (#511)
Browse files Browse the repository at this point in the history
* Add toggle options for "node-config-controller", "control-plane-config-controller", "feature-controller" and "update-node-config-controller"
  • Loading branch information
HomayoonAlimohammadi authored Jun 27, 2024
1 parent 2958f94 commit 05ceac0
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 34 deletions.
30 changes: 21 additions & 9 deletions src/k8s/cmd/k8sd/k8sd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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")
Expand Down
76 changes: 51 additions & 25 deletions src/k8s/pkg/k8sd/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -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
}
Expand Down

0 comments on commit 05ceac0

Please sign in to comment.