Skip to content

Commit

Permalink
Merge pull request #7764 from idebeijer/cluster-autoscaler-release-1.32
Browse files Browse the repository at this point in the history
[cluster-autoscaler-release-1.32] fix: add --leader-elect flags back by reverting #7233
  • Loading branch information
k8s-ci-robot authored Jan 24, 2025
2 parents fbe4465 + 57d8f63 commit a221e41
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions cluster-autoscaler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ func multiStringFlag(name string, usage string) *MultiStringFlag {
}

var (
leaseResourceName = flag.String("lease-resource-name", "cluster-autoscaler", "The lease resource to use in leader election.")
clusterName = flag.String("cluster-name", "", "Autoscaled cluster name, if available")
address = flag.String("address", ":8085", "The address to expose prometheus metrics.")
kubernetes = flag.String("kubernetes", "", "Kubernetes master location. Leave blank for default")
Expand Down Expand Up @@ -692,6 +691,10 @@ func main() {
klog.Fatalf("Failed to add logging feature flags: %v", err)
}

leaderElection := leaderElectionConfiguration()
// Must be called before kube_flag.InitFlags() to ensure leader election flags are parsed and available.
componentopts.BindLeaderElectionFlags(&leaderElection, pflag.CommandLine)

logsapi.AddFlags(loggingConfig, pflag.CommandLine)
featureGate.AddFlag(pflag.CommandLine)
kube_flag.InitFlags()
Expand All @@ -705,10 +708,6 @@ func main() {
}
}

leaderElection := defaultLeaderElectionConfiguration()
leaderElection.LeaderElect = true
componentopts.BindLeaderElectionFlags(&leaderElection, pflag.CommandLine)

logs.InitLogs()
if err := logsapi.ValidateAndApply(loggingConfig, featureGate); err != nil {
klog.Fatalf("Failed to validate and apply logging configuration: %v", err)
Expand Down Expand Up @@ -788,14 +787,14 @@ func main() {
}
}

func defaultLeaderElectionConfiguration() componentbaseconfig.LeaderElectionConfiguration {
func leaderElectionConfiguration() componentbaseconfig.LeaderElectionConfiguration {
return componentbaseconfig.LeaderElectionConfiguration{
LeaderElect: false,
LeaderElect: true,
LeaseDuration: metav1.Duration{Duration: defaultLeaseDuration},
RenewDeadline: metav1.Duration{Duration: defaultRenewDeadline},
RetryPeriod: metav1.Duration{Duration: defaultRetryPeriod},
ResourceLock: resourcelock.LeasesResourceLock,
ResourceName: *leaseResourceName,
ResourceName: "cluster-autoscaler",
}
}

Expand Down

0 comments on commit a221e41

Please sign in to comment.