-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
Use ObjectGetter Interface instead of clientset.Interface for leaderelection pkg #44338
Use ObjectGetter Interface instead of clientset.Interface for leaderelection pkg #44338
Conversation
2c8455d
to
f86570f
Compare
These seems wrong. We are subverting all the query param and path versioning built into the client with this change. Why aren't you using a typed client? cc @deads2k @caesarxuchao what do you guys think? |
I would expect a typed client. Maybe you just want a configmap getter? |
@@ -60,15 +68,21 @@ func (el *EndpointsLock) Create(ler LeaderElectionRecord) error { | |||
if err != nil { | |||
return err | |||
} | |||
el.e, err = el.Client.Core().Endpoints(el.EndpointsMeta.Namespace).Create(&v1.Endpoints{ |
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 Endpoints missed in federation clientset? You can generate it by adding endpoints
at this line. I'm not sure if the generated client will actually work, you might need to register it to the federation's scheme
as well, but it's worth a try.
Thanks for the review. i would get back on the suggestions. |
cc @kubernetes/sig-federation-api-reviews |
@deads2k agree with your point |
f86570f
to
dc7f454
Compare
Thank you all for suggestions. Now i used ConfigMapsGetter for ConfigMapLock and EndpointsGetter for EndpointsLock. it worked out pretty well. @mikedanese, @deads2k PTAL However we do have a situation in federation wherein i am not able to use the ConfigMapGetter from federation clientset. I am getting below error:
I would open a new issue to fix the compatibility issue in federation clientset. |
The issue i mentioned above might get solved if we start using "k8s.io/client-go/kubernetes/typed/core/v1" pkg for corev1 client. |
@@ -23,14 +23,14 @@ import ( | |||
|
|||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | |||
"k8s.io/kubernetes/pkg/api/v1" | |||
"k8s.io/kubernetes/pkg/client/clientset_generated/clientset" | |||
corev1client "k8s.io/kubernetes/pkg/client/clientset_generated/clientset/typed/core/v1" |
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.
might be out of scope, but why don't we use client-go here?
Would that require a big "switch-all" to client-go?
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.
yes @luxas, it requires big "switch-all" to client-go and is out of scope for this pr.
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.
It will be done in #39173.
dc7f454
to
616594b
Compare
Thanks, lgtm. Please squash. |
I'm not familiar with federation. Are the non-federation resources available on a federation apiserver? If so, we can plumb a clientset to the federation control plane. @nikhiljindal wdyt? |
Not today. We want to support that #33622. |
@@ -35,7 +35,7 @@ type ConfigMapLock struct { | |||
// ConfigMapMeta should contain a Name and a Namespace of an | |||
// ConfigMapMeta object that the Leadercmlector will attempt to lead. | |||
ConfigMapMeta metav1.ObjectMeta | |||
Client clientset.Interface | |||
Client corev1client.ConfigMapsGetter |
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.
Can we pass corev1client.ConfigMapInterface around, i.e., passing Client.ConfigMaps(ConfigMapMeta.Namespace) around? It looks like federation.ConfigMapInterface has the same methods as corev1client.ConfigMapInterface, so you can reuse the leaderelection code for federation.
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.
@caesarxuchao, even though ConfigMapInterface is the same, as they are generated. they are 2 different types today as is evident from below error i got when i passed federation corev1 client.
# k8s.io/kubernetes/federation/cmd/federation-controller-manager/app
federation/cmd/federation-controller-manager/app/controllermanager.go:163: cannot use leaderElectionClient.CoreV1() (type "k8s.io/kubernetes/federation/client/clientset_generated/federation_clientset/typed/core/v1".CoreV1Interface) as type "k8s.io/kubernetes/pkg/client/clientset_generated/clientset/typed/core/v1".ConfigMapsGetter in field value:
"k8s.io/kubernetes/federation/client/clientset_generated/federation_clientset/typed/core/v1".CoreV1Interface does not implement "k8s.io/kubernetes/pkg/client/clientset_generated/clientset/typed/core/v1".ConfigMapsGetter (wrong type for ConfigMaps method)
have ConfigMaps(string) "k8s.io/kubernetes/federation/client/clientset_generated/federation_clientset/typed/core/v1".ConfigMapInterface
want ConfigMaps(string) "k8s.io/kubernetes/pkg/client/clientset_generated/clientset/typed/core/v1".ConfigMapInterface
we should start using client-go, then these types will be unique
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.
we should start using client-go, then these types will be unique
I don't think so, client-go doesn't include any federation code.
I saw this error message, it's saying federation corev1 cannot be used as clientset's ConfigMapsGetter, because although the two definitions of ConfigMapInterface are the same, to the compiler, they are two different types.
However, if you pass federation.ConfigMapInterface directly, compiler should accept it as a clientset.ConfigMapInterface, because they have the same methods defined.
I didn't try it though, so i could be wrong :)
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.
Okie, i will try. thanks for suggestion.
616594b
to
ef13a4c
Compare
@mikedanese, commits squashed. PTAL |
@k8s-bot bazel test this |
@k8s-bot bazel test this |
/lgtm |
@davidopp, can you approve if it looks good please |
ef13a4c
to
e23f1d5
Compare
@k8s-bot cvm gce e2e test this |
@mikedanese, realized that the consumers of |
@mikedanese, gentle reminder. This PR is smaller now :) request an lgtm again please. |
Sorry I missed this! /lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: mikedanese, shashidharatd
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
@k8s-bot test this [submit-queue is verifying that this PR is safe to merge] |
Automatic merge from submit-queue (batch tested with PRs 40544, 44338, 45225) |
@shashidharatd: The following test(s) failed:
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
Thanks @mikedanese |
What this PR does / why we need it:
We plan to reuse leaderelection pkg to add leader election function to federation controller manager, but the current implementation uses kubernetes clientset.Interface and federation clientset does not satisfy all the interface methods. It would be better if the leaderelection package use rest.Interface which is also supported by federation clientset.
This pr is to refactor leaderelection pkg to use rest.Interface instead of clientset.Interface
Special notes for your reviewer:
This is a sub-task of bigger work to add leader election to federation controller manager as documented in #44283
Release note: