@@ -218,6 +218,9 @@ func pivoting(ctx context.Context, inputGetter func() PivotingInput) {
218218 Logf ("Error: %v" , err )
219219 }
220220
221+ By ("Add paused annotation to BMHs" )
222+ addPausedAnnotation (ctx , input .BootstrapClusterProxy )
223+
221224 By ("Moving the cluster to self hosted" )
222225 clusterctl .Move (ctx , clusterctl.MoveInput {
223226 LogFolder : filepath .Join (input .ArtifactFolder , "clusters" , input .ClusterName + "-bootstrap" ),
@@ -243,6 +246,9 @@ func pivoting(ctx context.Context, inputGetter func() PivotingInput) {
243246 ClusterctlConfigPath : input .ClusterctlConfigPath ,
244247 })
245248
249+ By ("Remove paused annotation from BMH" )
250+ removePausedAnnotation (ctx , input .TargetCluster )
251+
246252 By ("Remove BMO deployment from the source cluster" )
247253 RemoveDeployment (ctx , func () RemoveDeploymentInput {
248254 return RemoveDeploymentInput {
@@ -500,6 +506,9 @@ func rePivoting(ctx context.Context, inputGetter func() RePivotingInput) {
500506 return input .BootstrapClusterProxy .GetClient ().Get (ctx , client.ObjectKey {Name : "kube-system" }, kubeSystem )
501507 }, "5s" , "100ms" ).Should (Succeed (), "Failed to assert bootstrap API server stability" )
502508
509+ By ("Add paused annotation to BMHs" )
510+ addPausedAnnotation (ctx , input .TargetCluster )
511+
503512 By ("Move back to bootstrap cluster" )
504513 clusterctl .Move (ctx , clusterctl.MoveInput {
505514 LogFolder : filepath .Join (input .ArtifactFolder , "clusters" , input .ClusterName + "-pivot" ),
@@ -526,6 +535,9 @@ func rePivoting(ctx context.Context, inputGetter func() RePivotingInput) {
526535 })
527536 Expect (controlPlane ).ToNot (BeNil ())
528537
538+ By ("Remove paused annotation from BMHs" )
539+ removePausedAnnotation (ctx , input .BootstrapClusterProxy )
540+
529541 By ("Check that BMHs are in provisioned state" )
530542 WaitForNumBmhInState (ctx , bmov1alpha1 .StateProvisioned , WaitForNumInput {
531543 Client : input .BootstrapClusterProxy .GetClient (),
@@ -586,3 +598,38 @@ func fetchContainerLogs(containerNames *[]string, folder string, containerComman
586598 Expect (writeErr ).ToNot (HaveOccurred ())
587599 }
588600}
601+
602+ func removePausedAnnotation (ctx context.Context , targetCluster framework.ClusterProxy ) {
603+ bmhs , err := GetAllBmhs (ctx , targetCluster .GetClient (), "metal3" )
604+ Expect (err ).ToNot (HaveOccurred (), "Cannot fetch BMHs" )
605+ for _ , bmh := range bmhs {
606+ if bmh .ObjectMeta .Annotations != nil {
607+ if _ , ok := bmh .ObjectMeta .Annotations [bmov1alpha1 .PausedAnnotation ]; ok {
608+ delete (bmh .ObjectMeta .Annotations , bmov1alpha1 .PausedAnnotation )
609+ err = targetCluster .GetClient ().Update (ctx , & bmh )
610+ if err != nil {
611+ Logf ("Cannot remove paused annotation from BMH %s: %v" , bmh .Name , err )
612+ }
613+ Logf ("Removed paused annotation from BMH %s" , bmh .Name )
614+ }
615+ }
616+ }
617+ Expect (err ).ToNot (HaveOccurred (), "Cannot remove paused annotation from BMHs" )
618+ }
619+
620+ func addPausedAnnotation (ctx context.Context , targetCluster framework.ClusterProxy ) {
621+ bmhs , err := GetAllBmhs (ctx , targetCluster .GetClient (), "metal3" )
622+ Expect (err ).ToNot (HaveOccurred (), "Cannot fetch BMHs" )
623+ for _ , bmh := range bmhs {
624+ if bmh .ObjectMeta .Annotations == nil {
625+ bmh .ObjectMeta .Annotations = map [string ]string {}
626+ }
627+ bmh .ObjectMeta .Annotations [bmov1alpha1 .PausedAnnotation ] = "manual-pivoting"
628+ err = targetCluster .GetClient ().Update (ctx , & bmh )
629+ if err != nil {
630+ Logf ("Cannot add paused annotation to BMH %s: %v" , bmh .Name , err )
631+ }
632+ Logf ("Added paused annotation to BMH %s" , bmh .Name )
633+ }
634+ Expect (err ).ToNot (HaveOccurred (), "Cannot add paused annotation to BMHs" )
635+ }
0 commit comments