@@ -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 {
@@ -499,6 +505,9 @@ func rePivoting(ctx context.Context, inputGetter func() RePivotingInput) {
499505 return input .BootstrapClusterProxy .GetClient ().Get (ctx , client.ObjectKey {Name : "kube-system" }, kubeSystem )
500506 }, "5s" , "100ms" ).Should (Succeed (), "Failed to assert bootstrap API server stability" )
501507
508+ By ("Add paused annotation to BMHs" )
509+ addPausedAnnotation (ctx , input .TargetCluster )
510+
502511 By ("Move back to bootstrap cluster" )
503512 clusterctl .Move (ctx , clusterctl.MoveInput {
504513 LogFolder : filepath .Join (input .ArtifactFolder , "clusters" , input .ClusterName + "-pivot" ),
@@ -525,6 +534,9 @@ func rePivoting(ctx context.Context, inputGetter func() RePivotingInput) {
525534 })
526535 Expect (controlPlane ).ToNot (BeNil ())
527536
537+ By ("Remove paused annotation from BMHs" )
538+ removePausedAnnotation (ctx , input .BootstrapClusterProxy )
539+
528540 By ("Check that BMHs are in provisioned state" )
529541 WaitForNumBmhInState (ctx , bmov1alpha1 .StateProvisioned , WaitForNumInput {
530542 Client : input .BootstrapClusterProxy .GetClient (),
@@ -585,3 +597,38 @@ func fetchContainerLogs(containerNames *[]string, folder string, containerComman
585597 Expect (writeErr ).ToNot (HaveOccurred ())
586598 }
587599}
600+
601+ func removePausedAnnotation (ctx context.Context , targetCluster framework.ClusterProxy ) {
602+ bmhs , err := GetAllBmhs (ctx , targetCluster .GetClient (), "metal3" )
603+ Expect (err ).ToNot (HaveOccurred (), "Cannot fetch BMHs" )
604+ for _ , bmh := range bmhs {
605+ if bmh .ObjectMeta .Annotations != nil {
606+ if _ , ok := bmh .ObjectMeta .Annotations [bmov1alpha1 .PausedAnnotation ]; ok {
607+ delete (bmh .ObjectMeta .Annotations , bmov1alpha1 .PausedAnnotation )
608+ err = targetCluster .GetClient ().Update (ctx , & bmh )
609+ if err != nil {
610+ Logf ("Cannot remove paused annotation from BMH %s: %v" , bmh .Name , err )
611+ }
612+ Logf ("Removed paused annotation from BMH %s" , bmh .Name )
613+ }
614+ }
615+ }
616+ Expect (err ).ToNot (HaveOccurred (), "Cannot remove paused annotation from BMHs" )
617+ }
618+
619+ func addPausedAnnotation (ctx context.Context , targetCluster framework.ClusterProxy ) {
620+ bmhs , err := GetAllBmhs (ctx , targetCluster .GetClient (), "metal3" )
621+ Expect (err ).ToNot (HaveOccurred (), "Cannot fetch BMHs" )
622+ for _ , bmh := range bmhs {
623+ if bmh .ObjectMeta .Annotations == nil {
624+ bmh .ObjectMeta .Annotations = map [string ]string {}
625+ }
626+ bmh .ObjectMeta .Annotations [bmov1alpha1 .PausedAnnotation ] = "manual-pivoting"
627+ err = targetCluster .GetClient ().Update (ctx , & bmh )
628+ if err != nil {
629+ Logf ("Cannot add paused annotation to BMH %s: %v" , bmh .Name , err )
630+ }
631+ Logf ("Added paused annotation to BMH %s" , bmh .Name )
632+ }
633+ Expect (err ).ToNot (HaveOccurred (), "Cannot add paused annotation to BMHs" )
634+ }
0 commit comments