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 optional presubmit job to run apidiff on the client-go module #33866

Merged
merged 1 commit into from
Dec 12, 2024

Conversation

aojea
Copy link
Member

@aojea aojea commented Nov 27, 2024

Having an optional presubmit that gets executed automatically when a client-go file is modified, to run apidiff against the client-go module will be helpful for reviewers to understand the impact of the changes and, if necessary, evaluate if the breaking changes are necessary or can be done in a different way that does not break downstream clients (i.e. declare the old function deprecated and add a new one)

See gist with the differences between minors versions in client-go https://gist.github.com/aojea/696155fb3e2f8775574e6afddcb33cfc , it seems we were doing better overall, but being more consistent in this area will help to reduce the friction of the ecosystem that need to consume these APIS and clients, see kubernetes/kubernetes#124380

Reference to slack discussion https://kubernetes.slack.com/archives/C0EG7JC6T/p1732746366129629

Example execution:

./hack/apidiff.sh -t 26c08dde527c0d4453e95f49e3c6ef7663042f7b -r 9d62330bfa31a4fce28093d052f65ff0e88ac3a0  ./staging/src/k8s.io/client-go
Checking 26c08dde527c0d4453e95f49e3c6ef7663042f7b (= v1.32.0-beta.0-516-g26c08dde527) for API changes since 9d62330bfa31a4fce28093d052f65ff0e88ac3a0 (= v1.33.0-alpha.0-3-g9d62330bfa3).
Installing apidiff into /tmp/tmp.yRagAHGNPP.
Preparing worktree (detached HEAD 26c08dde527)
Updating files: 100% (26242/26242), done.
HEAD is now at 26c08dde527 Wait for updated keys to be observed
Preparing worktree (detached HEAD 9d62330bfa3)
Updating files: 100% (26242/26242), done.
HEAD is now at 9d62330bfa3 Merge pull request #128286 from umagnus/fix_unmount_relative_path

## ./staging/src/k8s.io/client-go
no changes

Some notes about API differences:

Changes in internal packages are usually okay.
However, remember that custom schedulers
and scheduler plugins depend on pkg/scheduler/framework.

API changes in staging repos are more critical.
Try to avoid them as much as possible.
But sometimes changing an API is the lesser evil
and/or the impact on downstream consumers is low.
Use common sense and code searches.

@aojea aojea requested a review from pohly November 27, 2024 22:37
@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. approved Indicates a PR has been approved by an approver from all required OWNERS files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. area/config Issues or PRs related to code in /config area/jobs sig/testing Categorizes an issue or PR as relevant to SIG Testing. labels Nov 27, 2024
@aojea
Copy link
Member Author

aojea commented Nov 27, 2024

@pohly if I run the script locally it does not work as I expect, but as we talked offline and if you see my gist it works fine, do you think is a problem of the hack script or of the environment?

./hack/apidiff.sh ./staging/src/k8s.io/client-go
Checking current working tree for API changes since 94a15929cf13354fdf3747cb266d511154f8c97b (= v1.28.0-alpha.0-315-g94a15929cf1).
Installing apidiff into /tmp/tmp.lzfNPXoYIp.
Preparing worktree (detached HEAD 94a15929cf1)
Updating files: 100% (23757/23757), done.
HEAD is now at 94a15929cf1 Merge pull request #116408 from ChenLingPeng/fit
loading ./staging/src/k8s.io/client-go: -: pattern ./staging/src/k8s.io/client-go/...: main module (k8s.io/kubernetes) does not contain package k8s.io/kubernetes/staging/src/k8s.io/client-go
!!! [1127 22:33:46] Call tree:
!!! [1127 22:33:46]  1: ./hack/apidiff.sh:184 run(...)
!!! [1127 22:33:46]  2: ./hack/apidiff.sh:200 inWorktree(...)
!!! [1127 22:33:46] Call tree:
!!! [1127 22:33:46]  1: ./hack/apidiff.sh:200 inWorktree(...)

EDIT

This seems to be a problem of getting the base from kubernetes versions without go workspaces, see description with good run

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 28, 2024
@aojea aojea changed the title [WIP] add optional presubmit job to run apidiff on the client-go module add optional presubmit job to run apidiff on the client-go module Nov 28, 2024
@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 Nov 28, 2024
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 28, 2024
@aojea
Copy link
Member Author

aojea commented Nov 28, 2024

/assign @deads2k @liggitt @jpbetz
/cc @BenTheElder @pohly
/sig api-machinery

@k8s-ci-robot k8s-ci-robot added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Nov 28, 2024
@liggitt
Copy link
Member

liggitt commented Nov 28, 2024

/lgtm
/hold in case you want more eyes before merge

@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Nov 28, 2024
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 28, 2024
@aojea
Copy link
Member Author

aojea commented Nov 28, 2024

Ok, this should be ready now, but still depends on kubernetes/kubernetes#129021 to support the wildecard and the modules that are not present in the workspace for the generated code

@aojea
Copy link
Member Author

aojea commented Dec 12, 2024

/hold cancel

The k/k fixes got merged

@pohly can you PTAL?

@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 Dec 12, 2024
# PR gets merged into. What we want instead is the revision at
# which the PR branch diverged from the target branch.
# We get that from "git merge-base".
- "./hack/apidiff.sh -r $(git merge-base ${PULL_BASE_SHA} ${PULL_PULL_SHA}) -t ${PULL_PULL_SHA} ./staging/src/k8s.io/code-generator/examples ./staging/src/k8s.io/client-go"
Copy link
Member

Choose a reason for hiding this comment

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

I recommend moving this fully out into a script somewhere, it will need iterating on and inline in prowjob config is a poor place to iterate on scripts.

I don't consider this a hard blocker, but seriously consider doing this sooner than later.
If it were planned to be a blocking job, I'd be more concerned.

The moment this apidiff script wants more computed inputs, we have a mess, but if some wrapper script takes in the prow envs, it's not a problem.

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 don't think adding an indirection in this case is going to help, if we end needing more complexity for this job then we are doing something wrong

Copy link
Member

Choose a reason for hiding this comment

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

usually the prowjob should make a trivial invocation like make test, and encapsulate the rest in the repo under test, where you can iterate on it with a tested PR

it's not about more complexity, it's about any change to how this needs to be invoked. right now you're passing quite a lot as arguments coming from env or even computed.

Copy link
Member

Choose a reason for hiding this comment

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

(which also makes local replication more difficult)

Copy link
Member Author

Choose a reason for hiding this comment

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

🤔 there are only 2 arguments that depend on prow variables

Copy link
Member

@BenTheElder BenTheElder Dec 12, 2024

Choose a reason for hiding this comment

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

(aside: PULL_PULL_SHA will not be set on batch PR runs, TODO to rework this out if we ever want a blocking job later)

https://docs.prow.k8s.io/docs/jobs/#job-environment-variables

Copy link
Contributor

Choose a reason for hiding this comment

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

apidiff.sh was meant to be agnostic of the CI system in which it gets run. But I don't feel strongly about this.

(aside: PULL_PULL_SHA will not be set on batch PR runs, TODO to rework this out if we ever want a blocking job later)

It's complexity like this that I wanted to keep out of the script... In the job it's clearer which variables are set. 🤷

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

apidiff.sh was meant to be agnostic of the CI system in which it gets run. But I don't feel strongly about this.

... eh... prow is the CI system Kubernetes uses, we normally support it in our tools / scripts.

It's complexity like this that I wanted to keep out of the script... In the job it's clearer which variables are set. 🤷

That complexity has to go somewhere, and it's harder to iterate on correctly if it's inline in the job.

Copy link
Member

Choose a reason for hiding this comment

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

(also, we're not requiring prow-like-environment-variables, just supporting it as a fallback if the args are not otherwise set, see the PR)

Copy link
Member

@BenTheElder BenTheElder left a comment

Choose a reason for hiding this comment

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

the REPO_ROOT value is wrong and should be detected in the apidiff script (or passed in via pwd if we really can't do it in the script for some reason, there's copy paste one-liners for this in k/k)

that's the only blocking concern

# A periodic job which shows API diffs for staging repos per day
- name: ci-kubernetes-apidiff-daily
cluster: eks-prow-build-cluster
interval: 24h
Copy link
Member

@BenTheElder BenTheElder Dec 12, 2024

Choose a reason for hiding this comment

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

this approach isn't technically guaranteed to schedule daily, you should probably use a cron for this and pick a particular time of day to run for consistency

Copy link
Member Author

Choose a reason for hiding this comment

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

it's a canary job, I just want to get some periodic signal , nothing else, if this work well we figure out a more elegant way of scheduling, but in the meantime think on it as a personal job, nothing else

Copy link
Member

Choose a reason for hiding this comment

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

OK, it's not that complicated though ... https://docs.prow.k8s.io/docs/jobs/#how-to-configure-new-jobs

You just swap this field for cron: <normal cron string>, e.g. cron: 0 0 * * * would run every day at midnight UTC

Copy link
Member

Choose a reason for hiding this comment

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

If the time window matches, the report will be more useful, otherwise it will vary by how many developers have recently been merging code. not blocking, but consider this in a follow-up. We can look at the merge graph in k/k.

Copy link
Member

Choose a reason for hiding this comment

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

this thread is non-blocking, we can do this in a follow-up, but I strongly recommend it.

interval: 24h is almost always not what people actually want, interval makes sense for frequently run things where we don't want to stack up missed runs from the job potentially taking longer than the interval, and we don't care at all about timing otherwise.

pretty much any job with a long interval is using a cron instead for this reason, the scheduling is more predictable.

for a daily report you want predictable, so you can reliably check it after it's done.
the timing of interval is affected by when it was first introduced, any disruptions to prow, and any other jitter, since it's always computed since the last run.

@aojea
Copy link
Member Author

aojea commented Dec 12, 2024

the REPO_ROOT value is wrong and should be detected in the apidiff script (or passed in via pwd if we really can't do it in the script for some reason, there's copy paste one-liners for this in k/k)

that's the only blocking concern

that variable is not used, at least I didn't find where, so I removed it

@BenTheElder
Copy link
Member

/lgtm
/approve
let's iterate on the other details.

after kubernetes/kubernetes#129188 we could gracefully drop some of the flags in presubmit and streamline it.

I'll send a follow-up to switch to a cron for the periodic.

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aojea, BenTheElder

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

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 12, 2024
Copy link
Member

@BenTheElder BenTheElder 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 Dec 12, 2024
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 12, 2024
@BenTheElder
Copy link
Member

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 12, 2024
@k8s-ci-robot k8s-ci-robot merged commit c00c8c6 into kubernetes:master Dec 12, 2024
7 checks passed
@k8s-ci-robot
Copy link
Contributor

@aojea: Updated the job-config configmap in namespace default at cluster test-infra-trusted using the following files:

  • key apidiff.yaml using file config/jobs/kubernetes/sig-testing/apidiff.yaml

In response to this:

Having an optional presubmit that gets executed automatically when a client-go file is modified, to run apidiff against the client-go module will be helpful for reviewers to understand the impact of the changes and, if necessary, evaluate if the breaking changes are necessary or can be done in a different way that does not break downstream clients (i.e. declare the old function deprecated and add a new one)

See gist with the differences between minors versions in client-go https://gist.github.com/aojea/696155fb3e2f8775574e6afddcb33cfc , it seems we were doing better overall, but being more consistent in this area will help to reduce the friction of the ecosystem that need to consume these APIS and clients, see kubernetes/kubernetes#124380

Reference to slack discussion https://kubernetes.slack.com/archives/C0EG7JC6T/p1732746366129629

Example execution:

./hack/apidiff.sh -t 26c08dde527c0d4453e95f49e3c6ef7663042f7b -r 9d62330bfa31a4fce28093d052f65ff0e88ac3a0  ./staging/src/k8s.io/client-go
Checking 26c08dde527c0d4453e95f49e3c6ef7663042f7b (= v1.32.0-beta.0-516-g26c08dde527) for API changes since 9d62330bfa31a4fce28093d052f65ff0e88ac3a0 (= v1.33.0-alpha.0-3-g9d62330bfa3).
Installing apidiff into /tmp/tmp.yRagAHGNPP.
Preparing worktree (detached HEAD 26c08dde527)
Updating files: 100% (26242/26242), done.
HEAD is now at 26c08dde527 Wait for updated keys to be observed
Preparing worktree (detached HEAD 9d62330bfa3)
Updating files: 100% (26242/26242), done.
HEAD is now at 9d62330bfa3 Merge pull request #128286 from umagnus/fix_unmount_relative_path

## ./staging/src/k8s.io/client-go
no changes

Some notes about API differences:

Changes in internal packages are usually okay.
However, remember that custom schedulers
and scheduler plugins depend on pkg/scheduler/framework.

API changes in staging repos are more critical.
Try to avoid them as much as possible.
But sometimes changing an API is the lesser evil
and/or the impact on downstream consumers is low.
Use common sense and code searches.

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-sigs/prow repository.

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. area/config Issues or PRs related to code in /config area/jobs 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. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants