Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring Flags #11

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions cmd/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,37 @@ var (
setupLog = ctrl.Log.WithName("setup")
)

// variables to hold command-line flags
var (
// metricsAddr listen address for the prometheus metrics endpoint.
metricsAddr string
// probeAddr list address for health-probe endpoint.
probeAddr string
// webhookPort port number on which webhook listens to.
webhookPort int
// enableLeaderElection enables leader election process, for high-available deployments.
enableLeaderElection bool
)

func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
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.IntVar(&webhookPort, "webhook-port", 9443,
"Webhook server listen port.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")

utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(operatorv1alpha1.AddToScheme(scheme))
utilruntime.Must(apiextv1.AddToScheme(scheme))
// +kubebuilder:scaffold:scheme
}

func main() {
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,
}
opts := zap.Options{Development: true}
opts.BindFlags(flag.CommandLine)
flag.Parse()

Expand All @@ -58,7 +69,7 @@ func main() {
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
Port: webhookPort,
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "01a9b2d1.shipwright.io",
Expand Down