Skip to content

Commit

Permalink
Merge pull request #117 from elmiko/update-leader-election/release-4.5
Browse files Browse the repository at this point in the history
Bug 1864352: Update leader election for release 4.5
  • Loading branch information
openshift-merge-robot committed Sep 17, 2020
2 parents 95cb5aa + d234337 commit f6733e6
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions cmd/manager/main.go
Expand Up @@ -19,6 +19,7 @@ package main
import (
"flag"
"log"
"time"

machinev1 "github.com/openshift/machine-api-operator/pkg/apis/machine/v1beta1"
"k8s.io/klog"
Expand All @@ -29,10 +30,39 @@ import (
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
)

// The default durations for the leader election operations.
var (
leaseDuration = 120 * time.Second
renewDeadline = 110 * time.Second
retryPeriod = 20 * time.Second
)

func main() {

flag.Set("logtostderr", "true")
watchNamespace := flag.String("namespace", "", "Namespace that the controller watches to reconcile machine-api objects. If unspecified, the controller watches for machine-api objects across all namespaces.")
watchNamespace := flag.String(
"namespace",
"",
"Namespace that the controller watches to reconcile machine-api objects. If unspecified, the controller watches for machine-api objects across all namespaces.",
)

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",
leaseDuration,
"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.",
)
klog.InitFlags(nil)
flag.Parse()

Expand All @@ -43,7 +73,15 @@ func main() {
}

// Setup a Manager
opts := manager.Options{}
opts := manager.Options{
LeaderElection: *leaderElect,
LeaderElectionNamespace: *leaderElectResourceNamespace,
LeaderElectionID: "cluster-api-provider-openstack-leader",
LeaseDuration: leaderElectLeaseDuration,
// Slow the default retry and renew election rate to reduce etcd writes at idle: BZ 1858400
RetryPeriod: &retryPeriod,
RenewDeadline: &renewDeadline,
}
if *watchNamespace != "" {
opts.Namespace = *watchNamespace
klog.Infof("Watching machine-api objects only in namespace %q for reconciliation.", opts.Namespace)
Expand Down

0 comments on commit f6733e6

Please sign in to comment.