@@ -135,7 +135,7 @@ var _ = Describe("PolicyRef Tier", func() {
135135 currentServiceAccount )
136136 }, timeout , pollingInterval ).Should (BeNil ())
137137
138- Byf ("Verifying ServicdAccount has proper labels" )
138+ Byf ("Verifying ServiceAccount has proper labels" )
139139 currentServiceAccount := & corev1.ServiceAccount {}
140140 Expect (workloadClient .Get (context .TODO (),
141141 types.NamespacedName {Namespace : saNamespace , Name : saName },
@@ -144,6 +144,8 @@ var _ = Describe("PolicyRef Tier", func() {
144144 v , ok := currentServiceAccount .Labels [firstConfigMapLabelKey ]
145145 Expect (ok ).To (BeTrue ())
146146 Expect (v ).To (Equal (firstConfigMapLabelValue ))
147+ v , ok = currentServiceAccount .Labels [secondConfigMapLabelKey ]
148+ Expect (ok ).To (BeFalse ())
147149
148150 Byf ("Verifying ClusterSummary %s status reports conflict for Resources feature" , clusterSummary .Name )
149151 Eventually (func () bool {
@@ -165,7 +167,7 @@ var _ = Describe("PolicyRef Tier", func() {
165167 return false
166168 }, timeout , pollingInterval ).Should (BeTrue ())
167169
168- By ("Updating second ConfigMap tier" )
170+ By (fmt . Sprintf ( "Updating ConfigMap %s/%s tier" , secondConfigMap . Namespace , secondConfigMap . Name ) )
169171 const lowerTier = 90
170172 err = retry .RetryOnConflict (retry .DefaultRetry , func () error {
171173 Expect (k8sClient .Get (context .TODO (),
@@ -177,18 +179,22 @@ var _ = Describe("PolicyRef Tier", func() {
177179 Name : firstConfigMap .Name ,
178180 },
179181 {
180- Tier : lowerTier ,
181182 Kind : string (libsveltosv1beta1 .ConfigMapReferencedResourceKind ),
182183 Namespace : secondConfigMap .Namespace ,
183184 Name : secondConfigMap .Name ,
185+ Tier : lowerTier ,
184186 },
185187 }
186188 return k8sClient .Update (context .TODO (), currentClusterProfile )
187189 })
188190 Expect (err ).To (BeNil ())
189191
190- Byf ("Verifying ClusterSummary %s status is set to Deployed for Resources feature" , clusterSummary .Name )
191- verifyFeatureStatusIsProvisioned (kindWorkloadCluster .GetNamespace (), clusterSummary .Name , libsveltosv1beta1 .FeatureResources )
192+ Expect (k8sClient .Get (context .TODO (),
193+ types.NamespacedName {Name : clusterProfile .Name }, currentClusterProfile )).To (Succeed ())
194+
195+ clusterSummary = verifyClusterSummary (clusterops .ClusterProfileLabelName ,
196+ currentClusterProfile .Name , & currentClusterProfile .Spec ,
197+ kindWorkloadCluster .GetNamespace (), kindWorkloadCluster .GetName (), getClusterType ())
192198
193199 Byf ("Verifying proper ServiceAccount is still present in the workload cluster with correct labels" )
194200 Eventually (func () bool {
@@ -203,12 +209,63 @@ var _ = Describe("PolicyRef Tier", func() {
203209 if currentServiceAccount .Labels == nil {
204210 return false
205211 }
212+ _ , ok = currentServiceAccount .Labels [firstConfigMapLabelKey ]
213+ if ok {
214+ return false
215+ }
206216 v , ok = currentServiceAccount .Labels [secondConfigMapLabelKey ]
207217 return ok && v == secondConfigMapLabelValue
208218 }, timeout , pollingInterval ).Should (BeTrue ())
209219
220+ By ("Changing first ConfigMap so there is no conflict anymore" )
221+ newSaNamespace := randomString ()
222+ firstConfigMap = createConfigMapWithPolicy (configMapNs , namePrefix + randomString (),
223+ fmt .Sprintf (resource , newSaNamespace , saName , firstConfigMapLabelKey , firstConfigMapLabelValue ))
224+ Expect (k8sClient .Create (context .TODO (), firstConfigMap )).To (Succeed ())
225+
226+ err = retry .RetryOnConflict (retry .DefaultRetry , func () error {
227+ Expect (k8sClient .Get (context .TODO (),
228+ types.NamespacedName {Name : clusterProfile .Name }, currentClusterProfile )).To (Succeed ())
229+ currentClusterProfile .Spec .PolicyRefs = []configv1beta1.PolicyRef {
230+ {
231+ Kind : string (libsveltosv1beta1 .ConfigMapReferencedResourceKind ),
232+ Namespace : firstConfigMap .Namespace ,
233+ Name : firstConfigMap .Name ,
234+ },
235+ {
236+ Kind : string (libsveltosv1beta1 .ConfigMapReferencedResourceKind ),
237+ Namespace : secondConfigMap .Namespace ,
238+ Name : secondConfigMap .Name ,
239+ Tier : lowerTier ,
240+ },
241+ }
242+ return k8sClient .Update (context .TODO (), currentClusterProfile )
243+ })
244+ Expect (err ).To (BeNil ())
245+
246+ Byf ("Verifying new ServiceAccount is present in the workload cluster with correct labels" )
247+ Eventually (func () bool {
248+ currentServiceAccount := & corev1.ServiceAccount {}
249+ err = workloadClient .Get (context .TODO (),
250+ types.NamespacedName {Namespace : newSaNamespace , Name : saName },
251+ currentServiceAccount )
252+ if err != nil {
253+ return false
254+ }
255+
256+ if currentServiceAccount .Labels == nil {
257+ return false
258+ }
259+ v , ok = currentServiceAccount .Labels [firstConfigMapLabelKey ]
260+ return ok && v == firstConfigMapLabelValue
261+ }, timeout , pollingInterval ).Should (BeTrue ())
262+
263+ Byf ("Verifying ClusterSummary %s status is set to Deployed for Resources feature" , clusterSummary .Name )
264+ verifyFeatureStatusIsProvisioned (clusterSummary .Namespace , clusterSummary .Name , libsveltosv1beta1 .FeatureResources )
265+
210266 policies := []policy {
211267 {kind : "ServiceAccount" , name : saName , namespace : saNamespace , group : "" },
268+ {kind : "ServiceAccount" , name : saName , namespace : newSaNamespace , group : "" },
212269 }
213270 verifyClusterConfiguration (configv1beta1 .ClusterProfileKind , clusterProfile .Name ,
214271 clusterSummary .Spec .ClusterNamespace , clusterSummary .Spec .ClusterName , libsveltosv1beta1 .FeatureResources ,
@@ -228,5 +285,14 @@ var _ = Describe("PolicyRef Tier", func() {
228285 currentServiceAccount )
229286 return err != nil && apierrors .IsNotFound (err )
230287 }, timeout , pollingInterval ).Should (BeTrue ())
288+
289+ Byf ("Verifying second ServiceAccount is removed from the workload cluster" )
290+ Eventually (func () bool {
291+ currentServiceAccount := & corev1.ServiceAccount {}
292+ err = workloadClient .Get (context .TODO (),
293+ types.NamespacedName {Namespace : newSaNamespace , Name : saName },
294+ currentServiceAccount )
295+ return err != nil && apierrors .IsNotFound (err )
296+ }, timeout , pollingInterval ).Should (BeTrue ())
231297 })
232298})
0 commit comments