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 · 11 comments
Open
Labels
BadErrorMessage Issues related compiler error messages that should be better. early-in-cycle A change that should be done early in the 3 month dev cycle. GoCommand cmd/go help wanted modules NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@carnott-snap
Copy link

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

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
@toothrot toothrot added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 17, 2019
@bcmills
Copy link
Contributor

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.

@bcmills bcmills added modules NeedsFix The path to resolution is known, but the work has not been done. labels Sep 17, 2019
@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 17, 2019
@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
@seguidor777

This comment has been minimized.

@seguidor777

This comment has been minimized.

@bcmills

This comment has been minimized.

@carnott-snap
Copy link
Author

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$

@bcmills
Copy link
Contributor

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.

@bcmills bcmills modified the milestones: Backlog, Go1.17 Mar 11, 2021
@bcmills bcmills self-assigned this Mar 11, 2021
@bcmills bcmills modified the milestones: Go1.17, Go1.18 Apr 28, 2021
@ianlancetaylor
Copy link
Contributor

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

@bcmills
Copy link
Contributor

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.)

@bcmills bcmills modified the milestones: Go1.20, Go1.21 Dec 12, 2022
@bcmills bcmills added the early-in-cycle A change that should be done early in the 3 month dev cycle. label Dec 12, 2022
@gopherbot
Copy link
Contributor

This issue is currently labeled as early-in-cycle for Go 1.21.
That time is now, so a friendly reminder to look at it again.

@bcmills bcmills modified the milestones: Go1.21, Go1.22 Jun 20, 2023
@gopherbot
Copy link
Contributor

This issue is currently labeled as early-in-cycle for Go 1.22.
That time is now, so a friendly reminder to look at it again.

@bcmills bcmills modified the milestones: Go1.22, Backlog Feb 1, 2024
@bcmills bcmills removed their assignment Mar 14, 2024
@bcmills bcmills added BadErrorMessage Issues related compiler error messages that should be better. GoCommand cmd/go help wanted labels Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BadErrorMessage Issues related compiler error messages that should be better. early-in-cycle A change that should be done early in the 3 month dev cycle. GoCommand cmd/go help wanted modules NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

7 participants