NewCmd create a new cobra command
()
| 29 | |
| 30 | // NewCmd create a new cobra command |
| 31 | func NewCmd() *cobra.Command { |
| 32 | var metricsAddr string |
| 33 | var leaderElectionEnable bool |
| 34 | var configMapName string |
| 35 | var secretName string |
| 36 | var port int |
| 37 | var pprofHTTPServer bool |
| 38 | var leaderLeaseDuration int |
| 39 | var leaderRenewDeadline int |
| 40 | var maxConcurrentReconciles int |
| 41 | |
| 42 | cmd := cobra.Command{ |
| 43 | Use: "controller [flags]", |
| 44 | SilenceErrors: true, |
| 45 | RunE: func(_ *cobra.Command, _ []string) error { |
| 46 | return RunController( |
| 47 | metricsAddr, |
| 48 | configMapName, |
| 49 | secretName, |
| 50 | leaderElectionConfiguration{ |
| 51 | enable: leaderElectionEnable, |
| 52 | leaseDuration: time.Duration(leaderLeaseDuration) * time.Second, |
| 53 | renewDeadline: time.Duration(leaderRenewDeadline) * time.Second, |
| 54 | }, |
| 55 | pprofHTTPServer, |
| 56 | port, |
| 57 | maxConcurrentReconciles, |
| 58 | configuration.Current, |
| 59 | ) |
| 60 | }, |
| 61 | } |
| 62 | |
| 63 | cmd.Flags().StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.") |
| 64 | |
| 65 | cmd.Flags().BoolVar(&leaderElectionEnable, "leader-elect", false, |
| 66 | "Enable leader election for controller manager. "+ |
| 67 | "If enabled, this will ensure there is only one active controller manager.") |
| 68 | cmd.Flags().IntVar(&leaderLeaseDuration, "leader-lease-duration", 15, |
| 69 | "the leader lease duration expressed in seconds") |
| 70 | cmd.Flags().IntVar(&leaderRenewDeadline, "leader-renew-deadline", 10, |
| 71 | "the leader renew deadline expressed in seconds") |
| 72 | |
| 73 | cmd.Flags().StringVar(&configMapName, "config-map-name", "", "The name of the ConfigMap containing "+ |
| 74 | "the operator configuration") |
| 75 | cmd.Flags().StringVar(&secretName, "secret-name", "", "The name of the Secret containing "+ |
| 76 | "the operator configuration. Values are merged with the ConfigMap's one, overwriting them if already defined") |
| 77 | cmd.Flags().IntVar(&port, "webhook-port", 9443, "The port the controller should be listening on."+ |
| 78 | " If modified, take care to update the service pointing to it") |
| 79 | cmd.Flags().BoolVar( |
| 80 | &pprofHTTPServer, |
| 81 | "pprof-server", |
| 82 | false, |
| 83 | "If true it will start a pprof debug http server on localhost:6060. Defaults to false.", |
| 84 | ) |
| 85 | cmd.Flags().IntVar( |
| 86 | &maxConcurrentReconciles, |
| 87 | "max-concurrent-reconciles", |
| 88 | 10, |