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

cmd/go: incompatible module version not detected by 'go run' or 'go build' #34330

Open
carnott-snap opened this issue Sep 16, 2019 · 9 comments
Open
Assignees
Milestone

Comments

@carnott-snap
Copy link

@carnott-snap carnott-snap commented Sep 16, 2019

What version of Go are you using (go version)?

[user@localhost ~]$ go version
go version go1.13 linux/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
[user@localhost ~]$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/user/.cache/go-build"
GOENV="/home/user/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY="*.sc-corp.net"
GONOSUMDB="*.sc-corp.net"
GOOS="linux"
GOPATH="/home/user/go"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/user/.local/share/umake/go/go-lang"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/user/.local/share/umake/go/go-lang/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/tmp/test/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build698062687=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Create the following go.mod file:

module test
  
go 1.13

require k8s.io/client-go v12.0.0+incompatible

Create the following main.go file:

package main
  
import (
        "fmt"

        "k8s.io/client-go/pkg/version"
)

func main() { fmt.Println(version.Get()) }

What did you expect to see?

The toolchain should fail all interactions with k8s.io/client-go because of the combination of the go.mod file at the v12.0.0 tag:

[user@localhost test]$ go get k8s.io/client-go@v12.0.0
go: finding k8s.io v12.0.0
go: finding k8s.io/client-go v12.0.0
go: finding k8s.io/client-go v12.0.0
go get k8s.io/client-go@v12.0.0: k8s.io/client-go@v12.0.0: invalid version: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v12
[user@localhost test]$ go run .
go: finding k8s.io/client-go v12.0.0+incompatible
go: finding k8s.io/client-go v12.0.0+incompatible
go list -m: k8s.io/client-go@v12.0.0+incompatible: invalid version: +incompatible suffix not allowed: module contains a go.mod file, so semantic import versioning is required
[user@localhost test]$ go build
go: finding k8s.io/client-go v12.0.0+incompatible
go: finding k8s.io/client-go v12.0.0+incompatible
go list -m: k8s.io/client-go@v12.0.0+incompatible: invalid version: +incompatible suffix not allowed: module contains a go.mod file, so semantic import versioning is required
[user@localhost test]$ go doc k8s.io/client-go/pkg/version
go: finding k8s.io/client-go v12.0.0+incompatible
go: finding k8s.io/client-go v12.0.0+incompatible
go list -m: k8s.io/client-go@v12.0.0+incompatible: invalid version: +incompatible suffix not allowed: module contains a go.mod file, so semantic import versioning is required

What did you see instead?

All parts of the toolchain I tested appear to re-find the problematic module on every invocation, however go get fails (as above), go doc warns, and both go run and go build succeed:

[user@localhost test]$ go run .
go: finding k8s.io/client-go v12.0.0+incompatible
go: finding k8s.io/client-go v12.0.0+incompatible
v0.0.0-master+$Format:%h$
[user@localhost test]$ go build
go: finding k8s.io/client-go v12.0.0+incompatible
go: finding k8s.io/client-go v12.0.0+incompatible
[user@localhost test]$ ./test 
v0.0.0-master+$Format:%h$
[user@localhost test]$ go doc k8s.io/client-go/pkg/version
go: finding k8s.io/client-go v12.0.0+incompatible
go: finding k8s.io/client-go v12.0.0+incompatible
go list -m: k8s.io/client-go@v12.0.0+incompatible: invalid version: +incompatible suffix not allowed: module contains a go.mod file, so semantic import versioning is required
package version // import "k8s.io/client-go/pkg/version"

Package version supplies version information collected at build time to
kubernetes components.

func Get() apimachineryversion.Info
@carnott-snap carnott-snap changed the title cmd/go: incompatible v2+ module versions allowed in go.mod cmd/go: module version validation does not apply to go.mod Sep 16, 2019
@toothrot
Copy link
Contributor

@toothrot toothrot commented Sep 17, 2019

I am not sure if this is a bug in build or doc. /cc @bcmills @jayconrod who know more about the nuances here.

Loading

@toothrot toothrot added this to the Go1.14 milestone Sep 17, 2019
@bcmills
Copy link
Member

@bcmills bcmills commented Sep 17, 2019

Thanks for the report. I can reproduce the described behavior starting from a clean module cache, and this is indeed a bug in go run / go build.

Loading

@bcmills bcmills changed the title cmd/go: module version validation does not apply to go.mod cmd/go: incompatible module version not detected by 'go run' or 'go build' Sep 17, 2019
@rsc rsc removed this from the Go1.14 milestone Oct 9, 2019
@rsc rsc added this to the Backlog milestone Oct 9, 2019
@seguidor777

This comment was marked as off-topic.

@seguidor777

This comment was marked as off-topic.

@bcmills

This comment was marked as off-topic.

@carnott-snap
Copy link
Author

@carnott-snap carnott-snap commented Mar 11, 2021

With the recent changes in 1.16 the failure is not reproducable through the suggestions and default flow:

[user@localhost trash]$ go run .
go: k8s.io/client-go@v12.0.0+incompatible: missing go.sum entry; to add it:
        go mod download k8s.io/client-go
[user@localhost trash]$ go mod download k8s.io/client-go
go mod download: k8s.io/client-go@v12.0.0+incompatible: invalid version: +incompatible suffix not allowed: module contains a go.mod file, so semantic import versioning is required

But the go get is only a warning, so (starting from a clean state) it still reproduces:

[user@localhost trash]$ go mod download
go mod download: k8s.io/client-go@v12.0.0+incompatible: invalid version: +incompatible suffix not allowed: module contains a go.mod file, so semantic import versioning is required
[user@localhost trash]$ go get k8s.io/client-go@v12.0.0
go get: k8s.io/client-go@v12.0.0: invalid version: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v12
[user@localhost trash]$ go run .
main.go:6:2: missing go.sum entry for module providing package k8s.io/client-go/pkg/version (imported by test); to add:
        go get test
[user@localhost trash]$ go get test
go: downloading k8s.io/client-go v12.0.0+incompatible
go: downloading k8s.io/apimachinery v0.0.0-20190612205821-1799e75a0719
go: warning: k8s.io/client-go@v12.0.0+incompatible: retracted by module author: pre-module versions are obsolete
go: to switch to the latest unretracted version, run:
        go get k8s.io/client-go@latest
[user@localhost trash]$ go run .
v0.0.0-master+$Format:%h$

Loading

@bcmills
Copy link
Member

@bcmills bcmills commented Mar 11, 2021

Thanks for the updated steps to reproduce. I'll see if I can get to this for 1.17 once the lazy-loading changes are done.

Loading

@bcmills bcmills removed this from the Backlog milestone Mar 11, 2021
@bcmills bcmills added this to the Go1.17 milestone Mar 11, 2021
@bcmills bcmills self-assigned this Mar 11, 2021
@bcmills bcmills removed this from the Go1.17 milestone Apr 28, 2021
@bcmills bcmills added this to the Go1.18 milestone Apr 28, 2021
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Nov 10, 2021

@bcmills Is this likely to happen for 1.18? Thanks.

Loading

@bcmills
Copy link
Member

@bcmills bcmills commented Nov 10, 2021

Sadly no.

(Changes to version validation tend to catch existing broken modules, so they shouldn't happen during the freeze.)

Loading

@bcmills bcmills removed this from the Go1.18 milestone Nov 10, 2021
@bcmills bcmills added this to the Go1.19 milestone Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
7 participants