go1.18を使ったときに、golangci-lintのtypecheckのエラーが出たり、go generateがこけた
//
golangci-lintのtypecheckのエラー
go.mod
で、go1.16
が指定されているプロジェクトで、手元のgoのバージョンを1.18.2
にしてgolangci-lint
を実行したときに、今まで出ていなかったエラーが発生しました。こんな感じ
...net/http/httptest (-: could not load export data: no export data for "net/http/httptest") (typecheck) "net/http/httptest" ^ k8sapiserver/k8sapiserver.go:23:13: could not import...load export data: no export data for "k8s.io/kubernetes/pkg/kubeapiserver/authorizer/modes") (typecheck) authzmodes "k8s.io/kubernetes/pkg/kubeapiserver/authorizer/modes" ^... ...
go1.16.15
やgo.17.10
では、上記のエラーは発生していませんでした。
対処
golangci-lint
のバージョンを最新に上げました。(ちょうど別件でgo.mod
に記載のバージョンも上げたので念のため記載しておきます。)
# go.mod - go 1.16 + go 1.17 - github.com/golangci/golangci-lint v1.41.1 + github.com/golangci/golangci-lint v1.46.2
上記の対応により、手元のgoバージョンgo1.18.2
で、先のエラーは発生しなくなりました。
go generateがこけた
上記の続きで、go1.18.2
を使ったときにgo generate
を実行したときに以下のエラーが発生しました。
go generate ./... prog.go:12:2: cannot find package "." in: /workspace/kube-scheduler-simulator/simulator/vendor/github.com/golang/mock/mockgen/model Please reference the steps in the README to fix this error: https://github.com/golang/mock#reflect-vendoring-error.prog.go:12:2: cannot find package "." in: /workspace/kube-scheduler-simulator/simulator/vendor/github.com/golang/mock/mockgen/model Please reference the steps in the README to fix this error: https://github.com/golang/mock#reflect-vendoring-error.prog.go:12:2: no required module provides package github.com/golang/mock/mockgen/model: go.mod file not found in current directory or any parent directory; see 'go help modules' prog.go:14:2: no required module provides package sigs.k8s.io/kube-scheduler-simulator/simulator/export: go.mod file not found in current directory or any parent directory; see 'go help modules' 2022/07/10 14:41:06 Loading input failed: exit status 1 export/export.go:3: running "mockgen": exit status 1 prog.go:12:2: cannot find package "." in: /workspace/kube-scheduler-simulator/simulator/vendor/github.com/golang/mock/mockgen/model Please reference the steps in the README to fix this error: https://github.com/golang/mock#reflect-vendoring-error.prog.go:12:2: cannot find package "." in: /workspace/kube-scheduler-simulator/simulator/vendor/github.com/golang/mock/mockgen/model Please reference the steps in the README to fix this error: https://github.com/golang/mock#reflect-vendoring-error.prog.go:12:2: no required module provides package github.com/golang/mock/mockgen/model: go.mod file not found in current directory or any parent directory; see 'go help modules' prog.go:14:2: no required module provides package sigs.k8s.io/kube-scheduler-simulator/simulator/node: go.mod file not found in current directory or any parent directory; see 'go help modules' 2022/07/10 14:41:07 Loading input failed: exit status 1 node/node.go:3: running "mockgen": exit status 1 prog.go:12:2: cannot find package "." in: /workspace/kube-scheduler-simulator/simulator/vendor/github.com/golang/mock/mockgen/model Please reference the steps in the README to fix this error: https://github.com/golang/mock#reflect-vendoring-error.prog.go:12:2: cannot find package "." in: /workspace/kube-scheduler-simulator/simulator/vendor/github.com/golang/mock/mockgen/model Please reference the steps in the README to fix this error: https://github.com/golang/mock#reflect-vendoring-error.prog.go:12:2: no required module provides package github.com/golang/mock/mockgen/model: go.mod file not found in current directory or any parent directory; see 'go help modules' prog.go:14:2: no required module provides package sigs.k8s.io/kube-scheduler-simulator/simulator/replicateexistingcluster: go.mod file not found in current directory or any parent directory; see 'go help modules' 2022/07/10 14:41:08 Loading input failed: exit status 1 replicateexistingcluster/replicateexistingcluster.go:3: running "mockgen": exit status 1 prog.go:12:2: cannot find package "." in: /workspace/kube-scheduler-simulator/simulator/vendor/github.com/golang/mock/mockgen/model Please reference the steps in the README to fix this error: https://github.com/golang/mock#reflect-vendoring-error.prog.go:12:2: cannot find package "." in: /workspace/kube-scheduler-simulator/simulator/vendor/github.com/golang/mock/mockgen/model Please reference the steps in the README to fix this error: https://github.com/golang/mock#reflect-vendoring-error.prog.go:12:2: no required module provides package github.com/golang/mock/mockgen/model: go.mod file not found in current directory or any parent directory; see 'go help modules' prog.go:14:2: no required module provides package sigs.k8s.io/kube-scheduler-simulator/simulator/scheduler/plugin: go.mod file not found in current directory or any parent directory; see 'go help modules' 2022/07/10 14:41:09 Loading input failed: exit status 1 scheduler/plugin/wrappedplugin.go:13: running "mockgen": exit status 1 make: *** [Makefile:3: generate] Error 1
go1.16.15
を使用していたときは発生していませんでしたが、こちらgo1.18.2
を使用し始めたときに発生するようになりました。
対処
ここにある2つのうちのどちらかで対処可能です。
例えば以下のように修正します。
- //go:generate mockgen -destination=./mock_$GOPACKAGE/pod.go . PodService + //go:generate mockgen --build_flags=--mod=mod -destination=./mock_$GOPACKAGE/pod.go . PodService