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

Add tooling to generate listers #35639

Merged
merged 4 commits into from
Nov 1, 2016
Merged

Conversation

ncdc
Copy link
Member

@ncdc ncdc commented Oct 26, 2016

Add lister-gen tool to auto-generate listers. So far this PR only demonstrates replacing the manually-written StoreToLimitRangeLister with the generated LimitRangeLister, as it's a small and easy swap.

cc @deads2k @liggitt @sttts @nikhiljindal @lavalamp @smarterclayton @derekwaynecarr @kubernetes/sig-api-machinery @kubernetes/rh-cluster-infra


This change is Reviewable

@ncdc ncdc added sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. release-note-none Denotes a PR that doesn't merit a release note. labels Oct 26, 2016
@@ -71,4 +73,21 @@ ${clientgen} --clientset-name=federation_internalclientset --clientset-path=k8s.
${clientgen} --clientset-name=federation_release_1_5 --clientset-path=k8s.io/kubernetes/federation/client/clientset_generated --input="../../federation/apis/federation/v1beta1","api/v1","extensions/v1beta1" --included-types-overrides="api/v1/Service,api/v1/Namespace,extensions/v1beta1/ReplicaSet,api/v1/Secret,extensions/v1beta1/Ingress,extensions/v1beta1/Deployment,extensions/v1beta1/DaemonSet,api/v1/ConfigMap,api/v1/Event" "$@"
${setgen} "$@"

LISTERGEN_APIS=(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deads2k I don't really like doing it this way, but I need to use the internal packages, not the versioned ones, and KUBE_AVAILABLE_GROUP_VERSIONS only contains the versioned packages. I'll gladly welcome any suggestions for how to improve this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deads2k I don't really like doing it this way, but I need to use the internal packages, not the versioned ones, and KUBE_AVAILABLE_GROUP_VERSIONS only contains the versioned packages. I'll gladly welcome any suggestions for how to improve this.

based on the sig-api-machinery call, I suspect we want both internal an external.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Especially if we have each GV for listers in its own package, this won't be an issue.

@k8s-github-robot k8s-github-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Oct 26, 2016
@ncdc ncdc assigned sttts, liggitt and deads2k and unassigned mikedanese Oct 26, 2016
// PodDisruptionBudgetLister helps list PodDisruptionBudgets.
type PodDisruptionBudgetLister interface {
// List lists all PodDisruptionBudgets in the indexer.
List(selector labels.Selector) (ret []*policy.PodDisruptionBudget, err error)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cool. I think it will be easy modify lister-gen to generate List functions that return v1alpha1.PDB? I would like to include the versioned Listers in client-go.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@caesarxuchao yeah, it should be. All the generated files for a single invocation of lister-gen go into the same package, and it's configurable, so we could run it multiple times for each set of apis we want to group together. Or we could decide that each api group gets its listers in an appropriately named package, per group. WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my perspective, I'd like to keep versioned and internalversioned listers in different packages, like how we organize clientset. That makes porting to client-go easy, because client-go should only expose versioned APIs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you handle batch/v1 and batch/v2alpha1? You can't put listers for both of those api groups into the same package.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both are generated (BatchV1 and BatchV2alpha1, there's also Batch which picks the preferred version but that's deprecated, already) , user needs to pick one explicitly, see #35471.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@soltysh right, but both v1 and v2alpha1 have a Job, so I can't generate a JobLister for both GVs in the same package.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized that probably v2alpha1.Job is not being used anywhere and you can do anything with it :/

var typeLister_NonNamespacedGet = `
// Get retrieves the $.type|public$ from the index for a given name.
func (s *$.type|private$Lister) Get(name string) (*$.type|raw$, error) {
key := &$.type|raw${ObjectMeta: api.ObjectMeta{Name: name}}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I discovered that I can't blindly use api.ObjectMeta because the package won't always be api. I need to find a way to consistently pick the right package for ObjectMeta for each type in question. For right now, it's either api or v1, but at some point, if we have v2.ObjectMeta, I'd love to be able to support that w/o having to modify lister-gen after the fact.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a local fix for this 😄

@deads2k
Copy link
Contributor

deads2k commented Oct 26, 2016

Can we separate the output to /pkg/client/listers/<group>/<version>/<resource>.go?

@ncdc
Copy link
Member Author

ncdc commented Oct 26, 2016

@deads2k yes, we can. Just waiting on agreement.

@deads2k
Copy link
Contributor

deads2k commented Oct 26, 2016

I like the output.

@caesarxuchao
Copy link
Member

caesarxuchao commented Oct 26, 2016

 Can we separate the output to /pkg/client/listers/<group>/<version>/<resource>.go?

It sounds good to me. It will solve the v1 job lister v.s. v2alpha job lister problem.

@ncdc
Copy link
Member Author

ncdc commented Oct 26, 2016

Ok, sold. I will separate by group and version.

@caesarxuchao
Copy link
Member

Is the plan to put the internal one under <group>/internalversion/<resource>.go?

@ncdc
Copy link
Member Author

ncdc commented Oct 26, 2016

For v1 pods, we'd find them in pkg/client/listers/core/v1/pods.go.

For internal pods, options could be:

  • pkg/client/listers/core/pods.go
  • pkg/client/listers/core/internal/pods.go
  • pkg/client/listers/core/internalversion/pods.go
  • something else?

@caesarxuchao
Copy link
Member

I like pkg/client/listers/core/internalversion/pods.go. It's similar to the structure of clientsets (currently clientset uses name "unversioned", it will be changed to "internalversion" in #35471).

@deads2k
Copy link
Contributor

deads2k commented Oct 26, 2016

I like pkg/client/listers/core/internal/pods.go

@caesarxuchao
Copy link
Member

I can update #35471 to use "internal", if that's what people agree on.

@ncdc
Copy link
Member Author

ncdc commented Oct 26, 2016

internal sounds better to me

@caesarxuchao
Copy link
Member

caesarxuchao commented Oct 26, 2016

I remembered golang reserves "internal" package, it means something different. See: https://docs.google.com/document/d/1e8kOo3r51b2BWtTs_1uADIA5djfXhPT36s6eHVRIvaU/edit

@ncdc
Copy link
Member Author

ncdc commented Oct 27, 2016

I remember that now. I still think "internalversion" doesn't sound great,
but if we can't find anything better, I can use that.

On Wed, Oct 26, 2016 at 6:53 PM, Chao Xu notifications@github.com wrote:

I remembered golang reserves "internal" package, it means something
different.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#35639 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAABYuOKs_O65LZ2x0gawvYRwn4WGAo5ks5q39nogaJpZM4KhZbN
.

if extractBoolTagOrDie("genclient", t.SecondClosestCommentLines) == false {
continue
}
if _, found := gvToTypes[gv]; !found {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the if block.

var packageList generator.Packages

orderer := namer.Orderer{Namer: namer.NewPrivateNamer(0)}
for i := range groupVersions {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for i, gv

type PetSetLister interface {
// List lists all PetSets in the indexer.
List(selector labels.Selector) (ret []*apps.PetSet, err error)
// PetSets returns an object that can list and get PetSets.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... in a given namespace.

@ncdc
Copy link
Member Author

ncdc commented Oct 27, 2016

I'm refactoring what files this generates - hold off for reviewing for now

@ncdc
Copy link
Member Author

ncdc commented Oct 27, 2016

Does this list of generated files look ok?

pkg/client/listers/core/internalversion/zz_generated.listers.Pod.go
pkg/client/listers/core/internalversion/zz_generated.listers.Node.go
pkg/client/listers/core/internalversion/zz_generated.listers.Secret.go
pkg/client/listers/core/internalversion/zz_generated.listers.PersistentVolume.go
pkg/client/listers/core/internalversion/zz_generated.listers.Event.go
pkg/client/listers/core/internalversion/zz_generated.listers.LimitRange.go
pkg/client/listers/core/internalversion/zz_generated.listers.ComponentStatus.go
pkg/client/listers/core/internalversion/zz_generated.listers.ResourceQuota.go
pkg/client/listers/core/internalversion/zz_generated.listers.PodTemplate.go
pkg/client/listers/core/internalversion/zz_generated.listers.ConfigMap.go
pkg/client/listers/core/internalversion/zz_generated.listers.Namespace.go
pkg/client/listers/core/internalversion/zz_generated.listers.Endpoints.go
pkg/client/listers/core/internalversion/zz_generated.listers.PersistentVolumeClaim.go
pkg/client/listers/core/internalversion/zz_generated.listers.ReplicationController.go
pkg/client/listers/core/internalversion/zz_generated.listers.Service.go
pkg/client/listers/core/internalversion/zz_generated.listers.ServiceAccount.go
pkg/client/listers/core/v1/zz_generated.listers.ComponentStatus.go
pkg/client/listers/core/v1/zz_generated.listers.ResourceQuota.go
pkg/client/listers/core/v1/zz_generated.listers.Pod.go
pkg/client/listers/core/v1/zz_generated.listers.Namespace.go
pkg/client/listers/core/v1/zz_generated.listers.Service.go
pkg/client/listers/core/v1/zz_generated.listers.PersistentVolume.go
pkg/client/listers/core/v1/zz_generated.listers.Event.go
pkg/client/listers/core/v1/zz_generated.listers.Secret.go
pkg/client/listers/core/v1/zz_generated.listers.ConfigMap.go
pkg/client/listers/core/v1/zz_generated.listers.PodTemplate.go
pkg/client/listers/core/v1/zz_generated.listers.ReplicationController.go
pkg/client/listers/core/v1/zz_generated.listers.Node.go
pkg/client/listers/core/v1/zz_generated.listers.ServiceAccount.go
pkg/client/listers/core/v1/zz_generated.listers.Endpoints.go
pkg/client/listers/core/v1/zz_generated.listers.LimitRange.go
pkg/client/listers/core/v1/zz_generated.listers.PersistentVolumeClaim.go
pkg/client/listers/apps/internalversion/zz_generated.listers.PetSet.go
pkg/client/listers/apps/v1alpha1/zz_generated.listers.PetSet.go
pkg/client/listers/authentication/internalversion/zz_generated.listers.TokenReview.go
pkg/client/listers/authentication/v1beta1/zz_generated.listers.TokenReview.go
pkg/client/listers/authorization/internalversion/zz_generated.listers.SubjectAccessReview.go
pkg/client/listers/authorization/internalversion/zz_generated.listers.LocalSubjectAccessReview.go
pkg/client/listers/authorization/internalversion/zz_generated.listers.SelfSubjectAccessReview.go
pkg/client/listers/authorization/v1beta1/zz_generated.listers.LocalSubjectAccessReview.go
pkg/client/listers/authorization/v1beta1/zz_generated.listers.SelfSubjectAccessReview.go
pkg/client/listers/authorization/v1beta1/zz_generated.listers.SubjectAccessReview.go
pkg/client/listers/autoscaling/internalversion/zz_generated.listers.HorizontalPodAutoscaler.go
pkg/client/listers/autoscaling/v1/zz_generated.listers.HorizontalPodAutoscaler.go
pkg/client/listers/batch/internalversion/zz_generated.listers.Job.go
pkg/client/listers/batch/internalversion/zz_generated.listers.ScheduledJob.go
pkg/client/listers/batch/v1/zz_generated.listers.Job.go
pkg/client/listers/certificates/internalversion/zz_generated.listers.CertificateSigningRequest.go
pkg/client/listers/certificates/v1alpha1/zz_generated.listers.CertificateSigningRequest.go
pkg/client/listers/extensions/internalversion/zz_generated.listers.NetworkPolicy.go
pkg/client/listers/extensions/internalversion/zz_generated.listers.Ingress.go
pkg/client/listers/extensions/internalversion/zz_generated.listers.ReplicaSet.go
pkg/client/listers/extensions/internalversion/zz_generated.listers.ThirdPartyResource.go
pkg/client/listers/extensions/internalversion/zz_generated.listers.DaemonSet.go
pkg/client/listers/extensions/internalversion/zz_generated.listers.PodSecurityPolicy.go
pkg/client/listers/extensions/internalversion/zz_generated.listers.Scale.go
pkg/client/listers/extensions/internalversion/zz_generated.listers.Deployment.go
pkg/client/listers/extensions/v1beta1/zz_generated.listers.Job.go
pkg/client/listers/extensions/v1beta1/zz_generated.listers.Ingress.go
pkg/client/listers/extensions/v1beta1/zz_generated.listers.PodSecurityPolicy.go
pkg/client/listers/extensions/v1beta1/zz_generated.listers.Scale.go
pkg/client/listers/extensions/v1beta1/zz_generated.listers.ReplicaSet.go
pkg/client/listers/extensions/v1beta1/zz_generated.listers.ThirdPartyResource.go
pkg/client/listers/extensions/v1beta1/zz_generated.listers.Deployment.go
pkg/client/listers/extensions/v1beta1/zz_generated.listers.DaemonSet.go
pkg/client/listers/imagepolicy/internalversion/zz_generated.listers.ImageReview.go
pkg/client/listers/imagepolicy/v1alpha1/zz_generated.listers.ImageReview.go
pkg/client/listers/policy/internalversion/zz_generated.listers.PodDisruptionBudget.go
pkg/client/listers/policy/v1alpha1/zz_generated.listers.PodDisruptionBudget.go
pkg/client/listers/rbac/internalversion/zz_generated.listers.ClusterRoleBinding.go
pkg/client/listers/rbac/internalversion/zz_generated.listers.Role.go
pkg/client/listers/rbac/internalversion/zz_generated.listers.ClusterRole.go
pkg/client/listers/rbac/internalversion/zz_generated.listers.RoleBinding.go
pkg/client/listers/rbac/v1alpha1/zz_generated.listers.Role.go
pkg/client/listers/rbac/v1alpha1/zz_generated.listers.RoleBinding.go
pkg/client/listers/rbac/v1alpha1/zz_generated.listers.ClusterRole.go
pkg/client/listers/rbac/v1alpha1/zz_generated.listers.ClusterRoleBinding.go
pkg/client/listers/storage/internalversion/zz_generated.listers.StorageClass.go
pkg/client/listers/storage/v1beta1/zz_generated.listers.StorageClass.go

@caesarxuchao
Copy link
Member

The generated files lgtm.

Regarding whether having zz_generated, it depends on whether we want to check in the code to the repo in the future, because I remember @thockin planed to not checking in files with this prefix. I think having the prefix is fine.

@deads2k
Copy link
Contributor

deads2k commented Oct 28, 2016

Regarding whether having zz_generated, it depends on whether we want to check in the code to the repo in the future, because I remember @thockin planed to not checking in files with this prefix. I think having the prefix is fine.

We'll need the interfaces at compile/editing time or our searches won't work well.

@ncdc
Copy link
Member Author

ncdc commented Oct 28, 2016

Any other comments?

@deads2k deads2k added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 28, 2016
@deads2k
Copy link
Contributor

deads2k commented Oct 28, 2016

lgtm

@k8s-ci-robot
Copy link
Contributor

Jenkins unit/integration failed for commit d270474. Full PR test history.

The magic incantation to run this job again is @k8s-bot unit test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

@k8s-ci-robot
Copy link
Contributor

Jenkins verification failed for commit d270474. Full PR test history.

The magic incantation to run this job again is @k8s-bot verify test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

@ncdc
Copy link
Member Author

ncdc commented Oct 31, 2016

Rebased and updated now that #35471 went in. @deads2k please take another look, thanks.

@deads2k
Copy link
Contributor

deads2k commented Oct 31, 2016

still lgtm

@caesarxuchao
Copy link
Member

Thanks @ncdc.

@k8s-github-robot k8s-github-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 31, 2016
@ncdc ncdc added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 31, 2016
@thockin
Copy link
Member

thockin commented Oct 31, 2016

Any file named zz_generated.* should be created "on demand" as part of the
build. This introduces a generator that is NOT plugged into Makefile. It
should probably be.

On Mon, Oct 31, 2016 at 7:39 PM, Kubernetes Submit Queue <
notifications@github.com> wrote:

/lgtm cancel //PR changed after LGTM, removing LGTM. @deads2k
https://github.com/deads2k @liggitt https://github.com/liggitt @ncdc
https://github.com/ncdc @sttts https://github.com/sttts


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#35639 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFVgVNQCUPEu4aCVBhVpselxSIIXhO6mks5q5jXvgaJpZM4KhZbN
.

@k8s-ci-robot
Copy link
Contributor

Jenkins GKE smoke e2e failed for commit 13abf36. Full PR test history.

The magic incantation to run this job again is @k8s-bot cvm gke e2e test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

@k8s-ci-robot
Copy link
Contributor

Jenkins GCE Node e2e failed for commit 13abf36. Full PR test history.

The magic incantation to run this job again is @k8s-bot node e2e test this. Please help us cut down flakes by linking to an open flake issue when you hit one in your PR.

@ncdc
Copy link
Member Author

ncdc commented Nov 1, 2016

@thockin

Any file named zz_generated.* should be created "on demand" as part of the build.

Meaning a) we should remove zz_generated from these files and still commit them, or b) we should leave zz_generated and not check them in?

This introduces a generator that is NOT plugged into Makefile. It should probably be.

It's related to client-gen, which is also not plugged into Makefile. Do you want to ultimately get rid of hack/update-codegen.sh (client-gen, set-gen, and lister-gen added by this PR)? If so, could we do that in a follow-up?

@ncdc
Copy link
Member Author

ncdc commented Nov 1, 2016

Infra flakes

@k8s-bot cvm gke e2e test this

@ncdc
Copy link
Member Author

ncdc commented Nov 1, 2016

Infra flakes @k8s-bot node e2e test this

@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

@k8s-github-robot k8s-github-robot merged commit 1fa8369 into kubernetes:master Nov 1, 2016
@caesarxuchao
Copy link
Member

client-go needs to copy these files from the main repo, so we do need to commit these files, at least until client-go becomes independent of the main repo, so we shouldn't include zz_generated in the file names.

@thockin
Copy link
Member

thockin commented Nov 2, 2016

On Tue, Nov 1, 2016 at 3:14 PM, Andy Goldstein notifications@github.com wrote:

@thockin

Any file named zz_generated.* should be created "on demand" as part of the build.

Meaning a) we should remove zz_generated from these files and still commit them, or b) we should leave zz_generated and not check them in?

Meaning you should use a different name until they are generated on
demand, at which time we can name them zz_generated...

This introduces a generator that is NOT plugged into Makefile. It should probably be.

It's related to client-gen, which is also not plugged into Makefile. Do you want to ultimately get rid of hack/update-codegen.sh (client-gen, set-gen, and lister-gen added by this PR)? If so, could we do that in a follow-up?

If this generator can not reasonably be tied into the build yet,
that's OK. It is my intention/aspiration to make all generated
files stop being checked in, but primarily around pkg/apis?/*.
Including JSON.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet