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

Feat/4982 unwanted dependency checks #5509

Conversation

antoooks
Copy link
Contributor

@antoooks antoooks commented Jan 8, 2024

Addresses #4982

  • Add unwanted dependencies checking referring to kubernetes/kubernetes unwanted-dependencies.json file
  • Add unwanted-dependencies-check Github workflow

@k8s-ci-robot
Copy link
Contributor

This PR has multiple commits, and the default merge method is: merge.
You can request commits to be squashed using the label: tide/merge-method-squash

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.

@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. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 8, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @antoooks. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jan 8, 2024
@antoooks antoooks marked this pull request as draft January 8, 2024 15:14
@antoooks antoooks marked this pull request as ready for review January 8, 2024 15:44
@antoooks antoooks changed the title [WIP] Feat/4982 unwanted dependency checks Feat/4982 unwanted dependency checks Jan 8, 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 Jan 8, 2024
Copy link
Member

@charles-chenzz charles-chenzz left a comment

Choose a reason for hiding this comment

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

/ok-to-test

@@ -0,0 +1,42 @@
name: unwanted-dependencies-check

Copy link
Member

@charles-chenzz charles-chenzz Jan 10, 2024

Choose a reason for hiding this comment

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

can this yaml run on prow job? as we have an issue which want to migrate some actions workflows to prow
#5486

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a requirement to make the job optional, is it possible in prow to always run it but not cancelling the other pipeline?

Copy link
Member

Choose a reason for hiding this comment

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

I'm not quite sure, but prow can run multiple jobs and choose to make some jobs optional. we might need to investigate prow( but prow is quite a huge project)

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 have confirmed with @natasha41575, it is decided that for this PR we'll still stick to GH action, and if your PR for prow is already merged we can migrate it to prow

Copy link
Member

Choose a reason for hiding this comment

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

my PR for prow is still in pending review, we should merge this first

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 10, 2024
Copy link
Member

@varshaprasad96 varshaprasad96 left a comment

Choose a reason for hiding this comment

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

The changes look good to me. Looks like this test is failing in the CI for this PR. Can it be fixed?

@antoooks
Copy link
Contributor Author

antoooks commented Feb 7, 2024

The changes look good to me. Looks like this test is failing in the CI for this PR. Can it be fixed?

Hi @varshaprasad96, It is expected to be failed on purpose and will be treated as an optional test, so it won't affect approval. (please refer to the referenced issue page)

I think since it checks on different parts of kustomize, we should have a separate PR with respective domain owners doing the fix.

@varshaprasad96
Copy link
Member

Hi @varshaprasad96, It is expected to be failed on purpose and will be treated as an optional test, so it won't affect approval. (please refer to the referenced issue page)

Got it! Thanks!

Copy link
Member

@varshaprasad96 varshaprasad96 left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: antoooks, varshaprasad96

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 added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 7, 2024
@koba1t
Copy link
Member

koba1t commented Feb 8, 2024

Hi!
I think Kubernetes only imports below three packages. So we need to check only the below packages.
https://github.com/kubernetes/kubernetes/blob/f07b47c3d1e596f53640285afb0d53a81fe6f259/go.mod#L232-L234

@antoooks
Copy link
Contributor Author

antoooks commented Feb 8, 2024

Hi! I think Kubernetes only imports below three packages. So we need to check only the below packages. https://github.com/kubernetes/kubernetes/blob/f07b47c3d1e596f53640285afb0d53a81fe6f259/go.mod#L232-L234

Noted, thanks for pointing it out

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 8, 2024
@antoooks
Copy link
Contributor Author

antoooks commented Feb 8, 2024

@koba1t feedback added

@antoooks antoooks force-pushed the feat/4982-unwanted-dependency-checks branch from dd82d0c to 629f8a9 Compare February 21, 2024 15:39
@antoooks antoooks force-pushed the feat/4982-unwanted-dependency-checks branch from d7cc869 to 9f518fe Compare February 21, 2024 16:01
remove json file

add extra condition to ignore docs changes

revert unintended changes

revert unintended changes
@antoooks antoooks force-pushed the feat/4982-unwanted-dependency-checks branch from a95165a to 35fa808 Compare February 21, 2024 16:09
Copy link
Member

@charles-chenzz charles-chenzz left a comment

Choose a reason for hiding this comment

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

/lgtm
/assign @koba1t

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

FYI, the check meant to be fail because we do have unwanted dependencies :)

@koba1t
Copy link
Member

koba1t commented Mar 9, 2024

Hi @antoooks
Sorry for the delayed response. It's many times to take investigate.
I think there is something wrong with this check step.

For Example

in github.com/spf13/viper module.

in CI result

Looks like this dependency were found in the result.

...
Error: unwanted dependencies found. (github.com/spf13/viper at /home/runner/work/kustomize/kustomize/kyaml/go.sum)
Error: unwanted dependencies found. (github.com/spf13/viper at /home/runner/work/kustomize/kustomize/kustomize/go.sum)
Error: unwanted dependencies found. (github.com/spf13/viper at /home/runner/work/kustomize/kustomize/api/go.sum)
...

run go mod graph

github.com/spf13/viper was required only on the sigs.k8s.io/kustomize/cmd/gorepomod module. But this module appears in the go mod graph result.

$ pwd
${HOME}/kustomize/kustomize
$ go mod graph | grep viper           
sigs.k8s.io/kustomize/cmd/gorepomod github.com/spf13/[email protected]
github.com/spf13/[email protected] github.com/fsnotify/[email protected]
github.com/spf13/[email protected] github.com/hashicorp/[email protected]
github.com/spf13/[email protected] github.com/magiconair/[email protected]
...

I run after disabling to gowork.

$ GOWORK=off go mod graph | grep viper
$ 

Maybe this result was mixed in the go.work results.

Could you investigate this more?
If you need my help, please feel free to send a mention to me!

@antoooks
Copy link
Contributor Author

GOWORK=off go mod graph | grep viper

Hi @koba1t, thank you for checking and finding this, I have found a logic error on line 83, which supposed to detect if unwanted deps are exist inside go.sum. But instead I write it as -z $(cat $file | fgrep $dep) which means if it does not exist.

Same error also happened on line 92 with go mod graph.

@k8s-ci-robot
Copy link
Contributor

New changes are detected. LGTM label has been removed.

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

koba1t commented Mar 18, 2024

Thanks for your great work, @antoooks!

But I'm still concerned that the unwanted-dependencies-check is still down...
Maybe you need to look at "status.unwantedReferences" in the hack/unwanted-dependencies.json` file.
https://github.com/kubernetes/kubernetes/blob/aa73f3163a52e9a99df01b86f60eeed31abd54d9/cmd/dependencyverifier/dependencyverifier.go#L46-L48

Because I think this entry for the exception to the unwanted dependencies list.
https://github.com/kubernetes/kubernetes/pull/116598/files#diff-09f70f26cff6c34dc0063a45ca43cf5025d653058b06f7966fc8e6f3b9cecd3eR102

@antoooks
Copy link
Contributor Author

Thanks for your great work, @antoooks!

But I'm still concerned that the unwanted-dependencies-check is still down... Maybe you need to look at "status.unwantedReferences" in the hack/unwanted-dependencies.json` file. https://github.com/kubernetes/kubernetes/blob/aa73f3163a52e9a99df01b86f60eeed31abd54d9/cmd/dependencyverifier/dependencyverifier.go#L46-L48

Because I think this entry for the exception to the unwanted dependencies list. https://github.com/kubernetes/kubernetes/pull/116598/files#diff-09f70f26cff6c34dc0063a45ca43cf5025d653058b06f7966fc8e6f3b9cecd3eR102

Hey @koba1t, thanks for the feedback. Do you mean we need to whitelist dependencies in the PR commit you are referring on your comment?

with:
title: 🐛 unwanted-dependencies-check failed for ${{ github.sha }}
token: ${{ secrets.GITHUB_TOKEN }}
labels: kind/bug
Copy link
Member

@koba1t koba1t Mar 20, 2024

Choose a reason for hiding this comment

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

Maybe kind/dependencies is the better label for that issue.

READ_PATH=$(realpath ${JSON_PATH_LOCAL})
else
# Default behavior: pull unwanted-dependencies.json from kubernetes/kubernetes upstream repo
JSON_PATH_URL='https://raw.githubusercontent.com/kubernetes/kubernetes/e51fe4a61cca7f4a0875630da433f280b52c138a/hack/unwanted-dependencies.json'
Copy link
Member

Choose a reason for hiding this comment

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

I think that the JSON file may be old.
So, I think maybe better to use the latest file.

@koba1t
Copy link
Member

koba1t commented Mar 20, 2024

Hey @koba1t, thanks for the feedback. Do you mean we need to whitelist dependencies in the PR commit you are referring on your comment?

I think that is better because we have a few unwanted dependencies that we can't delete.
For example,
github.com/pkg/error was required evanphx/json-patch package, and we can't delete this dependency.
https://github.com/evanphx/json-patch/blob/master/v5/go.mod#L7

@antoooks
Copy link
Contributor Author

hi @koba1t , I have integrated all the changes we discussed. However it seems that the unwanted deps list on k/k has changed. Could you check for deps I need to put into whitelist?

@koba1t
Copy link
Member

koba1t commented Apr 17, 2024

 2024-03-27 15:06:09 (33.8 MB/s) - ‘/home/runner/work/kustomize/kustomize/hack/unwanted-dependencies.json’ saved [11055/11055]

Error: unwanted dependencies found. (github.com/mailru/easyjson at /home/runner/work/kustomize/kustomize/kustomize/go.sum)
Error: unwanted dependencies found. (github.com/mailru/easyjson at /home/runner/work/kustomize/kustomize/api/go.sum)
Error: unwanted dependencies found. (github.com/mailru/easyjson at /home/runner/work/kustomize/kustomize/kyaml/go.sum)
Error: unwanted dependencies found. (github.com/pkg/errors at /home/runner/work/kustomize/kustomize/kustomize/go.sum)
Error: unwanted dependencies found. (github.com/pkg/errors at /home/runner/work/kustomize/kustomize/api/go.sum)

The above dependencies are listed on the whitelist.
https://github.com/kubernetes/;kubernetes/blob/d831b13e6f6fb5efb566100286190fedca6dd340/hack/unwanted-dependencies.json#L162-L183

Maybe that is better to find the whitelist from the unwanted-dependencies.json files on k/k.

@antoooks
Copy link
Contributor Author

antoooks commented May 8, 2024

 2024-03-27 15:06:09 (33.8 MB/s) - ‘/home/runner/work/kustomize/kustomize/hack/unwanted-dependencies.json’ saved [11055/11055]

Error: unwanted dependencies found. (github.com/mailru/easyjson at /home/runner/work/kustomize/kustomize/kustomize/go.sum)
Error: unwanted dependencies found. (github.com/mailru/easyjson at /home/runner/work/kustomize/kustomize/api/go.sum)
Error: unwanted dependencies found. (github.com/mailru/easyjson at /home/runner/work/kustomize/kustomize/kyaml/go.sum)
Error: unwanted dependencies found. (github.com/pkg/errors at /home/runner/work/kustomize/kustomize/kustomize/go.sum)
Error: unwanted dependencies found. (github.com/pkg/errors at /home/runner/work/kustomize/kustomize/api/go.sum)

The above dependencies are listed on the whitelist. https://github.com/kubernetes/;kubernetes/blob/d831b13e6f6fb5efb566100286190fedca6dd340/hack/unwanted-dependencies.json#L162-L183

Maybe that is better to find the whitelist from the unwanted-dependencies.json files on k/k.

Thanks for the note @koba1t , fixed on the subsequent commit

@antoooks
Copy link
Contributor Author

/close due to deprioritisation

@antoooks antoooks closed this Jun 19, 2024
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Development

Successfully merging this pull request may close these issues.

7 participants