@@ -331,13 +331,6 @@ var _ = Describe("Test framework deployment", func() {
331331 cluster .clusterName ,
332332 "policy.open-cluster-management.io/sync-policies-on-multicluster-hub=true" ,
333333 )
334- DeferCleanup (
335- Kubectl ,
336- "annotate" ,
337- "ManagedCluster" ,
338- cluster .clusterName ,
339- "policy.open-cluster-management.io/sync-policies-on-multicluster-hub-" ,
340- )
341334
342335 // This is a hack to trigger a reconcile.
343336 Kubectl (
@@ -347,8 +340,11 @@ var _ = Describe("Test framework deployment", func() {
347340 "ManagedClusterAddOn" ,
348341 case1ManagedClusterAddOnName ,
349342 "trigger-reconcile=" + time .Now ().Format (time .RFC3339 ),
343+ "--overwrite" ,
350344 )
351345
346+ By (logPrefix + "verifying that the spec sync is not disabled" )
347+
352348 Eventually (func (g Gomega ) {
353349 deploy = GetWithTimeout (
354350 cluster .clusterClient , gvrDeployment , case1DeploymentName , addonNamespace , true , 60 ,
@@ -365,6 +361,52 @@ var _ = Describe("Test framework deployment", func() {
365361 g .Expect (arg ).ToNot (Equal ("--disable-spec-sync=true" ))
366362 }
367363 }, 60 , 5 ).Should (Succeed ())
364+
365+ By (logPrefix + "cleaning up" )
366+
367+ Kubectl ("annotate" , "-n" , cluster .clusterName , "-f" , case1ManagedClusterAddOnCR , "policy-addon-pause=true" )
368+
369+ // This is hacky but this sets the ManifestWork to orphan everything so that we can remove the
370+ // policy.open-cluster-management.io/sync-policies-on-multicluster-hub annotation and not have it delete
371+ // the cluster namespace. This will get reset to SelectivelyOrphan when the addon controller is reconciled
372+ // below.
373+ Eventually (func (g Gomega ) {
374+ mw := GetWithTimeout (clientDynamic , gvrManifestWork , case1MWName , cluster .clusterName , true , 15 )
375+
376+ err := unstructured .SetNestedField (mw .Object , "Orphan" , "spec" , "deleteOption" , "propagationPolicy" )
377+ g .Expect (err ).ToNot (HaveOccurred ())
378+
379+ _ , err = cluster .clusterClient .Resource (gvrManifestWork ).Namespace (cluster .clusterName ).Update (
380+ context .TODO (), mw , metav1.UpdateOptions {},
381+ )
382+ g .Expect (err ).ToNot (HaveOccurred ())
383+ }, 30 , 5 ).Should (Succeed ())
384+
385+ Kubectl (
386+ "annotate" ,
387+ "ManagedCluster" ,
388+ cluster .clusterName ,
389+ "policy.open-cluster-management.io/sync-policies-on-multicluster-hub-" ,
390+ )
391+
392+ Kubectl ("annotate" , "-n" , cluster .clusterName , "-f" , case1ManagedClusterAddOnCR , "policy-addon-pause-" )
393+
394+ // Wait for the ManifestWork to be updated to not reference the cluster namespace.
395+ Eventually (func (g Gomega ) {
396+ mw := GetWithTimeout (clientDynamic , gvrManifestWork , case1MWName , cluster .clusterName , true , 15 )
397+ manifests , _ , _ := unstructured .NestedSlice (mw .Object , "spec" , "workload" , "manifests" )
398+
399+ for _ , manifest := range manifests {
400+ g .Expect (manifest .(map [string ]interface {})["kind" ]).ToNot (Equal ("Namespace" ))
401+ }
402+ }, 30 , 5 ).Should (Succeed ())
403+
404+ By (logPrefix + "deleting the managedclusteraddon" )
405+ Kubectl ("delete" , "-n" , cluster .clusterName , "-f" , case1ManagedClusterAddOnCR , "--timeout=90s" )
406+ deploy = GetWithTimeout (
407+ cluster .clusterClient , gvrDeployment , case1DeploymentName , addonNamespace , false , 30 ,
408+ )
409+ Expect (deploy ).To (BeNil ())
368410 })
369411
370412 It ("should use the onMulticlusterHub value set in the custom annotation" , func () {
0 commit comments