-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
controller-runtime v0.16.0 fails starting the manager when the operator is using cache.Options with kinds identified ByObject that are not present on the specific cluster.
This could happen for instance trying to finetune upfront the cache also for monitoring kinds when the prometheous stack is not deployed or OKD/OCP specific kinds when on vanilla k8s.
Now the operator dies with something like:
failed to determine if *v1.ConsoleQuickStart is namespaced: failed to get restmapping: failed to find API group "console.openshift.io"","stacktrace":"github.com/kubevirt/hyperconverged-cluster-operator/cmd/cmdcommon.HcCmdHelper.ExitOnError
/go/src/github.com/kubevirt/hyperconverged-cluster-operator/cmd/cmdcommon/cmdcommon.go:97
main.main
/go/src/github.com/kubevirt/hyperconverged-cluster-operator/cmd/hyperconverged-cluster-operator/main.go:104
runtime.main
/usr/local/go/src/runtime/proc.go:250
the same code was working with controller-runtime <= v0.15.0.
This is probably got probably changed with: #2421
The error comes from
controller-runtime/pkg/cache/cache.go
Lines 399 to 405 in c20ea14
| isNamespaced, err := apiutil.IsObjectNamespaced(obj, opts.Scheme, opts.Mapper) | |
| if err != nil { | |
| return opts, fmt.Errorf("failed to determine if %T is namespaced: %w", obj, err) | |
| } | |
| if !isNamespaced && byObject.Namespaces != nil { | |
| return opts, fmt.Errorf("type %T is not namespaced, but its ByObject.Namespaces setting is not nil", obj) | |
| } |
that is supposed to use
isNamespaced during cache initialization to ensure that byObject.Namespaces is not set for cluster-scope kind.
A simple fix is just about skipping that additional check for non existing kinds instead of breaking the cache initialization and so the manager one.