younsl commented on code in PR #441:
URL: 
https://github.com/apache/superset-kubernetes-operator/pull/441#discussion_r4281708529


##########
cmd/main_test.go:
##########
@@ -51,3 +57,42 @@ func TestParseWatchNamespaces(t *testing.T) {
                })
        }
 }
+
+func TestCacheOptionsScopesPodsToParentLabel(t *testing.T) {

Review Comment:
   Good point, dropped it in 4a8b118. The guard now sits in the existing 
reconcile tests instead: TestReconcile_ComponentResourcesCarryLabels checks the 
parent label on the Deployment pod template, and 
TestReconcile_LifecycleCreatesParentOwnedTaskJobAndStatus checks it on the task 
Job pod template. I removed the label from the builders locally to confirm both 
tests fail.



##########
cmd/main_test.go:
##########
@@ -51,3 +57,42 @@ func TestParseWatchNamespaces(t *testing.T) {
                })
        }
 }
+
+func TestCacheOptionsScopesPodsToParentLabel(t *testing.T) {
+       namespaces := map[string]cache.Config{"team-a": {}}
+       opts, err := cacheOptions(namespaces)
+       if err != nil {
+               t.Fatalf("cacheOptions: %v", err)
+       }
+       if _, ok := opts.DefaultNamespaces["team-a"]; !ok || 
len(opts.DefaultNamespaces) != 1 {
+               t.Errorf("DefaultNamespaces = %v, want only team-a", 
sortedKeys(opts.DefaultNamespaces))
+       }
+
+       var podSelector labels.Selector
+       for obj, byObj := range opts.ByObject {
+               if _, ok := obj.(*corev1.Pod); ok {
+                       podSelector = byObj.Label
+               }
+       }
+       if podSelector == nil {
+               t.Fatal("no Pod label selector in ByObject")
+       }
+
+       tests := []struct {
+               name   string
+               labels labels.Set
+               want   bool
+       }{
+               {"component pod", labels.Set{naming.LabelKeyParent: "demo", 
naming.LabelKeyComponent: "web-server"}, true},
+               {"lifecycle task pod", labels.Set{naming.LabelKeyParent: 
"demo", naming.LabelKeyComponent: "init"}, true},
+               {"unrelated pod", labels.Set{"app": "other"}, false},
+               {"no labels", labels.Set{}, false},

Review Comment:
   Agreed, the non-match assertions went away with that test in 4a8b118.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to