Skip to content

Commit

Permalink
feat(controller): expose all the current manager options as flags in …
Browse files Browse the repository at this point in the history
…cmd (#44)

* feat(controller): expose all the current manager options as flags in cmd

* fix(controller): missing kubernetesWebhookPort option in Config

* fix(controller): missing yaml tag for kubernetesWebhookPort in Config
  • Loading branch information
AlanLonguet authored Feb 11, 2023
1 parent 950d729 commit 72b9cb7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 29 deletions.
6 changes: 5 additions & 1 deletion cmd/controllers/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func buildControllersStartCmd(app *burrito.App) *cobra.Command {
cmd.Flags().StringVar(&app.Config.Controller.Timers.DriftDetection, "drift-detection-period", "20m", "period between two plans. Must end with s, m or h.")
cmd.Flags().StringVar(&app.Config.Controller.Timers.OnError, "on-error-period", "1m", "period between two runners launch when an error occured. Must end with s, m or h.")
cmd.Flags().StringVar(&app.Config.Controller.Timers.WaitAction, "wait-action-period", "1m", "period between two runners when a layer is locked. Must end with s, m or h.")

cmd.Flags().BoolVar(&app.Config.Controller.LeaderElection.Enabled, "leader-election", true, "whether leader election is enabled or not, default to true")
cmd.Flags().StringVar(&app.Config.Controller.LeaderElection.ID, "leader-election-id", "6d185457.terraform.padok.cloud", "lease id used for leader election")
cmd.Flags().StringVar(&app.Config.Controller.HealthProbeBindAddress, "metrics-bind-address", ":8080", "address to bind the metrics server embedded in the controllers")
cmd.Flags().StringVar(&app.Config.Controller.MetricsBindAddress, "health-probe-bind-address", ":8081", "address to bind the health probe server embedded in the controllers")
cmd.Flags().IntVar(&app.Config.Controller.KubernetesWehbookPort, "kubernetes-webhook-port", 9443, "port used by the validating webhook server embedded in the controllers")
return cmd
}
15 changes: 12 additions & 3 deletions internal/burrito/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,18 @@ type WebhookGitlabConfig struct {
}

type ControllerConfig struct {
WatchedNamespaces []string `yaml:"namespaces"`
Timers ControllerTimers `yaml:"timers"`
Types []string `yaml:"types"`
WatchedNamespaces []string `yaml:"namespaces"`
Timers ControllerTimers `yaml:"timers"`
Types []string `yaml:"types"`
LeaderElection LeaderElectionConfig `yaml:"leaderElection"`
MetricsBindAddress string `yaml:"metricsBindAddress"`
HealthProbeBindAddress string `yaml:"healthProbeBindAddress"`
KubernetesWehbookPort int `yaml:"kubernetesWebhookPort"`
}

type LeaderElectionConfig struct {
Enabled bool `yaml:"enabled"`
ID string `yaml:"id"`
}

type ControllerTimers struct {
Expand Down
30 changes: 5 additions & 25 deletions internal/controllers/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,11 @@ func New(c *config.Config) *Controllers {

func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))

utilruntime.Must(configv1alpha1.AddToScheme(scheme))
//+kubebuilder:scaffold:scheme
}

func (c *Controllers) Exec() {
// var metricsAddr string
// var enableLeaderElection bool
// var probeAddr string
// flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
// flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
// flag.BoolVar(&enableLeaderElection, "leader-elect", false,
// "Enable leader election for controller manager. "+
// "Enabling this will ensure there is only one active controller manager.")
opts := zap.Options{
Development: true,
}
Expand All @@ -86,22 +77,11 @@ func (c *Controllers) Exec() {

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: ":8080",
Port: 9443,
HealthProbeBindAddress: ":8081",
LeaderElection: false,
LeaderElectionID: "6d185457.terraform.padok.cloud",
// LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily
// when the Manager ends. This requires the binary to immediately end when the
// Manager is stopped, otherwise, this setting is unsafe. Setting this significantly
// speeds up voluntary leader transitions as the new leader don't have to wait
// LeaseDuration time first.
//
// In the default scaffold provided, the program ends immediately after
// the manager stops, so would be fine to enable this option. However,
// if you are doing or is intended to do any operation such as perform cleanups
// after the manager stops then its usage might be unsafe.
// LeaderElectionReleaseOnCancel: true,
MetricsBindAddress: c.config.Controller.MetricsBindAddress,
Port: c.config.Controller.KubernetesWehbookPort,
HealthProbeBindAddress: c.config.Controller.HealthProbeBindAddress,
LeaderElection: c.config.Controller.LeaderElection.Enabled,
LeaderElectionID: c.config.Controller.LeaderElection.ID,
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down

0 comments on commit 72b9cb7

Please sign in to comment.