-
Notifications
You must be signed in to change notification settings - Fork 43
allow leader election to accept namespace #1
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
Conversation
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.
If the POD_NAME
environment variable is not set, I think we could use this code. That way, we would no longer require operators to set the POD_NAME environment variable using the downward API in their deployment (as long as they don't override hostname in their pod spec).
This behavior would need to be documented.
func Become(ctx context.Context, lockName string) error { | ||
// leader. Upon termination of that pod, the garbage collector will delete | ||
// the ConfigMap, enabling a different pod to become the leader. | ||
func Become(ctx context.Context, lockName string, ns string) error { |
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.
WDYT of duplicating the leaderelection.Options struct from controller-runtime and using that as a parameter to leader.Become()
func Become(ctx context.Context, lockName string, ns string) error { | |
func Become(ctx context.Context, opts Options) error { |
@@ -210,10 +198,7 @@ func isPodEvicted(pod corev1.Pod) bool { | |||
|
|||
// getOperatorNamespace returns the namespace the operator should be running in. | |||
func getOperatorNamespace() (string, error) { |
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.
Nit: have this take a path to make it testable (without resetting a global in tests)
func getOperatorNamespace() (string, error) { | |
func getOperatorNamespace(namespacePath string) (string, error) { |
This approach to leader election depends on a "lease" resource, implemented with a ConfigMap, having an owner reference to the Pod that the operator is running in. If the Pod goes away, the lease automatically goes with it, and thus someone else can become the leader. But given that, I don't see how this is going to work if the operator itself is either running outside the cluster, or running in a different namespace than where the lease is. Mind elaborating on the goal and how it's going to work? |
@mhrivnak Yeah, that's totally right. I had lost track of that constraint. Given that, it doesn't make sense to accept an explicit namespace since this will only ever work in-cluster, and owner references don't work across namespace boundaries. Do you think it's reasonable to use the pod hostname if Or should we keep the hard requirement on |
Pull Request Test Coverage Report for Build 178610974
💛 - Coveralls |
* remove isRunLocal() * change errNoNamespace value, it now returns "Namespace is required when running outside the cluster" * update tests
My first implementation used the pod hostname, but that was changed after it was pointed out as not being a reliable way to identify the pod name. Based on the comments, it sounds like the hostname should be avoided. |
Based on the comments above, it sounds like it would be a bad idea to accept a namespace parameter. Closing this PR. |
"Namespace is required when running outside the cluster"