-
Notifications
You must be signed in to change notification settings - Fork 57
Bug 2034484: feat: bumped library-go version #166
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package leaderelection | ||
|
|
||
| import ( | ||
| "context" | ||
| "time" | ||
|
|
||
| configv1 "github.com/openshift/api/config/v1" | ||
| "github.com/openshift/library-go/pkg/config/clusterstatus" | ||
| "github.com/openshift/library-go/pkg/config/leaderelection" | ||
| "k8s.io/client-go/rest" | ||
| "k8s.io/klog" | ||
| ) | ||
|
|
||
| // GetLeaderElectionConfig returns leader election configs defaults based on the cluster topology | ||
| func GetLeaderElectionConfig(restConfig *rest.Config, enabled bool) configv1.LeaderElection { | ||
|
|
||
| // Defaults follow conventions | ||
| // https://github.com/openshift/enhancements/blob/master/CONVENTIONS.md#high-availability | ||
| defaultLeaderElection := leaderelection.LeaderElectionDefaulting( | ||
| configv1.LeaderElection{ | ||
| Disable: !enabled, | ||
| }, | ||
| "", "", | ||
| ) | ||
|
|
||
| if enabled { | ||
| ctx, cancel := context.WithTimeout(context.Background(), time.Second*3) | ||
| defer cancel() | ||
| if infra, err := clusterstatus.GetClusterInfraStatus(ctx, restConfig); err == nil && infra != nil { | ||
| if infra.ControlPlaneTopology == configv1.SingleReplicaTopologyMode { | ||
| return leaderelection.LeaderElectionSNOConfig(defaultLeaderElection) | ||
| } | ||
| } else { | ||
| klog.Warningf("unable to get cluster infrastructure status, using HA cluster values for leader election: %v", err) | ||
| } | ||
| } | ||
|
|
||
| return defaultLeaderElection | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the leaderelection implementation specific to ptp-operator? Why aren't you just importing https://github.com/openshift/library-go/blob/master/pkg/config/leaderelection/leaderelection.go here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @josephdrichard You're right this isn't specific to ptp-operator. When the PR was opened there was a breaking dependency change between the k8s-23 libs and controller-runtime. It was causing some problems and I figured a bit of code was the better approach for now since library-go wasn't being used else where in the code. Luckily, controller-runtime was updated a few hours so we can import it now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you still looking to update this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies, forgot to mention in the reply. This PR has been updated with the latest library-go code and I'm using those methods to drive the leaderelection configs