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

go get explicit versions to avoid ambiguous imports #305

Merged
merged 1 commit into from
Jan 5, 2023

Conversation

nikhita
Copy link
Member

@nikhita nikhita commented Jan 5, 2023

Fixes #304

Ref: kubernetes/kubernetes#113366, kubernetes/kubernetes#114829

I haven't had the chance to do a test run of the bot to verify this but can reproduce this locally using:

  1. Clone the https://github.com/kubernetes/kube-aggregator repo (the publishing-bot fails while publishing this repo).
  2. Run go mod edit -require=golang.org/x/[email protected]. It's not an exact representation of what the bot does since it doesn't update k8s deps but it's enough to reproduce the error.
  3. Run go mod tidy. We'll see a failure:
k8s.io/kube-aggregator/pkg/cmd/server imports
	k8s.io/apiserver/pkg/server/options imports
	k8s.io/apiserver/pkg/storage/storagebackend/factory imports
	go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc tested by
	go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc.test imports
	google.golang.org/grpc/interop imports
	golang.org/x/oauth2/google imports
	cloud.google.com/go/compute/metadata: ambiguous import: found package cloud.google.com/go/compute/metadata in multiple modules:
	cloud.google.com/go v0.97.0 (/Users/nraghunath/go/pkg/mod/cloud.google.com/[email protected]/compute/metadata)
	cloud.google.com/go/compute/metadata v0.2.0 (/Users/nraghunath/go/pkg/mod/cloud.google.com/go/compute/[email protected])
  1. Run go get cloud.google.com/[email protected] and then run go mod tidy again. It passes without an error.

Notes:

  1. Even after this change is merged, if someone clones the repo they'll always be a need to run a go get cloud.google.com/[email protected] for go mod tidy to succeed (due to cmd/go: ensure that 'go mod tidy' and go get -u do not introduce ambiguous imports golang/go#27899).
  2. Running a go get cloud.google.com/go/compute/[email protected] will also technically allow go mod tidy for kube-aggregator but it'll fail for apiserver becaue it has an explict require directive for cloud.google.com/[email protected].

This will be necessary until we bump cloud.google.com/go or remove dependency on it as mentioned in #304.

/hold
for review

/cc @dims @liggitt

@k8s-ci-robot k8s-ci-robot requested review from dims and liggitt January 5, 2023 06:43
@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. 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/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jan 5, 2023
@nikhita nikhita force-pushed the handle-ambiguous-import branch from 9475fb8 to 2907ef3 Compare January 5, 2023 07:26
@nikhita
Copy link
Member Author

nikhita commented Jan 5, 2023

cc @skitt -- since you created googleapis/google-cloud-go#7209

@nikhita nikhita force-pushed the handle-ambiguous-import branch from 2907ef3 to b2e6451 Compare January 5, 2023 08:10
@nikhita nikhita force-pushed the handle-ambiguous-import branch from b2e6451 to a329b53 Compare January 5, 2023 10:39
@nikhita
Copy link
Member Author

nikhita commented Jan 5, 2023

I haven't had the chance to do a test run of the bot to verify this

Verified for just publishing the master branch for kube-aggregator and it worked 👍

@dims
Copy link
Member

dims commented Jan 5, 2023

/approve
/lgtm

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dims, nikhita

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 lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 5, 2023
@nikhita
Copy link
Member Author

nikhita commented Jan 5, 2023

/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 5, 2023
@k8s-ci-robot k8s-ci-robot merged commit a5cb9e8 into kubernetes:master Jan 5, 2023
# ref: https://github.com/kubernetes/publishing-bot/issues/304
# TODO(nikhita): remove this when k/k drops or bumps
# cloud.google.com/go to a version > v0.105.0
go get cloud.google.com/[email protected]
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I'm not sure we should do this… doesn't this change the versions the module is requiring?

Copy link
Member Author

Choose a reason for hiding this comment

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

doesn't this change the versions the module is requiring

Yes, but it ends up being a no-op for repos (e.g kube-aggregator) that don't need to require cloud.google.com/go because go mod tidy will remove it from go.mod.

For repos that already require it (e.g. apiserver), they are already at v0.97.0 so it ends up being a no-op again.

Copy link
Member

Choose a reason for hiding this comment

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

This still seems like something that shouldn't happen at this level, and will get stale or force the wrong version eventually on some branch

Copy link
Member

@skitt skitt Jan 5, 2023

Choose a reason for hiding this comment

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

At least it could check that the current go.mod pulls in cloud.google.com/go, in a version older than v0.105.0 (if any); something like

if [ "$((go list -m -json cloud.google.com/go | jq -r '.Version'; echo v0.105.0) | sort -V | head -n 1)" != v0.105.0 ]; then

Or just re-get the currently-required version:

if [ -n "$(go list -m cloud.google.com/go)" ]; then go get "cloud.google.com/go@$(go list -m -json cloud.google.com/go | jq -r '.Version')"; fi

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/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ambiguous imports with cloud.google.com/go/compute/metadata
5 participants