@@ -96,6 +96,24 @@ func TestGenerateOverlayOptions(t *testing.T) {
9696 resourceType : ResourceTypeDaemonSet ,
9797 wantLabels : map [string ]string {"app" : "falco" },
9898 },
99+ {
100+ name : "Falco with conflicting selector labels, selector labels take precedence in pod template" ,
101+ obj : builders .NewFalco ().
102+ WithName ("falco-custom" ).WithNamespace (testNamespace ).
103+ WithLabels (map [string ]string {
104+ "app.kubernetes.io/name" : "falco-operator" ,
105+ "app.kubernetes.io/instance" : "instance-1" ,
106+ }).
107+ Build (),
108+ defs : FalcoDefaults ,
109+ resourceType : ResourceTypeDaemonSet ,
110+ // In pod template, selector labels (name, instance) override user labels.
111+ // Non-conflicting user labels (managed-by) are preserved.
112+ wantLabels : map [string ]string {
113+ "app.kubernetes.io/name" : "falco-operator" ,
114+ "app.kubernetes.io/instance" : "instance-1" ,
115+ },
116+ },
99117 {
100118 name : "Component with defaults only produces labels option" ,
101119 obj : builders .NewComponent ().
@@ -164,18 +182,19 @@ func TestGenerateOverlayOptions(t *testing.T) {
164182 for _ , tt := range tests {
165183 t .Run (tt .name , func (t * testing.T ) {
166184 opts := GenerateOverlayOptions (tt .obj )
167- overlay , err := GenerateUserOverlay (tt .resourceType , "test" , tt .defs , opts ... )
185+ overlay , err := GenerateUserOverlay (tt .resourceType , tt . obj . GetName () , tt .defs , opts ... )
168186 require .NoError (t , err )
169187 require .NotNil (t , overlay )
170188
171189 // Labels propagate to metadata and pod template.
172190 for k , v := range tt .wantLabels {
173191 assert .Equal (t , v , overlay .GetLabels ()[k ], "metadata label %s" , k )
174192 }
193+
194+ // Assert that pod template labels include the expected labels (selector labels take precedence over user labels).
175195 templateLabels , _ , _ := unstructured .NestedStringMap (overlay .Object , "spec" , "template" , "metadata" , "labels" )
176- for k , v := range tt .wantLabels {
177- assert .Equal (t , v , templateLabels [k ], "pod template label %s" , k )
178- }
196+ assert .Equal (t , tt .obj .GetName (), templateLabels ["app.kubernetes.io/instance" ], "pod template label app.kubernetes.io/instance should match object name" )
197+ assert .Equal (t , tt .obj .GetName (), templateLabels ["app.kubernetes.io/name" ], "pod template label app.kubernetes.io/name should match object name" )
179198
180199 // Replicas.
181200 if tt .wantReplicas > 0 {
0 commit comments