Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change unnamed related object from * to - #212

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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