kubernetes-sigs / controller-runtime

Repo for the controller-runtime subproject of kubebuilder (sig-apimachinery)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DefaultLabelSelector overrides ByObject.Label in DefaultNamespaces

robbie-demuth opened this issue · comments

Prior to #2421, which substituted Namespaces []string for DefaultNamespaces map[string]Config, it used to be possible to combine DefaultLabelSelector, ByObject, and Namespaces like so:

cache.Options{
	Namespaces: []string{"<OPERATOR_NAMESPACE>"},
	DefaultLabelSelector: metav1.LabelSelectorAsSelector(&metav1.LabelSelector{
		MatchLabels: map[string]string{"app.kubernetes.io/name": "appian"},
	}),
	ByObject: map[client.Object]cache.ByObject{
		&apiv1beta1.Appian{}: {
			Label: labels.Everything(),
		},
	},
},

This resulted in the controller's cache only including objects in the <OPERATOR_NAMESPACE> namespace with all Appian custom resources being included and only other resources matching app.kubernetes.io/name=appian being included

The config above is no longer possible. Now, one must do something like so:

cache.Options{
	DefaultNamespaces: map[string]cache.Config{
		"<OPERATOR_NAMESPACE>": {},
	},
	DefaultLabelSelector: metav1.LabelSelectorAsSelector(&metav1.LabelSelector{
		MatchLabels: map[string]string{"app.kubernetes.io/name": "appian"},
	}),
	ByObject: map[client.Object]cache.ByObject{
		&apiv1beta1.Appian{}: {
			Label: labels.Everything(),
		},
	},
},

This however, doesn't result in the same behavior. It still results in the controller's cache only including objects in the <OPERATOR_NAMESPACE> namespace, but the ByObject.Label configuration is ignored, meaning only Appian custom resources matching app.kubernetes.io/name=appian are included