Skip to content
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

Leader election events are recorded with the wrong config #1798

Closed
JustinKuli opened this issue Feb 9, 2022 · 0 comments · Fixed by #1803
Closed

Leader election events are recorded with the wrong config #1798

JustinKuli opened this issue Feb 9, 2022 · 0 comments · Fixed by #1803

Comments

@JustinKuli
Copy link
Contributor

I'm working with a controller that needs to synchronize resources between two different Kubernetes clusters. The controller runs in what we'll call the "spoke" cluster, but we want it to watch resources in another cluster, which we call the "hub." To handle the leader election inside the spoke cluster, we make the manager like this:

options := manager.Options{
    ...
    LeaderElectionConfig: spokeCfg,
}

mgr, err := ctrl.NewManager(hubCfg, options)

This seems to work, and the configmap/lease that the leader election uses are on the spoke cluster. However, the leader election Events are going to the hub cluster.

We noticed this because we didn't give the kubeconfig on the hub cluster permissions to create events, so we get an error log like this (some details elided) :

E0208 21:45:38.523903       1 event.go:264] Server rejected event '&v1.Event{TypeMeta:v1.TypeMeta{Kind:"", APIVersion:""}, ..., Reason:"LeaderElection", Message:"... became leader", ...}': 'events is forbidden: User "..." cannot create resource "events" in API group "" in the namespace "..."' (will not retry!)

I think the issue is that the recorderProvider used here doesn't use the LeaderElectionConfig:

recorderProvider, err := options.newRecorderProvider(config, cluster.GetScheme(), options.Logger.WithName("events"), options.makeBroadcaster)
if err != nil {
return nil, err
}
// Create the resource lock to enable leader election)
leaderConfig := options.LeaderElectionConfig
if leaderConfig == nil {
leaderConfig = rest.CopyConfig(config)
}
resourceLock, err := options.newResourceLock(leaderConfig, recorderProvider, leaderelection.Options{

JustinKuli added a commit to JustinKuli/controller-runtime that referenced this issue Feb 14, 2022
Fixes: kubernetes-sigs#1798

Signed-off-by: Justin Kulikauskas <jkulikau@redhat.com>
JustinKuli added a commit to JustinKuli/controller-runtime that referenced this issue Feb 15, 2022
Fixes: kubernetes-sigs#1798

Signed-off-by: Justin Kulikauskas <jkulikau@redhat.com>
JustinKuli added a commit to JustinKuli/controller-runtime that referenced this issue Feb 15, 2022
Fixes: kubernetes-sigs#1798

Signed-off-by: Justin Kulikauskas <jkulikau@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant