Symptom:
We hit below error when we build an operator via kubebuilder 3.1 + controller runtime v0.8.3 + kuberentes 1.20.2
./../../pkg/mod/sigs.k8s.io/controller-runtime@v0.8.3/pkg/metrics/client_go_adapter.go:134:3: cannot use &latencyAdapter{...} (type *latencyAdapter) as type metrics.LatencyMetric in field value:
*latencyAdapter does not implement metrics.LatencyMetric (wrong type for Observe method)
have Observe(string, url.URL, time.Duration)
want Observe(context.Context, string, url.URL, time.Duration)
../../../pkg/mod/sigs.k8s.io/controller-runtime@v0.8.3/pkg/metrics/client_go_adapter.go:135:3: cannot use &resultAdapter{...} (type *resultAdapter) as type metrics.ResultMetric in field value:
*resultAdapter does not implement metrics.ResultMetric (wrong type for Increment method)
have Increment(string, string, string)
want Increment(context.Context, string, string, string)
Solution:
It is related to controller runtime v0.8.3 has compatible issues with Kubernetes 0.21 modules. See
linkTo fix it, find go.mod, change the module from 0.21 to 0.20.2