Skip to content

DefaultLabelSelector overrides ByObject.Label in DefaultNamespaces #2804

Closed
@robbie-demuth

Description

@robbie-demuth

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions