@@ -10,32 +10,32 @@ import (
1010 "open-cluster-management.io/config-policy-controller/test/utils"
1111)
1212
13- const (
14- case9ConfigPolicyNamePod string = "policy-pod-c9-create"
15- case9ConfigPolicyNameAnno string = "policy-pod-anno"
16- case9ConfigPolicyNameNoAnno string = "policy-pod-no-anno"
17- case9ConfigPolicyNameLabelPatch string = "policy-label-patch"
18- case9ConfigPolicyNameLabelCheck string = "policy-label-check"
19- case9ConfigPolicyNameLabelAuto string = "policy-label-check-auto"
20- case9ConfigPolicyNameNSCreate string = "policy-c9-create-ns"
21- case9ConfigPolicyNameIgnoreLabels string = "policy-ignore-labels"
22- case9MultiAnnoNSCreate string = "policy-create-ns-multiple-annotations"
23- case9CheckNSMusthave string = "policy-check-ns-mdcomptype-mh"
24- case9CheckNSMustonlyhave string = "policy-check-ns-mdcomptype-moh"
25- case9PolicyYamlPod string = "../resources/case9_md_check/case9_pod_create.yaml"
26- case9PolicyYamlAnno string = "../resources/case9_md_check/case9_annos.yaml"
27- case9PolicyYamlNoAnno string = "../resources/case9_md_check/case9_no_annos.yaml"
28- case9PolicyYamlLabelPatch string = "../resources/case9_md_check/case9_label_patch.yaml"
29- case9PolicyYamlLabelCheck string = "../resources/case9_md_check/case9_label_check.yaml"
30- case9PolicyYamlLabelAuto string = "../resources/case9_md_check/case9_label_check_auto.yaml"
31- case9PolicyYamlIgnoreLabels string = "../resources/case9_md_check/case9_mustonlyhave_nolabels.yaml"
32- case9PolicyYamlNSCreate string = "../resources/case9_md_check/case9_ns_create.yaml"
33- case9PolicyYamlMultiAnnoNSCreate string = "../resources/case9_md_check/case9_multianno_ns_create.yaml"
34- case9PolicyYamlCheckNSMusthave string = "../resources/case9_md_check/case9_checkns-md-mh.yaml"
35- case9PolicyYamlCheckNSMustonlyhave string = "../resources/case9_md_check/case9_checkns-md-moh.yaml"
36- )
37-
3813var _ = Describe ("Test pod obj template handling" , func () {
14+ const (
15+ case9ConfigPolicyNamePod string = "policy-pod-c9-create"
16+ case9ConfigPolicyNameAnno string = "policy-pod-anno"
17+ case9ConfigPolicyNameNoAnno string = "policy-pod-no-anno"
18+ case9ConfigPolicyNameLabelPatch string = "policy-label-patch"
19+ case9ConfigPolicyNameLabelCheck string = "policy-label-check"
20+ case9ConfigPolicyNameLabelAuto string = "policy-label-check-auto"
21+ case9ConfigPolicyNameNSCreate string = "policy-c9-create-ns"
22+ case9ConfigPolicyNameIgnoreLabels string = "policy-ignore-labels"
23+ case9MultiAnnoNSCreate string = "policy-create-ns-multiple-annotations"
24+ case9CheckNSMusthave string = "policy-check-ns-mdcomptype-mh"
25+ case9CheckNSMustonlyhave string = "policy-check-ns-mdcomptype-moh"
26+ case9PolicyYamlPod string = "../resources/case9_md_check/case9_pod_create.yaml"
27+ case9PolicyYamlAnno string = "../resources/case9_md_check/case9_annos.yaml"
28+ case9PolicyYamlNoAnno string = "../resources/case9_md_check/case9_no_annos.yaml"
29+ case9PolicyYamlLabelPatch string = "../resources/case9_md_check/case9_label_patch.yaml"
30+ case9PolicyYamlLabelCheck string = "../resources/case9_md_check/case9_label_check.yaml"
31+ case9PolicyYamlLabelAuto string = "../resources/case9_md_check/case9_label_check_auto.yaml"
32+ case9PolicyYamlIgnoreLabels string = "../resources/case9_md_check/case9_mustonlyhave_nolabels.yaml"
33+ case9PolicyYamlNSCreate string = "../resources/case9_md_check/case9_ns_create.yaml"
34+ case9PolicyYamlMultiAnnoNSCreate string = "../resources/case9_md_check/case9_multianno_ns_create.yaml"
35+ case9PolicyYamlCheckNSMusthave string = "../resources/case9_md_check/case9_checkns-md-mh.yaml"
36+ case9PolicyYamlCheckNSMustonlyhave string = "../resources/case9_md_check/case9_checkns-md-moh.yaml"
37+ )
38+
3939 Describe ("Create a pod policy on managed cluster in ns:" + testNamespace , Ordered , func () {
4040 It ("should create a policy properly on the managed cluster" , func () {
4141 By ("Creating " + case9ConfigPolicyNamePod + " on managed" )
@@ -128,6 +128,30 @@ var _ = Describe("Test pod obj template handling", func() {
128128 utils .CheckComplianceStatus (g , managedPlc , "Compliant" )
129129 }, defaultTimeoutSeconds , 1 ).Should (Succeed ())
130130 })
131+ It ("should not remove scc namespace annotations even in mustonlyhave mode" , func () {
132+ By ("Checking the current annotations" )
133+ obj := utils .GetWithTimeout (clientManagedDynamic , gvrNS ,
134+ "case9-test" , "" , true , defaultTimeoutSeconds )
135+ Expect (obj .GetAnnotations ()).To (HaveKeyWithValue ("foo.bar/baz" , "hello world" ))
136+ Expect (obj .GetAnnotations ()).To (HaveKeyWithValue ("openshift.io/sa.scc.policy" , "keep" ))
137+
138+ By ("Patching the annotations on the namespace" )
139+ utils .Kubectl ("patch" , "namespace" , "case9-test" , "-o=yaml" , "--type=merge" ,
140+ `-p={"metadata":{"annotations":{` +
141+ `"openshift.io/sa.scc.test": "example",` +
142+ `"openshift.io/sa.scc.policy": "example",` +
143+ `"foo.bar/baz": "incorrect"}}}` )
144+
145+ By ("Verifying the annotations in the policy are updated, and the new SCC annotation is kept" )
146+ Eventually (func (g Gomega ) {
147+ utils .Kubectl ("get" , "namespace" , "case9-test" , "-o=yaml" )
148+ obj := utils .GetWithTimeout (clientManagedDynamic , gvrNS ,
149+ "case9-test" , "" , true , defaultTimeoutSeconds )
150+ g .Expect (obj .GetAnnotations ()).To (HaveKeyWithValue ("foo.bar/baz" , "hello world" ))
151+ g .Expect (obj .GetAnnotations ()).To (HaveKeyWithValue ("openshift.io/sa.scc.test" , "example" ))
152+ g .Expect (obj .GetAnnotations ()).To (HaveKeyWithValue ("openshift.io/sa.scc.policy" , "keep" ))
153+ }, defaultTimeoutSeconds , 1 ).Should (Succeed ())
154+ })
131155 It ("should ignore labels and annotations if none are specified in the template" , func () {
132156 By ("Creating " + case9ConfigPolicyNameIgnoreLabels + " on managed" )
133157 utils .Kubectl ("apply" , "-f" , case9PolicyYamlIgnoreLabels , "-n" , testNamespace )
0 commit comments