Add Leader election flags for machine health checks
@@ -3,6 +3,7 @@ package main
import (
"flag"
"runtime"
+ "time"
"github.com/openshift/machine-api-operator/pkg/controller/machinehealthcheck"
"github.com/openshift/machine-api-operator/pkg/metrics"
@@ -44,6 +45,24 @@ func main() {
"The address for health checking.",
)
+ leaderElectResourceNamespace := flag.String(
+ "leader-elect-resource-namespace",
+ "",
+ "The namespace of resource object that is used for locking during leader election. If unspecified and running in cluster, defaults to the service account namespace for the controller. Required for leader-election outside of a cluster.",
+ )
+
+ leaderElect := flag.Bool(
+ "leader-elect",
+ false,
+ "Start a leader election client and gain leadership before executing the main loop. Enable this when running replicated components for high availability.",
+ )
+
+ leaderElectLeaseDuration := flag.Duration(
+ "leader-elect-lease-duration",
+ 15*time.Second,
+ "The duration that non-leader candidates will wait after observing a leadership renewal until attempting to acquire leadership of a led but unrenewed leader slot. This is effectively the maximum duration that a leader can be stopped before it is replaced by another candidate. This is only applicable if leader election is enabled.",
+ )
+
flag.Parse()
printVersion()
@@ -56,7 +75,12 @@ func main() {
opts := manager.Options{
MetricsBindAddress: *metricsAddress,
HealthProbeBindAddress: *healthAddr,
+ LeaderElection: *leaderElect,
+ LeaderElectionNamespace: *leaderElectResourceNamespace,
+ LeaderElectionID: "cluster-api-provider-healthcheck-leader",
+ LeaseDuration: leaderElectLeaseDuration,
}
+
if *watchNamespace != "" {
opts.Namespace = *watchNamespace
glog.Infof("Watching machine-api objects only in namespace %q for reconciliation.", opts.Namespace)
