go: cmd/go: cannot Resolve K8s Package from Dependency
What version of Go are you using (go version
)?
go version go1.11 windows/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env
)?
Windows 10 Enterprise x64 Reproduced with go1.11 on Windows Subsystem for Linux (Ubuntu) as well.
What did you do?
Tried to run go test/go build with code that uses methods from the prometheus monitoring project.
Reproduce with:
package main
import (
"github.com/prometheus/prometheus/config"
)
func main() {}
var c config.Config
Ultimately related to issues I’ve opened before #26843 and dep issue 1976.
At this point I’m a bit perplexed as to how to deal with this.
What did you expect to see?
The standard behavior of a test or build.
What did you see instead?
$ go mod verify
all modules verified
$ go build main.go
go: finding github.com/Azure/azure-sdk-for-go/arm/compute latest
go: finding github.com/Azure/azure-sdk-for-go/arm/network latest
go: finding github.com/Azure/azure-sdk-for-go/arm latest
go: finding k8s.io/client-go/pkg/api latest
go: finding k8s.io/client-go/pkg/apis/extensions/v1beta1 latest
go: finding k8s.io/client-go/pkg latest
go: finding k8s.io/client-go/pkg/apis/extensions latest
go: finding k8s.io/client-go/pkg/apis latest
build promtest: cannot find module for path github.com/Azure/azure-sdk-for-go/arm/compute
Fix azure-sdk-for-go issue by adding to go.mod: require github.com/Azure/azure-sdk-for-go v5.0.0-beta.0.20161028183111-bd73d950fa44+incompatible // indirect
$ go build main.go
go: finding github.com/Azure/azure-sdk-for-go v5.0.0-beta.0.20161028183111-bd73d950fa44+incompatible
go: finding k8s.io/client-go/pkg/apis/extensions/v1beta1 latest
go: finding k8s.io/client-go/pkg/api latest
go: finding k8s.io/client-go/pkg/apis/extensions latest
go: finding k8s.io/client-go/pkg latest
go: finding k8s.io/client-go/pkg/apis latest
../../go/pkg/mod/github.com/prometheus/prometheus@v2.3.2+incompatible/discovery/kubernetes/kubernetes.go:34:2: unknown import path
"k8s.io/client-go/pkg/api": cannot find module providing package k8s.io/client-go/pkg/api
../../go/pkg/mod/github.com/prometheus/prometheus@v2.3.2+incompatible/discovery/kubernetes/endpoints.go:26:2: unknown import path
"k8s.io/client-go/pkg/api/v1": cannot find module providing package k8s.io/client-go/pkg/api/v1
../../go/pkg/mod/github.com/prometheus/prometheus@v2.3.2+incompatible/discovery/kubernetes/ingress.go:25:2: unknown import path "k
8s.io/client-go/pkg/apis/extensions/v1beta1": cannot find module providing package k8s.io/client-go/pkg/apis/extensions/v1beta1
Oddly enough, k8s.io/client-go/pkg/api does not exist in the prometheus vendor directory and I cannot find it remapped in their vendor.json. Could k8s.io/client-go/pkg/api be using k8s.io/api?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 16 (14 by maintainers)
@swtch1 this situation comes about because of breaking changes in the
github.com/Azure/azure-sdk-for-go
packages. Because the import path of thegithub.com/Azure/azure-sdk-for-go/...
packages did not change after the breaking change, it’s impossible to work out which version is “correct”. Hence the power of semantic import versioning.There is a way to “fix” your case however, and that is to bootstrap your dependencies from the
github.com/prometheus/prometheus
module:succeeds.
cc @rsc @bcmills. Perhaps when resolving
github.com/prometheus/prometheus
, we see that it’s a non-module dependency, we also see that it could be converted from its existing dependency management configuration (govendor
), should we use the dependencies implied by the result ofgo mod init
?EDIT: to merge the two
go mod edit
lines.Having a similar issue as described here: https://groups.google.com/forum/#!topic/golang-nuts/BYV0IH_809Q. Thanks @myitcv for pointing me to this issue.
The “fix” seems to be some of what @bcmills described. ApiMachinery wasn’t the version I wanted even after a
go get
. I had to set this manually withgo mod edit -replace
. This kind of thing doesn’t really make me feel too confident about the system as even after I fixed that one package, it exposed others that I now have to also fix manually… 😕Ok, there is one outstanding bug here, but the rest seems to work fine without any
replace
directives.The bug is that, for some reason,
go get github.com/Azure/azure-sdk-for-go@v5.0.0-beta
addsv20.1.0+incompatible
instead of the requested version.If I fix that with a
go mod edit
, it seems to remain stable. I end up needing to fix up two other versions to point to non-semver revisions (one fork8s.io/apimachinery
, which uses a different versioning scheme for its tags, and one forgithub.com/hashicorp/serf
, which some other (tagged)hashicorp
package requires at a version newer than the latest tag), but beyond that everything builds.Using the source file from the original report:
@myitcv your script modifications worked for me. I really can’t thank you enough… I haven’t been able to build this project since I added those deps. This is seriously huge, thank you! Also not something I think I would have figured out on my own as I played with the replacements and other methods for hours.