villebro commented on code in PR #441:
URL:
https://github.com/apache/superset-kubernetes-operator/pull/441#discussion_r4278905523
##########
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:
These assert non-matches, which our dev guidelines state we should avoid. So
I'd remove these
##########
cmd/main_test.go:
##########
@@ -51,3 +57,42 @@ func TestParseWatchNamespaces(t *testing.T) {
})
}
}
+
+func TestCacheOptionsScopesPodsToParentLabel(t *testing.T) {
Review Comment:
Hmm, I'd drop this test. It only checks that Selector.Matches works on
hand-written label sets, so it doesn't verify the invariant this relies on:
that real component and task pods carry LabelKeyParent. If you want a guard,
assert that on the pod templates from the real builders instead.
--
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]