Skip to content

Commit 346d48a

Browse files
committed
Add manual paused annotation
Signed-off-by: Kashif Khan <[email protected]>
1 parent 65cee5d commit 346d48a

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

controllers/metal3machine_controller.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import (
3737
"sigs.k8s.io/cluster-api/util"
3838
"sigs.k8s.io/cluster-api/util/annotations"
3939
deprecatedv1beta1conditions "sigs.k8s.io/cluster-api/util/conditions/deprecated/v1beta1"
40-
"sigs.k8s.io/cluster-api/util/deprecated/v1beta1/conditions"
4140
v1beta1conditions "sigs.k8s.io/cluster-api/util/deprecated/v1beta1/conditions"
4241
v1beta2conditions "sigs.k8s.io/cluster-api/util/deprecated/v1beta1/conditions/v1beta2"
4342
v1beta1patch "sigs.k8s.io/cluster-api/util/deprecated/v1beta1/patch"
@@ -179,7 +178,7 @@ func (r *Metal3MachineReconciler) Reconcile(ctx context.Context, req ctrl.Reques
179178
// Check pause annotation on associated bmh (if any)
180179
if annotations.IsPaused(cluster, capm3Machine) {
181180
annotations.AddAnnotations(capm3Machine, map[string]string{"clusterctl.cluster.x-k8s.io/block-move": ""})
182-
err := machineMgr.SetPauseAnnotation(ctx)
181+
err = machineMgr.SetPauseAnnotation(ctx)
183182
if err != nil {
184183
machineLog.Info("failed to set pause annotation on associated bmh")
185184
v1beta1conditions.MarkFalse(capm3Machine, infrav1.AssociateBMHCondition, infrav1.PauseAnnotationSetFailedReason, clusterv1beta1.ConditionSeverityInfo, "")
@@ -204,7 +203,7 @@ func (r *Metal3MachineReconciler) Reconcile(ctx context.Context, req ctrl.Reques
204203
err = machineMgr.RemovePauseAnnotation(ctx)
205204
if err != nil {
206205
machineLog.Info("failed to remove pause annotation on associated bmh")
207-
conditions.MarkFalse(capm3Machine, infrav1.AssociateBMHCondition, infrav1.PauseAnnotationRemoveFailedReason, clusterv1.ConditionSeverityInfo, "")
206+
v1beta1conditions.MarkFalse(capm3Machine, infrav1.AssociateBMHCondition, infrav1.PauseAnnotationRemoveFailedReason, clusterv1beta1.ConditionSeverityInfo, "")
208207
return ctrl.Result{}, nil
209208
}
210209

test/e2e/pivoting.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)