@@ -22,7 +22,11 @@ import (
2222// TriggerUninstall will add an annotation to the controller's Deployment indicating that the controller needs to
2323// prepare to be uninstalled. This function will run until all ConfigurationPolicy objects have no finalizers.
2424func TriggerUninstall (
25- ctx context.Context , config * rest.Config , deploymentName , deploymentNamespace , policyNamespace string ,
25+ ctx context.Context ,
26+ config * rest.Config ,
27+ deploymentName string ,
28+ deploymentNamespace string ,
29+ policyNamespaces []string ,
2630) error {
2731 client := kubernetes .NewForConfigOrDie (config )
2832 dynamicClient := dynamic .NewForConfigOrDie (config )
@@ -77,35 +81,35 @@ func TriggerUninstall(
7781 default :
7882 }
7983
80- policyClient := dynamicClient . Resource ( configPolicyGVR ). Namespace ( policyNamespace )
84+ cleanedUp := true
8185
82- configPolicies , err := policyClient .List (ctx , metav1.ListOptions {})
83- if err != nil {
84- if k8serrors .IsServerTimeout (err ) || k8serrors .IsTimeout (err ) {
85- klog .Infof ("Retrying listing the ConfigurationPolicy objects due to error: %s" , err )
86+ for _ , ns := range policyNamespaces {
87+ policyClient := dynamicClient .Resource (configPolicyGVR ).Namespace (ns )
8688
87- continue
88- }
89+ configPolicies , err := policyClient .List (ctx , metav1.ListOptions {})
90+ if err != nil {
91+ klog .Errorf ("Error listing policies: %s" , err )
8992
90- return err
91- }
93+ return err
94+ }
9295
93- cleanedUp := true
96+ for _ , configPolicy := range configPolicies .Items {
97+ if len (configPolicy .GetFinalizers ()) != 0 {
98+ cleanedUp = false
9499
95- for _ , configPolicy := range configPolicies .Items {
96- if len (configPolicy .GetFinalizers ()) != 0 {
97- cleanedUp = false
100+ annos := configPolicy .GetAnnotations ()
101+ annos [common .UninstallingAnnotation ] = time .Now ().Format (time .RFC3339 )
98102
99- annos := configPolicy .GetAnnotations ()
100- annos [common .UninstallingAnnotation ] = time .Now ().Format (time .RFC3339 )
103+ updatedPolicy := configPolicy .DeepCopy ()
101104
102- updatedPolicy := configPolicy . DeepCopy ( )
105+ updatedPolicy . SetAnnotations ( annos )
103106
104- updatedPolicy .SetAnnotations (annos )
107+ if _ , err := policyClient .Update (ctx , updatedPolicy , metav1.UpdateOptions {}); err != nil {
108+ klog .Errorf ("Error updating policy %v/%v with an uninstalling annotation: %s" ,
109+ configPolicy .GetNamespace (), configPolicy .GetName (), err )
105110
106- if _ , err := policyClient .Update (ctx , updatedPolicy , metav1.UpdateOptions {}); err != nil {
107- klog .Errorf ("Error updating policy %v/%v with an uninstalling annotation: %s" ,
108- configPolicy .GetNamespace (), configPolicy .GetName (), err )
111+ return err
112+ }
109113 }
110114 }
111115 }
0 commit comments