Closed gschlueter-jaconi closed 1 month ago
I also encountered the same issue. After some debugging, I found the root cause: the default label selector is applied to the CR watch because no label selector defined in per-namespace default configuration. When watching all namespaces, per-namespace config has labels.Everything()
label selector that takes precedence.
As a workaround, I added the label helm.sdk.operatorframework.io/chart: <chart name>
to the CR and it worked.
One caveat: I'm not a maintainer and I'm not sure if this won't cause unwanted side effects, so use at your own risk :)
As for the fix, the most correct option I can think of is to apply the configuration in options.Cache.DefaultNamespaces
to selectorsByObject
in cmd.go:
selectorsByObject[crObj] = cache.ByObject{Label: sel, Namespaces: ...}
After taking another look, it seems to me that it's a bug in controller-runtime. From ByObject documentation.
// The defaulting follows the following precedence order:
// 1. ByObject
// 2. DefaultNamespaces[namespace]
// 3. Default*
In the helm operator, the label selector is always set in ByObject
so it must always take precedence.
Found a related issue: https://github.com/kubernetes-sigs/controller-runtime/issues/2804
Bug Report
What did you do?
Cloned the
operator-sdk
repo and tried out the example intestdata/helm/memcached-operator
in a local cluster with theWATCH_NAMESPACE
environment variable set todefault
:Check out the repo and go to the example dir:
Create the cluster:
Start the operator with the env variable set:
Create a memcached instance (in the
default
namespace):Observe the operator log:
What did you expect to see?
A Memcached StatefulSet should be created. It works as expected when I omit the
WATCH_NAMESPACE
variable.What did you see instead? Under which circumstances?
Nothing happens and the log shows no entry after the startup.
Environment
Operator type:
/language helm
Kubernetes cluster type:
vanilla (Kind)
$ operator-sdk version
operator-sdk version: "v1.35.0", commit: "e95abdbd5ccb7ca0fd586e0c6f578e491b0a025b", kubernetes version: "v1.28.0", go version: "go1.21.11", GOOS: "darwin", GOARCH: "amd64"
$ go version
(if language is Go)$ kubectl version
Client Version: v1.29.2 Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3 Server Version: v1.28.0
Possible Solution
Additional context