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

Use ObjectGetter Interface instead of clientset.Interface for leaderelection pkg #44338

Merged
merged 1 commit into from
May 2, 2017

Conversation

shashidharatd
Copy link

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:

NONE

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 11, 2017
@k8s-reviewable
Copy link

This change is Reviewable

@k8s-github-robot k8s-github-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. release-note-none Denotes a PR that doesn't merit a release note. labels Apr 11, 2017
@mikedanese
Copy link
Member

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?

@deads2k
Copy link
Contributor

deads2k commented Apr 12, 2017

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{
Copy link
Member

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.

@shashidharatd
Copy link
Author

Thanks for the review. i would get back on the suggestions.
meanwhile i also request @nikhiljindal, who is an expert on federation api's and the clientset to comment on this.

@shashidharatd
Copy link
Author

cc @kubernetes/sig-federation-api-reviews

@zhouhaibing089
Copy link
Contributor

@deads2k agree with your point ConfigmapGetter(though I believe not only getter)

@k8s-github-robot k8s-github-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 14, 2017
@shashidharatd
Copy link
Author

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:

# 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

I would open a new issue to fix the compatibility issue in federation clientset.
@nikhiljindal @caesarxuchao, do you have any suggestions

@shashidharatd shashidharatd changed the title Use rest.Interface instead of clientset.Interface for leaderelection pkg Use ObjectGetter Interface instead of clientset.Interface for leaderelection pkg Apr 14, 2017
@shashidharatd
Copy link
Author

The issue i mentioned above might get solved if we start using "k8s.io/client-go/kubernetes/typed/core/v1" pkg for corev1 client.

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 16, 2017
@@ -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"
Copy link
Member

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?

Copy link
Author

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.

Copy link
Member

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.

@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 17, 2017
@mikedanese
Copy link
Member

Thanks, lgtm. Please squash.

@caesarxuchao
Copy link
Member

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?

@nikhiljindal
Copy link
Contributor

Are the non-federation resources available on a federation apiserver

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
Copy link
Member

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.

Copy link
Author

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

Copy link
Member

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 :)

Copy link
Author

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.

@shashidharatd
Copy link
Author

@mikedanese, commits squashed. PTAL

@shashidharatd
Copy link
Author

@k8s-bot bazel test this

@mikedanese
Copy link
Member

@k8s-bot bazel test this

@mikedanese
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 18, 2017
@shashidharatd
Copy link
Author

@davidopp, can you approve if it looks good please

@k8s-github-robot k8s-github-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 19, 2017
@shashidharatd
Copy link
Author

@k8s-bot cvm gce e2e test this

@shashidharatd
Copy link
Author

@mikedanese, realized that the consumers of leaderelection can also pass clientset interface for Client which is a superset of corev1 client interface. So updated this pr to just contain the changes to leaderelection package. PTAL and request a LGTM once again.

@shashidharatd
Copy link
Author

@mikedanese, gentle reminder. This PR is smaller now :) request an lgtm again please.
Thanks !

@mikedanese
Copy link
Member

Sorry I missed this!

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 2, 2017
@k8s-github-robot
Copy link

[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 /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot
Copy link

@k8s-bot test this [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 40544, 44338, 45225)

@k8s-github-robot k8s-github-robot merged commit 932dabd into kubernetes:master May 2, 2017
@k8s-ci-robot
Copy link
Contributor

@shashidharatd: The following test(s) failed:

Test name Commit Details Rerun command
Jenkins GCE etcd3 e2e e23f1d5 link @k8s-bot gce etcd3 e2e test this

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.

@shashidharatd
Copy link
Author

Thanks @mikedanese

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet