@@ -371,6 +371,62 @@ var _ = Describe("TrustManager", Ordered, Label("Feature:TrustManager"), func()
371371 })
372372 })
373373
374+ // -------------------------------------------------------------------------
375+ // Managed label removal reconciliation
376+ // -------------------------------------------------------------------------
377+
378+ Context ("managed label removal reconciliation" , func () {
379+ It ("should restore the managed label when removed externally from resources" , func () {
380+ createTrustManager (newTrustManagerCR ())
381+
382+ // The "app" label is the managed resource label used by the predicate
383+ // to filter watch events. Removing it tests that the predicate checks
384+ // both old and new objects on updates, so the event is not silently dropped.
385+
386+ By ("removing managed label from ServiceAccount" )
387+ sa , err := clientset .CoreV1 ().ServiceAccounts (trustManagerNamespace ).Get (ctx , trustManagerServiceAccountName , metav1.GetOptions {})
388+ Expect (err ).ShouldNot (HaveOccurred ())
389+ delete (sa .Labels , "app" )
390+ _ , err = clientset .CoreV1 ().ServiceAccounts (trustManagerNamespace ).Update (ctx , sa , metav1.UpdateOptions {})
391+ Expect (err ).ShouldNot (HaveOccurred ())
392+
393+ By ("verifying controller restores managed label on ServiceAccount" )
394+ Eventually (func (g Gomega ) {
395+ sa , err := clientset .CoreV1 ().ServiceAccounts (trustManagerNamespace ).Get (ctx , trustManagerServiceAccountName , metav1.GetOptions {})
396+ g .Expect (err ).ShouldNot (HaveOccurred ())
397+ g .Expect (sa .Labels ).Should (HaveKeyWithValue ("app" , trustManagerCommonName ))
398+ }, lowTimeout , fastPollInterval ).Should (Succeed ())
399+
400+ By ("removing managed label from Deployment" )
401+ dep , err := clientset .AppsV1 ().Deployments (trustManagerNamespace ).Get (ctx , trustManagerDeploymentName , metav1.GetOptions {})
402+ Expect (err ).ShouldNot (HaveOccurred ())
403+ delete (dep .Labels , "app" )
404+ _ , err = clientset .AppsV1 ().Deployments (trustManagerNamespace ).Update (ctx , dep , metav1.UpdateOptions {})
405+ Expect (err ).ShouldNot (HaveOccurred ())
406+
407+ By ("verifying controller restores managed label on Deployment" )
408+ Eventually (func (g Gomega ) {
409+ dep , err := clientset .AppsV1 ().Deployments (trustManagerNamespace ).Get (ctx , trustManagerDeploymentName , metav1.GetOptions {})
410+ g .Expect (err ).ShouldNot (HaveOccurred ())
411+ g .Expect (dep .Labels ).Should (HaveKeyWithValue ("app" , trustManagerCommonName ))
412+ }, lowTimeout , fastPollInterval ).Should (Succeed ())
413+
414+ By ("removing managed label from ClusterRole" )
415+ cr , err := clientset .RbacV1 ().ClusterRoles ().Get (ctx , trustManagerClusterRoleName , metav1.GetOptions {})
416+ Expect (err ).ShouldNot (HaveOccurred ())
417+ delete (cr .Labels , "app" )
418+ _ , err = clientset .RbacV1 ().ClusterRoles ().Update (ctx , cr , metav1.UpdateOptions {})
419+ Expect (err ).ShouldNot (HaveOccurred ())
420+
421+ By ("verifying controller restores managed label on ClusterRole" )
422+ Eventually (func (g Gomega ) {
423+ cr , err := clientset .RbacV1 ().ClusterRoles ().Get (ctx , trustManagerClusterRoleName , metav1.GetOptions {})
424+ g .Expect (err ).ShouldNot (HaveOccurred ())
425+ g .Expect (cr .Labels ).Should (HaveKeyWithValue ("app" , trustManagerCommonName ))
426+ }, lowTimeout , fastPollInterval ).Should (Succeed ())
427+ })
428+ })
429+
374430 // -------------------------------------------------------------------------
375431 // Deployment configuration
376432 // -------------------------------------------------------------------------
0 commit comments