go-lgr compiler error despite source code not having changed

I have a Go application that has been working consistently for months, but it has suddenly started showing compilation errors. I haven’t made any changes to the project. It compiled without errors as recently as last Friday (28th May) but started showing errors on Tuesday 1st June).

The errors are as follows:

k8s.io/klog/klog.go:705:10: invalid operation: logr != nil (mismatched types logr.Logger and nil);

k8s.io/klog/klog.go:919:4: undefined: logr.WithCallDepth

My source code hasn’t changed, so I can only assume that one of the dependencies has changed. I see a new tag marked “BREAKING CHANGE” was released for this project (https://github.com/go-logr/logr/releases/tag/v1.0.0-rc1) at the time this occurred but can’t work out how it is related because the dependencies in my project explicitly rely on v0.1.0 and v0.2.0 of logr.

My go.mod file specifies this:

k8s.io/apimachinery v0.21.1,

which has given rise in the go.sum file to the following dependencies (among others):

github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
github.com/go-logr/logr v0.2.0 h1:QvGt2nLcHH0WK9orKa+ppBPAxREcH364nPUedEpK0TY=
github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8=
k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
k8s.io/klog/v2 v2.4.0 h1:7+X0fUguPyrKEC4WjH8iGDg3laWgMo5tMnRTIGTTxGQ=
k8s.io/klog/v2 v2.4.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y=
k8s.io/apimachinery v0.20.0 h1:jjzbTJRXk0unNS71L7h3lxGDH/2HPxMPaQY+MjECKL8=
k8s.io/apimachinery v0.20.0/go.mod h1:WlLqWAHZGg07AeltaI0MV5uk1Omp8xaN0JGLY6gkRpU=
k8s.io/apimachinery v0.20.2 h1:hFx6Sbt1oG0n6DZ+g4bFt5f6BoMkOjKWsQFu077M3Vg=
k8s.io/apimachinery v0.20.2/go.mod h1:WlLqWAHZGg07AeltaI0MV5uk1Omp8xaN0JGLY6gkRpU=

I’d appreciate any insight into the cause of the issue and how to fix it.

Hi !

Having same compilation error here.
Last success 28th May too

Try to rollback some versions without success.

@alan Do you have any clue to resolve this ?

This is my compil log

# k8s.io/klog
../k8s.io/klog/klog.go:705:10: invalid operation: logr != nil (mismatched types logr.Logger and nil)
../k8s.io/klog/klog.go:724:10: invalid operation: logr != nil (mismatched types logr.Logger and nil)
../k8s.io/klog/klog.go:742:10: invalid operation: logr != nil (mismatched types logr.Logger and nil)
../k8s.io/klog/klog.go:763:10: invalid operation: logr != nil (mismatched types logr.Logger and nil)
../k8s.io/klog/klog.go:782:11: invalid operation: loggr != nil (mismatched types logr.Logger and nil)
../k8s.io/klog/klog.go:783:3: undefined: logr.WithCallDepth
../k8s.io/klog/klog.go:794:11: invalid operation: loggr != nil (mismatched types logr.Logger and nil)
../k8s.io/klog/klog.go:795:3: undefined: logr.WithCallDepth
../k8s.io/klog/klog.go:915:9: invalid operation: log != nil (mismatched types logr.Logger and nil)
../k8s.io/klog/klog.go:919:4: undefined: logr.WithCallDepth
../k8s.io/klog/klog.go:919:4: too many errors

Hi Thomas

I didn’t resolve the issue but I found a workaround, which was to clone the repo and then build it with ‘go build’. This built without errors.

Thanks

Alan