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

🌱 Import Boss API restrictions should be transitive #9483

Closed

Conversation

JoelSpeed
Copy link
Contributor

What this PR does / why we need it:
We need to make sure that the packages transitive dependencies also don't import controller runtime for proper cleanliness and to prevent regressions.

Part of #9011

cc @sbueringer

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-area PR is missing an area label size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Sep 21, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign neolit123 for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

Copy link
Member

@chrischdi chrischdi left a comment

Choose a reason for hiding this comment

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

Makes sense!

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 21, 2023
@killianmuldoon
Copy link
Contributor

/area ci

Were you able to get the script to fail for transitive dependencies when using this? It doesn't seem to fail for me for the utils import in the addons/api/v1beta1 package

@k8s-ci-robot k8s-ci-robot added area/ci Issues or PRs related to ci and removed do-not-merge/needs-area PR is missing an area label labels Sep 21, 2023
@chrischdi
Copy link
Member

I'd still have expected that to fail for the ones whcih are not fixed?

/lgtm cancel

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 21, 2023
@JoelSpeed
Copy link
Contributor Author

So i'm trying to test this, but I can't actually get the import-boss to fail on anything at the moment, which is worrying

/hold until I can work out how to get it to fail on importing a controller-runtime package

@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 Sep 21, 2023
@killianmuldoon
Copy link
Contributor

So i'm trying to test this, but I can't actually get the import-boss to fail on anything at the moment, which is worrying

I was about to ask this - I haven't actually reviewed any PRs with it until now.

@JoelSpeed
Copy link
Contributor Author

So Import Boss, like most other gengo related projects, does not like relative paths, which is how we are configuring it right now.

When we pass --input-dirs, we currently use ./api as an example, you need to use sigs.k8s.io/cluster-api.api and use the proper go package name.

When it traverses the Universe of objects it discovers, it does a prefix match on the inputs, so only packages that it finds, which have an --input-dirs value as a prefix, are included in the files to be verified.

Currently it's comparing proper import paths with relative paths and nothing is actually being verified.

@chrischdi
Copy link
Member

@JoelSpeed
Copy link
Contributor Author

@chrischdi Can you get a positive failure on CAPV?
We have the unset GOPATH in the script for CAPI too

I just tried adding some debug logic to the skip and I don't think, even with the unset GOPATH it can be working

Skipping sigs.k8s.io/cluster-api/api/v1beta1 as it is not included in [./api/v1alpha4 ./api/v1beta1/index ./api/v1beta1]

The first string is the package name of a package we included in input dirs, but the logic here is causing it to skip the package

@JoelSpeed
Copy link
Contributor Author

I've been playing with various combinations and stepping through import-boss with a debugger, I can see no way that this can possibly work with relative paths, every combination of GOPATH set/unset and relative and package names, always ends up with the package name being compared against the input dir string.

My conclusion so far is that you have to have import-boss inside GOPATH for it to work, I hope someone can prove me wrong 😓

@JoelSpeed
Copy link
Contributor Author

/close

The transitive restrictions thing is for incoming imports, I'm not sure entirely what the use case is for that but it isn't going to help us here.

I think we could potentially use the incoming import thing to mark up other packages and prevent them from being imported into the API packages. Eg, we could prevent the util package being imported by putting a restriction on the util package

@k8s-ci-robot
Copy link
Contributor

@JoelSpeed: Closed this PR.

In response to this:

/close

The transitive restrictions thing is for incoming imports, I'm not sure entirely what the use case is for that but it isn't going to help us here.

I think we could potentially use the incoming import thing to mark up other packages and prevent them from being imported into the API packages. Eg, we could prevent the util package being imported by putting a restriction on the util package

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.

@sbueringer
Copy link
Member

Sorry might have missed it. Not sure if you were able to make it fail now.

Once we used unset we were able to make it fail (in Prow and locally on macOS with M2 inside of the "regular" GOPATH location)

kubernetes-sigs/cluster-api-provider-vsphere#2344 (comment)

https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_cluster-api-provider-vsphere/2344/pull-cluster-api-provider-vsphere-verify-main/1701512930987610112

Enforcing imports in source codes under the following directories: ./apis/v1alpha3,./apis/v1alpha4,./apis/v1beta1,./apis/vmware/v1beta1
E0912 08:35:45.985727   16631 main.go:41] Error: Failed executing generator: some packages had errors:
errors in package "./apis/v1beta1":
import sigs.k8s.io/controller-runtime/pkg/scheme has forbidden prefix sigs.k8s.io/controller-runtime
the following imports did not match any allowed prefix:
  sigs.k8s.io/controller-runtime/pkg/scheme
  sigs.k8s.io/controller-runtime/pkg/scheme
make: *** [Makefile:417: verify-import-restrictions] Error 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ci Issues or PRs related to ci cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. 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

5 participants