Skip to content

Ambiguous imports with cloud.google.com/go/compute/metadata #304

@nikhita

Description

@nikhita

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

On merging kubernetes/kubernetes#114822, the publishing-bot failed on running go mod tidy - kubernetes/kubernetes#56876 (comment):

+ go mod tidy
    	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 (/go-workspace/pkg/mod/cloud.google.com/[email protected]/compute/metadata)
    		cloud.google.com/go/compute/metadata v0.2.0 (/go-workspace/pkg/mod/cloud.google.com/go/compute/[email protected])

googleapis/google-cloud-go#6311 made compute/metadata its own module. This commit exists also exists on:

  • v0.105.0 of the root module (cloud.google.com/go)
  • v1.12.0 of cloud.google.com/go/compute

If a repo already depends on a version of cloud.google.com/go < v0.105.0 and tries to import cloud.google.com/go/compute/metadata, it'll hit the problem of ambiguous imports while running go mod tidy - golang/go#27899 (another example - ugorji/go#279).

Note: apiserver requires v0.97.0 of the root module - https://github.com/kubernetes/kubernetes/blob/293bf70916de8ef61d5f868f53959f1e15b3e091/staging/src/k8s.io/apiserver/go.mod#L60

To resolve this, we either need to:

  1. pin cloud.google.com/go to a version which includes the cloud.google.com/go/compute/metadata module i.e. > v0.105.0
  2. Run an explicit go get cloud.google.com/[email protected] before running go mod tidy.

For (1), it brings in additional changes that we might not want right now (like bumping genproto). So we go ahead with (2) until we are ready to bump cloud.google.com/go or remove the dependency on it.

/assign

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions