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 · 2 comments

Comments

@carnott-snap
Copy link

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

This comment has been minimized.

Copy link
Contributor

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.

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

This comment has been minimized.

Copy link
Member

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.

@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 modified the milestones: Go1.14, Backlog Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.