Client-go: Azure go-autorest causing ambiguous import

Created on 3 Jul 2019  路  4Comments  路  Source: kubernetes/client-go

Got an ambiguous import error when run go get ./... under a go module enabled project with client-go v12.0.0

build github.com/.../cmd/operator: cannot load github.com/Azure/go-autorest/autorest: ambiguous import: found github.com/Azure/go-autorest/autorest in multiple modules:
    github.com/Azure/go-autorest v11.1.2+incompatible (/.../github.com/!azure/[email protected]+incompatible/autorest)
    github.com/Azure/go-autorest/autorest v0.3.0 (/.../github.com/!azure/go-autorest/[email protected])

Looks like go-autorest, at least v11.1.2, is introduced by client-go

Here is the line in my go.mod file:

github.com/Azure/go-autorest/autorest v0.3.0 // indirect

but in the go.sum, there are many lines:

github.com/Azure/go-autorest v11.1.2+incompatible h1:viZ3tV5l4gE2Sw0xrasFHytCGtzYCrT+um/rrSQ1BfA=
github.com/Azure/go-autorest v11.1.2+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24=
github.com/Azure/go-autorest/autorest v0.3.0 h1:yOmXNB2qa2Kx40wMZB19YyafzjCHacXPk8u0neqa+M0=
github.com/Azure/go-autorest/autorest v0.3.0/go.mod h1:AKyIcETwSUFxIcs/Wnq/C+kwCtlEYGUVd7FPNb2slmg=
github.com/Azure/go-autorest/autorest/adal v0.1.0 h1:RSw/7EAullliqwkZvgIGDYZWQm1PGKXI8c4aY/87yuU=
github.com/Azure/go-autorest/autorest/adal v0.1.0/go.mod h1:MeS4XhScH55IST095THyTxElntu7WqB7pNbZo8Q5G3E=
github.com/Azure/go-autorest/autorest/date v0.1.0 h1:YGrhWfrgtFs84+h0o46rJrlmsZtyZRg470CqAXTZaGM=
github.com/Azure/go-autorest/autorest/date v0.1.0/go.mod h1:plvfp3oPSKwf2DNjlBjWF/7vwR+cUD/ELuzDCXwHUVA=
github.com/Azure/go-autorest/autorest/mocks v0.1.0 h1:Kx+AUU2Te+A3JIyYn6Dfs+cFgx5XorQKuIXrZGoq/SI=
github.com/Azure/go-autorest/autorest/mocks v0.1.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0=
github.com/Azure/go-autorest/logger v0.1.0 h1:ruG4BSDXONFRrZZJ2GUXDiUyVpayPmb1GnWeHDdaNKY=
github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6LSNgds39diKLz7Vrc=
github.com/Azure/go-autorest/tracing v0.1.0 h1:TRBxC5Pj/fIuh4Qob0ZpkggbfT8RC0SubHbpV3p4/Vc=
github.com/Azure/go-autorest/tracing v0.1.0/go.mod h1:ROEEAFwXycQw7Sn3DXNtEedEvdeRAgDr0izn4z5Ij88=

Most helpful comment

Looks like this is because how multi modules are configured in Azure/go-autorest. This is similar to https://github.com/ugorji/go/issues/279.

Also, similar errors have been reported for Azure/go-autorest in https://github.com/Azure/go-autorest/issues/414 and https://github.com/google/go-cloud/issues/1990.

This occurs because:

v11.1.2 -> doesn't have github.com/Azure/go-autorest/autorest{go.mod,go.sum} files.

autorest/v0.3.0 -> has github.com/Azure/go-autorest/autorest{go.mod,go.sum} files.

To fix this, you'll need to tell go to use a version of github.com/Azure/go-autorest that has github.com/Azure/go-autorest/autorest{go.mod,go.sum} files.

autorest/v0.3.0 and v12.2.0 point to the same commit, so adding the following line to your go.mod file should fix it.

require github.com/Azure/go-autorest v12.2.0+incompatible

All 4 comments

Looks like this is because how multi modules are configured in Azure/go-autorest. This is similar to https://github.com/ugorji/go/issues/279.

Also, similar errors have been reported for Azure/go-autorest in https://github.com/Azure/go-autorest/issues/414 and https://github.com/google/go-cloud/issues/1990.

This occurs because:

v11.1.2 -> doesn't have github.com/Azure/go-autorest/autorest{go.mod,go.sum} files.

autorest/v0.3.0 -> has github.com/Azure/go-autorest/autorest{go.mod,go.sum} files.

To fix this, you'll need to tell go to use a version of github.com/Azure/go-autorest that has github.com/Azure/go-autorest/autorest{go.mod,go.sum} files.

autorest/v0.3.0 and v12.2.0 point to the same commit, so adding the following line to your go.mod file should fix it.

require github.com/Azure/go-autorest v12.2.0+incompatible

fyi @sttts @liggitt @dims

Closing this issue since this is not a bug with client-go. This issue will only be hit if someone's using something in their go.mod that requires github.com/Azure/go-autorest/autorest v0.3.0.

Having said that, this issue should go away once https://github.com/kubernetes/kubernetes/pull/79574 has merged. :)

To anyone who is struggling with this issue, I managed to avoid this problem by removing the following two lines in go.mod.

github.com/Azure/go-autorest/autorest v0.9.2 // indirect
github.com/Azure/go-autorest/autorest/to v0.3.0 // indirect
go mod tidy
Was this page helpful?
0 / 5 - 0 ratings

Related issues

jharshman picture jharshman  路  4Comments

tamalsaha picture tamalsaha  路  3Comments

narasago picture narasago  路  3Comments

peterwillcn picture peterwillcn  路  5Comments

antoineco picture antoineco  路  6Comments