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 canonical meta types in prowjobs #6199

Merged
merged 4 commits into from
Jan 23, 2018
Merged

Use canonical meta types in prowjobs #6199

merged 4 commits into from
Jan 23, 2018

Conversation

0xmichalis
Copy link
Contributor

@0xmichalis 0xmichalis commented Jan 9, 2018

This PR vendors k8s/apimachinery and updates the prowjob API to use the canonical meta types. I will follow-up with vendoring k8s/api and k8s/client-go so we can drop the core k8s APIs that we maintain in test-infra and start generating prowjob informers.

Part of #1986

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jan 9, 2018
@0xmichalis
Copy link
Contributor Author

My latest try with dep seems more reasonable. What I did:

dep ensure
dep ensure -update k8s.io/apimachinery
dep prune
./hack/update-bazel.sh

There are still some dependencies that are updated but seem unrelated to the apimachinery repo which I am investigating.

@0xmichalis
Copy link
Contributor Author

Gopkg.lock changes seem correct.

@0xmichalis
Copy link
Contributor Author

Not sure how to debug the bazel failure.

@stevekuznetsov
Copy link
Contributor

@Kargakis I am going to try to get dependencies working this morning

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 12, 2018
@0xmichalis
Copy link
Contributor Author

Even more reasonable diff now. I just skipped dep ensure -update k8s.io/apimachinery, dep ensure seems to update the dependencies already. If we have green tests, then this should be ready to merge.

Copy link
Member

@cjwagner cjwagner left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 12, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cjwagner, kargakis

The full list of commands accepted by this bot can be found here.

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-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 12, 2018
@cjwagner
Copy link
Member

/hold
Oh, the kube.ObjectMeta type can be removed now.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 12, 2018
@0xmichalis
Copy link
Contributor Author

Oh, the kube.ObjectMeta type can be removed now.

Still used by pods. I am planning on moving pods to use the canonical types in a follow-up and then we can remove our types.

@fejta
Copy link
Contributor

fejta commented Jan 14, 2018

Try hack/update-deps.sh? You may need to add some drop dep lines (I haven't yet automated this part of the script just yet) to this script

@0xmichalis
Copy link
Contributor Author

The issue seems to be that some proto rules in the generated BUILD files inside apimachinery don't include vendor/ as a prefix. For example, here is an error from pull-test-infra-bazel:

W0115 15:13:28.474] ERROR: /workspace/k8s.io/test-infra/vendor/k8s.io/apimachinery/pkg/api/resource/BUILD:4:1: no such package 'k8s.io/apimachinery/pkg/util/intstr': BUILD file not found on package path and referenced by '//vendor/k8s.io/apimachinery/pkg/api/resource:resource_proto'

And here is the generated rule:

proto_library(
    name = "resource_proto",
    srcs = ["generated.proto"],
    visibility = ["//visibility:public"],
    deps = ["//k8s.io/apimachinery/pkg/util/intstr:intstr_proto"],
)

If //k8s.io/apimachinery/pkg/util/intstr:intstr_proto changes to //vendor/k8s.io/apimachinery/pkg/util/intstr:intstr_proto, everyone is happy. There are also a couple of other issues but I would expect those to go away by dropping dep lines in the script @fejta mentioned.

May it be an issue with how we use bazel? @ixdy @BenTheElder

@0xmichalis
Copy link
Contributor Author

I did some digging today and came up with a couple of different issues:

@0xmichalis
Copy link
Contributor Author

Any idea why/how we generate BUILD-e files?

@ixdy
Copy link
Member

ixdy commented Jan 16, 2018

At least somewhat related to the vendor/ issue is bazel-contrib/bazel-gazelle#63, but I'm not sure if that's the same issue that's happening here.

We might be running into issues with k/k (and thus apimachinery) using gazelle's "legacy" proto mode, while test-infra now uses the "normal" mode. I will investigate that theory.

What are BUILD-e files?

@ixdy
Copy link
Member

ixdy commented Jan 16, 2018

@BenTheElder what are these mysterious BUILD-e files?

@0xmichalis 0xmichalis changed the title [WIP] Use canonical meta types in prowjobs Use canonical meta types in prowjobs Jan 18, 2018
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 18, 2018
@0xmichalis
Copy link
Contributor Author

Fixed the remaining issues since kazel is updated. Hoping for green tests now 🙏 🙏 🙏

Metadata ObjectMeta `json:"metadata,omitempty"`
Spec ProwJobSpec `json:"spec,omitempty"`
Status ProwJobStatus `json:"status,omitempty"`
metav1.TypeMeta `json:",inline"`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hrm, I just realized this is not supported in Go yet: golang/go#6213

k8s is using a forked version of the json package.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems that k8s is using https://github.com/json-iterator/go for JSON marshalling/unmarshalling.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@deads2k @sttts what JSON library am I supposed to use outside of k8s in order to inline typemeta?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or this is something I shouldn't care about since it's supposedly handled by client-go?

Copy link
Contributor

Choose a reason for hiding this comment

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

@deads2k @sttts what JSON library am I supposed to use outside of k8s in order to inline typemeta?

jsoniter doesn't handle some cases of embedding. As I recall, it didn't work for openshift downstream. In theory, I think client-go will sort it for you. If not, I'd ask @thockin

@0xmichalis
Copy link
Contributor Author

I didn't have a lot of courage to deal with bazel this morning so I ended up creating a prowjob controller that uses client-go and informers in a separate repo to play around: https://github.com/kargakis/prowjob-controller

  • I changed ProwJob to use v1.PodSpec vs our own type and metav1.Time vs time.Time
  • GIven the correct directory structure, generation works like a breeze (thanks @sttts and the rest of the folks for making it happen!)
  • the controller seems to work as expected but I still need to verify watching of individual events

@0xmichalis
Copy link
Contributor Author

Also, the binary size of the controller, including k8s/api, k8s/apimachinery, and k8s/client-go is 34MB. Go seems to compile only what's actually used.

@0xmichalis
Copy link
Contributor Author

@ixdy I am updating gazelle to pick up bazel-contrib/bazel-gazelle#78, ptal

@0xmichalis
Copy link
Contributor Author

Finally green tests! 🎉

ObjectMeta ObjectMeta `json:"metadata,omitempty"`
Spec ProwJobSpec `json:"spec,omitempty"`
Status ProwJobStatus `json:"status,omitempty"`
APIVersion string `json:"apiVersion,omitempty"`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am leaving type meta as is for now. I will change to metav1.TypeMeta once we switch to use client-go (otherwise, it won't work).

@0xmichalis
Copy link
Contributor Author

@spxtr fyi

@spxtr
Copy link
Contributor

spxtr commented Jan 20, 2018

I endorse this PR.

Go seems to compile only what's actually used.

Unfortunately, because the reflect package exists, go cannot compile only what's actually used.

@0xmichalis 0xmichalis requested a review from ixdy January 22, 2018 10:03
@BenTheElder
Copy link
Member

@Kargakis this is pretty awesome, sadly it now needs another rebase after #6356. 😞

Do not switch type meta yet since struct inlining
does not work with Go's encoding/json.
@0xmichalis
Copy link
Contributor Author

Rebased

@0xmichalis
Copy link
Contributor Author

Green light on updating gazelle at #6388 (comment)

@fejta hopefully this won't break your update-deps.sh change.

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 23, 2018
@fejta
Copy link
Contributor

fejta commented Jan 23, 2018

Happy to deal with the fallout :)

@fejta
Copy link
Contributor

fejta commented Jan 23, 2018

thanks for getting this in!

@k8s-ci-robot k8s-ci-robot merged commit 600e402 into kubernetes:master Jan 23, 2018
@0xmichalis 0xmichalis deleted the import-canonical-k8s-api branch January 23, 2018 21:26
@BenTheElder
Copy link
Member

whoo! thanks @Kargakis! 🎉

@fejta
Copy link
Contributor

fejta commented Jan 23, 2018

I guess "happy" would be more accurate here 😉

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. 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.

9 participants