Skip to content

Commit

Permalink
feat: change Kruise leader election from configmap to configmapsleases
Browse files Browse the repository at this point in the history
Signed-off-by: HIHIA <[email protected]>
  • Loading branch information
YTGhost committed Feb 25, 2023
1 parent 85a9542 commit ab97599
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ func main() {
var leaderElectionNamespace string
var namespace string
var syncPeriodStr string
var leaseDuration time.Duration
var renewDeadLine time.Duration
var leaderElectionResourceLock string
var leaderElectionId string
var retryPeriod time.Duration

flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&healthProbeAddr, "health-probe-addr", ":8000", "The address the healthz/readyz endpoint binds to.")
flag.BoolVar(&allowPrivileged, "allow-privileged", true, "If true, allow privileged containers. It will only work if api-server is also"+
Expand All @@ -91,7 +97,16 @@ func main() {
flag.BoolVar(&enablePprof, "enable-pprof", true, "Enable pprof for controller manager.")
flag.StringVar(&pprofAddr, "pprof-addr", ":8090", "The address the pprof binds to.")
flag.StringVar(&syncPeriodStr, "sync-period", "", "Determines the minimum frequency at which watched resources are reconciled.")

flag.DurationVar(&leaseDuration, "leader-election-lease-duration", 15*time.Second,
"leader-election-lease-duration is the duration that non-leader candidates will wait to force acquire leadership. This is measured against time of last observed ack. Default is 15 seconds.")
flag.DurationVar(&renewDeadLine, "leader-election-renew-deadline", 10*time.Second,
"leader-election-renew-deadline is the duration that the acting controlplane will retry refreshing leadership before giving up. Default is 10 seconds.")
flag.StringVar(&leaderElectionResourceLock, "leader-election-resource-lock", resourcelock.ConfigMapsLeasesResourceLock,
"leader-election-resource-lock determines which resource lock to use for leader election, defaults to \"configmapsleases\".")
flag.StringVar(&leaderElectionId, "leader-election-id", "kruise-manager",
"leader-election-id determines the name of the resource that leader election will use for holding the leader lock, Default is kruise-manager.")
flag.DurationVar(&retryPeriod, "leader-election-retry-period", 2*time.Second,
"leader-election-retry-period is the duration the LeaderElector clients should wait between tries of actions. Default is 2 seconds.")
utilfeature.DefaultMutableFeatureGate.AddFlag(pflag.CommandLine)
klog.InitFlags(nil)
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
Expand Down Expand Up @@ -140,9 +155,12 @@ func main() {
MetricsBindAddress: metricsAddr,
HealthProbeBindAddress: healthProbeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "kruise-manager",
LeaderElectionID: leaderElectionId,
LeaderElectionNamespace: leaderElectionNamespace,
LeaderElectionResourceLock: resourcelock.ConfigMapsResourceLock,
LeaderElectionResourceLock: leaderElectionResourceLock,
LeaseDuration: &leaseDuration,
RenewDeadline: &renewDeadLine,
RetryPeriod: &retryPeriod,
Namespace: namespace,
SyncPeriod: syncPeriod,
NewCache: utilclient.NewCache,
Expand Down

0 comments on commit ab97599

Please sign in to comment.