Skip to content

Commit

Permalink
Change unnamed related object from * to -
Browse files Browse the repository at this point in the history
Since we just want one thing to possibly match, using "*" makes it seem like all of the things are bad. Using "-" also matches what we do for some things when we don’t know/care about the namespace

Ref: https://issues.redhat.com/browse/ACM-8782

Signed-off-by: Yi Rae Kim <yikim@redhat.com>
  • Loading branch information
yiraeChristineKim authored and openshift-merge-bot[bot] committed Mar 1, 2024
1 parent c2a08b8 commit e64cb46
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion controllers/configurationpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1626,7 +1626,7 @@ func (r *ConfigurationPolicyReconciler) handleObjects(
result = objectTmplEvalResult{objectNames: objNames, events: []objectTmplEvalEvent{resultEvent}}

if shouldAddCondensedRelatedObj {
// relatedObjs name is *
// relatedObjs name is -
relatedObjects = addCondensedRelatedObjs(
mapping.Resource,
resultEvent.compliant,
Expand Down
4 changes: 2 additions & 2 deletions controllers/configurationpolicy_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func addRelatedObjects(
}

// addCondensedRelatedObjs does not include all of relatedObjs.
// The Name field is "*". The list of objects will be presented on the console.
// The Name field is "-". The list of objects will be presented on the console.
func addCondensedRelatedObjs(
rsrc schema.GroupVersionResource,
compliant bool,
Expand All @@ -77,7 +77,7 @@ func addCondensedRelatedObjs(
namespaced bool,
reason string,
) (relatedObjects []policyv1.RelatedObject) {
metadata := policyv1.ObjectMetadata{Name: "*"}
metadata := policyv1.ObjectMetadata{Name: "-"}

if namespaced {
metadata.Namespace = namespace
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/case14_selection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ var _ = Describe("Test policy compliance with namespace selection", Ordered, fun
// When hasObjName = false
// compliant: NonCompliant
// metadata:
// name: '*'
// name: '-'
// namespace: range3
// reason: Resource not found but should exist
// is attached for range3.
Expand Down
28 changes: 14 additions & 14 deletions test/e2e/case37_no_name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ var _ = Describe("Test a namespace-scope policy that is missing name", Ordered,
relatedObjectsOne := relatedObjects[0].(map[string]interface{})
Expect(relatedObjectsOne["reason"].(string)).Should(Equal("Resource found but does not match"))

By("Check the name of related object is *")
By("Check the name of related object is -")
name, _, err := unstructured.NestedString(relatedObjects[0].(map[string]interface{}),
"object", "metadata", "name")
Expect(err).ShouldNot(HaveOccurred())
Expect(name).Should(Equal("*"))
Expect(name).Should(Equal("-"))
})
It("should have 1 Compliant relatedObject under the policy's status", func() {
By("Apply good ingress")
Expand Down Expand Up @@ -109,11 +109,11 @@ var _ = Describe("Test a namespace-scope policy that is missing name", Ordered,
reason := relatedObjects[0].(map[string]interface{})["reason"].(string)
Expect(reason).Should(Equal("Resource found as expected"))

By("Check the name of related object is not *")
By("Check the name of related object is not -")
name, _, err := unstructured.NestedString(relatedObjects[0].(map[string]interface{}),
"object", "metadata", "name")
Expect(err).ShouldNot(HaveOccurred())
Expect(name).ShouldNot(Equal("*"))
Expect(name).ShouldNot(Equal("-"))
})
AfterAll(func() {
utils.Kubectl("delete", "-f", case37PolicyNSPath, "-n", testNamespace, "--ignore-not-found")
Expand Down Expand Up @@ -159,11 +159,11 @@ var _ = Describe("Test a namespace-scope policy that is missing name", Ordered,
relatedObjectsOne := relatedObjects[0].(map[string]interface{})
Expect(relatedObjectsOne["reason"].(string)).Should(Equal("Resource not found as expected"))

By("Check the name of related object is *")
By("Check the name of related object is -")
name, _, err := unstructured.NestedString(relatedObjects[0].(map[string]interface{}),
"object", "metadata", "name")
Expect(err).ShouldNot(HaveOccurred())
Expect(name).Should(Equal("*"))
Expect(name).Should(Equal("-"))
})
It("should have 1 Compliant relatedObject under the policy's status", func() {
By("Apply a ingress that is not related to policy")
Expand Down Expand Up @@ -204,11 +204,11 @@ var _ = Describe("Test a namespace-scope policy that is missing name", Ordered,
relatedObjectsOne := relatedObjects[0].(map[string]interface{})
Expect(relatedObjectsOne["reason"].(string)).Should(Equal("Resource not found as expected"))

By("Check the name of related object is *")
By("Check the name of related object is -")
name, _, err := unstructured.NestedString(relatedObjects[0].(map[string]interface{}),
"object", "metadata", "name")
Expect(err).ShouldNot(HaveOccurred())
Expect(name).Should(Equal("*"))
Expect(name).Should(Equal("-"))
})
It("should have 1 NonCompliant relatedObject under the policy's status", func() {
By("Apply a ingress")
Expand Down Expand Up @@ -249,11 +249,11 @@ var _ = Describe("Test a namespace-scope policy that is missing name", Ordered,
reason := relatedObjects[0].(map[string]interface{})["reason"].(string)
Expect(reason).Should(Equal("Resource found but should not exist"))

By("Check the name of related object is not *")
By("Check the name of related object is not -")
name, _, err := unstructured.NestedString(relatedObjects[0].(map[string]interface{}),
"object", "metadata", "name")
Expect(err).ShouldNot(HaveOccurred())
Expect(name).ShouldNot(Equal("*"))
Expect(name).ShouldNot(Equal("-"))
})
AfterAll(func() {
utils.Kubectl("delete", "-f", case37PolicyNotHavePath, "-n", testNamespace, "--ignore-not-found")
Expand Down Expand Up @@ -321,11 +321,11 @@ var _ = Describe("Test a cluster-scope policy that is missing name ", Ordered, f
reason := relatedObjects[0].(map[string]interface{})["reason"].(string)
Expect(reason).Should(Equal("Resource found but does not match"))

By("Check the name of relatedObject is *")
By("Check the name of relatedObject is -")
name, _, err := unstructured.NestedString(relatedObjects[0].(map[string]interface{}),
"object", "metadata", "name")
Expect(err).ShouldNot(HaveOccurred())
Expect(name).Should(Equal("*"))
Expect(name).Should(Equal("-"))
})
AfterEach(func() {
utils.Kubectl("delete", "-f", case37PolicyCSPath, "-n", testNamespace, "--ignore-not-found")
Expand Down Expand Up @@ -380,11 +380,11 @@ var _ = Describe("Test a cluster-scope policy that is missing name ", Ordered, f
reason := relatedObjects[0].(map[string]interface{})["reason"].(string)
Expect(reason).Should(Equal("Resource not found as expected"))

By("Check the name of relatedObject is *")
By("Check the name of relatedObject is -")
name, _, err := unstructured.NestedString(relatedObjects[0].(map[string]interface{}),
"object", "metadata", "name")
Expect(err).ShouldNot(HaveOccurred())
Expect(name).Should(Equal("*"))
Expect(name).Should(Equal("-"))
})
AfterEach(func() {
utils.Kubectl("delete", "-f", case37PolicyCSMustnothavePath, "-n", testNamespace, "--ignore-not-found")
Expand Down

0 comments on commit e64cb46

Please sign in to comment.