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

make lint return error with Go version 1.16.3 #11312

Closed
daehyeok opened this issue May 6, 2021 · 10 comments
Closed

make lint return error with Go version 1.16.3 #11312

daehyeok opened this issue May 6, 2021 · 10 comments
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. priority/awaiting-more-evidence Lowest priority. Possibly useful, but not yet enough support to actually get it done.

Comments

@daehyeok
Copy link
Contributor

daehyeok commented May 6, 2021

Steps to reproduce the issue:

  1. After update Go to 1.16.3 make lint always return Error.
❯ env | rg ^GO
GOPATH=/Users/daehyeok/workspace/minikube/_gopath
GOROOT=/Users/daehyeok/.asdf/installs/golang/1.16.3/go
❯ go version
go version go1.16.3 darwin/amd64
❯ make lint
./out/linters/golangci-lint-v1.39.0 run --timeout 7m --build-tags "integration " --enable gofmt,goimports,gocritic,golint,gocyclo,misspell,nakedret,stylecheck,unconvert,unparam,dogsled --exclude 'variable on range scope.*in function literal|ifElseChain' --skip-files "pkg/minikube/translate/translations.go|pkg/minikube/assets/assets.go" ./...
pkg/drivers/kic/oci/oci.go:115:46: SA4023: this comparison is never true (staticcheck)
                if cgroup2, err := IsCgroup2UnifiedMode(); err == nil && cgroup2 {
                                                           ^
pkg/drivers/kic/oci/cgroups_other.go:28:6: SA4023(related information): k8s.io/minikube/pkg/drivers/kic/oci.IsCgroup2UnifiedMode never returns a nil interface value (staticcheck)
func IsCgroup2UnifiedMode() (bool, error) {
     ^
pkg/drivers/kic/oci/oci.go:130:46: SA4023: this comparison is never true (staticcheck)
                if cgroup2, err := IsCgroup2UnifiedMode(); err == nil && cgroup2 {

rule SA4023 looks added on latest version. If i use 1.16.2 make lint don't blame about SA4023

❯ env | rg ^GO
GOPATH=/Users/daehyeok/workspace/minikube/_gopath
GOROOT=/Users/daehyeok/.asdf/installs/golang/1.16.2/go
❯ go version
go version go1.16.2 darwin/amd64
❯ make lint
./out/linters/golangci-lint-v1.39.0 run --timeout 7m --build-tags "integration " --enable gofmt,goimports,gocritic,golint,gocyclo,misspell,nakedret,stylecheck,unconvert,unparam,dogsled --exclude 'variable on range scope.*in function literal|ifElseChain' --skip-files "pkg/minikube/translate/translations.go|pkg/minikube/assets/assets.go" ./...
@afbjorklund
Copy link
Collaborator

afbjorklund commented May 6, 2021

minikube currently uses 1.16.1

GO_VERSION ?= 1.16.1

But we should update to 1.16.3

https://github.com/kubernetes/kubernetes/blob/master/build/build-image/cross/VERSION

@afbjorklund
Copy link
Collaborator

afbjorklund commented May 6, 2021

The issue itself should be simple. Care to submit a PR ?

// IsCgroup2UnifiedMode returns whether we are running in cgroup 2 cgroup2 mode.
func IsCgroup2UnifiedMode() (bool, error) {
        return false, errors.Errorf("Not supported on %s", runtime.GOOS)
}

Possibly this should add a bogus if runtime.GOOS != "linux"

We already have that when using it, and in the tag, but the linter seems to be stupid.

@afbjorklund afbjorklund added kind/bug Categorizes issue or PR as related to a bug. priority/awaiting-more-evidence Lowest priority. Possibly useful, but not yet enough support to actually get it done. labels May 6, 2021
@daehyeok
Copy link
Contributor Author

daehyeok commented May 6, 2021

/assign

sure i will

@daehyeok
Copy link
Contributor Author

daehyeok commented May 6, 2021

yeah it looks linter issue. 1.16.4 release few hours ago. and this problem gone again.

❯ env | rg ^GO
GOPATH=/Users/daehyeok/workspace/minikube/_gopath
GOROOT=/Users/daehyeok/.asdf/installs/golang/1.16.4/go
❯ go version
go version go1.16.4 darwin/amd64
❯ make lint
./out/linters/golangci-lint-v1.39.0 run --timeout 7m --build-tags "integration " --enable gofmt,goimports,gocritic,golint,gocyclo,misspell,nakedret,stylecheck,unconvert,unparam,dogsled --exclude 'variable on range scope.*in function literal|ifElseChain' --skip-files "pkg/minikube/translate/translations.go|pkg/minikube/assets/assets.go" ./...

@afbjorklund
Copy link
Collaborator

afbjorklund commented May 6, 2021

Something like

// +build !linux

// IsCgroup2UnifiedMode returns whether we are running in cgroup 2 cgroup2 mode.
func IsCgroup2UnifiedMode() (bool, error) {
    if runtime.GOOS != "linux" {
        return false, errors.Errorf("Not supported on %s", runtime.GOOS)
    } else {
        panic()
    }
}

Or whatever it takes to make that confused "staticcheck" happy

@dominikh
Copy link

dominikh commented May 9, 2021

rule SA4023 looks added on latest version. If i use 1.16.2 make lint don't blame about SA4023

Staticcheck is not part of Go. Upgrading from Go 1.16.2 to 1.16.4 does not introduce new checks to Staticcheck. Upgrading Go may change the behavior of checks, however, especially ones that analyze the behavior of the standard library (which would apply to SA4023).

but the linter seems to be stupid

I'd love to make it "less stupid", but I can't do so if people don't report bugs upstream. I found this issue by chance.

I have tried to reproduce the issue, but no combination of GOOS, Go version and Staticcheck version (either standalone or in golangci-lint) could reproduce this issue, and from looking at your code, I don't see why the warning would be emitted, either.

You can read the check's documentation for what it actually aims to flag. It doesn't merely fire because a function never returns an untyped nil, but only if it also returns typed nils. Neither IsCgroup2UnifiedMode nor errors.Errorf do this, so I don't know what's up.

@afbjorklund
Copy link
Collaborator

afbjorklund commented May 9, 2021

I'd love to make it "less stupid", but I can't do so if people don't report bugs upstream. I found this issue by chance.

We know that linters are stupid, that's why they are non-blocking. As supposed to other tools, which are enforced.

That is not a major problem per se, sometimes we have to flag/workaround a false positive but that's OK too...

Thanks for taking the time to comment here!

If we can find the issue, will report upstream.

@daehyeok
Copy link
Contributor Author

daehyeok commented May 9, 2021

I'd love to make it "less stupid", but I can't do so if people don't report bugs upstream. I found this issue by chance.

I didn't report yet, because i couldn't narrow down which component fire the this warning. after little more investigation with my problematic env, i will make issue for it.

P.S thank for the comment and appreciate for the emacs go-mode 👍

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Aug 7, 2021
@afbjorklund
Copy link
Collaborator

Should be OK now, and minikube is up to go version 1.16.6 (same as Kubernetes 1.22)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. priority/awaiting-more-evidence Lowest priority. Possibly useful, but not yet enough support to actually get it done.
Projects
None yet
Development

No branches or pull requests

5 participants