Skip to content

Commit 74bbadf

Browse files
Cloud Userkashifest
authored andcommitted
BMH pause annotation should be synced with CAPM3 machine
Signed-off-by: Kashif Khan <[email protected]>
1 parent ca341fd commit 74bbadf

File tree

2 files changed

+40
-15
lines changed

2 files changed

+40
-15
lines changed

controllers/metal3machine_controller.go

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -152,29 +152,23 @@ func (r *Metal3MachineReconciler) Reconcile(ctx context.Context, req ctrl.Reques
152152
}
153153

154154
// Check pause annotation on associated bmh (if any)
155-
if !cluster.Spec.Paused {
156-
err := machineMgr.RemovePauseAnnotation(ctx)
157-
if err != nil {
158-
machineLog.Info("failed to check pause annotation on associated bmh")
159-
conditions.MarkFalse(capm3Machine, infrav1.AssociateBMHCondition, infrav1.PauseAnnotationRemoveFailedReason, clusterv1.ConditionSeverityInfo, "")
160-
return ctrl.Result{}, nil
161-
}
162-
} else {
163-
// set pause annotation on associated bmh (if any)
155+
if annotations.IsPaused(cluster, capm3Machine) {
164156
err := machineMgr.SetPauseAnnotation(ctx)
165157
if err != nil {
166158
machineLog.Info("failed to set pause annotation on associated bmh")
167159
conditions.MarkFalse(capm3Machine, infrav1.AssociateBMHCondition, infrav1.PauseAnnotationSetFailedReason, clusterv1.ConditionSeverityInfo, "")
168160
return ctrl.Result{}, nil
169161
}
170-
}
171-
172-
// Return early if the M3Machine or Cluster is paused.
173-
if annotations.IsPaused(cluster, capm3Machine) {
174162
machineLog.Info("reconciliation is paused for this object")
175163
conditions.MarkFalse(capm3Machine, infrav1.AssociateBMHCondition, infrav1.Metal3MachinePausedReason, clusterv1.ConditionSeverityInfo, "")
176164
return ctrl.Result{Requeue: true, RequeueAfter: requeueAfter}, nil
177165
}
166+
err = machineMgr.RemovePauseAnnotation(ctx)
167+
if err != nil {
168+
machineLog.Info("failed to remove pause annotation on associated bmh")
169+
conditions.MarkFalse(capm3Machine, infrav1.AssociateBMHCondition, infrav1.PauseAnnotationRemoveFailedReason, clusterv1.ConditionSeverityInfo, "")
170+
return ctrl.Result{}, nil
171+
}
178172

179173
// Handle deleted machines
180174
if !capm3Machine.ObjectMeta.DeletionTimestamp.IsZero() {

test/e2e/pivoting.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,21 @@ func pivoting(ctx context.Context, inputGetter func() PivotingInput) {
202202
return input.TargetCluster.GetClient().Get(ctx, client.ObjectKey{Name: "kube-system"}, kubeSystem)
203203
}, "5s", "100ms").Should(Succeed(), "Failed to assert target API server stability")
204204

205+
Logf("Dump the target cluster resources before pivoting")
206+
framework.DumpAllResources(ctx, framework.DumpAllResourcesInput{
207+
Lister: input.TargetCluster.GetClient(),
208+
Namespace: input.Namespace,
209+
LogPath: filepath.Join(input.ArtifactFolder, "clusters", "target-cluster-before-pivot", "resources"),
210+
KubeConfigPath: input.TargetCluster.GetKubeconfigPath(),
211+
ClusterctlConfigPath: input.ClusterctlConfigPath,
212+
})
213+
214+
By("Fetch logs from target cluster before pivoting")
215+
err = FetchClusterLogs(input.TargetCluster, filepath.Join(input.ArtifactFolder, "clusters", "target-cluster-before-pivot", "resources"))
216+
if err != nil {
217+
Logf("Error: %v", err)
218+
}
219+
205220
By("Moving the cluster to self hosted")
206221
clusterctl.Move(ctx, clusterctl.MoveInput{
207222
LogFolder: filepath.Join(input.ArtifactFolder, "clusters", input.ClusterName+"-bootstrap"),
@@ -212,6 +227,21 @@ func pivoting(ctx context.Context, inputGetter func() PivotingInput) {
212227
})
213228
LogFromFile(filepath.Join(input.ArtifactFolder, "clusters", input.ClusterName+"-bootstrap", "logs", input.Namespace, "clusterctl-move.log"))
214229

230+
By("Fetch logs from target cluster after pivoting")
231+
err = FetchClusterLogs(input.TargetCluster, filepath.Join(input.ArtifactFolder, "clusters", "target-cluster-after-pivot", "resources"))
232+
if err != nil {
233+
Logf("Error: %v", err)
234+
}
235+
236+
Logf("Dump the target cluster resources after pivoting")
237+
framework.DumpAllResources(ctx, framework.DumpAllResourcesInput{
238+
Lister: input.TargetCluster.GetClient(),
239+
Namespace: input.Namespace,
240+
LogPath: filepath.Join(input.ArtifactFolder, "clusters", "target-cluster-after-pivot", "resources"),
241+
KubeConfigPath: input.TargetCluster.GetKubeconfigPath(),
242+
ClusterctlConfigPath: input.ClusterctlConfigPath,
243+
})
244+
215245
By("Remove BMO deployment from the source cluster")
216246
RemoveDeployment(ctx, func() RemoveDeploymentInput {
217247
return RemoveDeploymentInput{
@@ -220,6 +250,7 @@ func pivoting(ctx context.Context, inputGetter func() PivotingInput) {
220250
Name: input.E2EConfig.MustGetVariable(NamePrefix) + "-controller-manager",
221251
}
222252
})
253+
223254
pivotingCluster := framework.DiscoveryAndWaitForCluster(ctx, framework.DiscoveryAndWaitForClusterInput{
224255
Getter: input.TargetCluster.GetClient(),
225256
Namespace: input.Namespace,
@@ -334,7 +365,6 @@ func RemoveDeployment(ctx context.Context, inputGetter func() RemoveDeploymentIn
334365
func labelBMOCRDs(ctx context.Context, targetCluster framework.ClusterProxy) {
335366
labels := map[string]string{}
336367
labels[clusterctlv1.ClusterctlLabel] = ""
337-
labels[clusterctlv1.ClusterctlMoveLabel] = ""
338368
labels[clusterctlv1.ClusterctlMoveHierarchyLabel] = ""
339369
labels[clusterv1.ProviderNameLabel] = "metal3"
340370
crdName := "baremetalhosts.metal3.io"
@@ -345,7 +375,8 @@ func labelBMOCRDs(ctx context.Context, targetCluster framework.ClusterProxy) {
345375
func labelHDCRDs(ctx context.Context, targetCluster framework.ClusterProxy) {
346376
labels := map[string]string{}
347377
labels[clusterctlv1.ClusterctlLabel] = ""
348-
labels[clusterctlv1.ClusterctlMoveLabel] = ""
378+
labels[clusterctlv1.ClusterctlMoveHierarchyLabel] = ""
379+
labels[clusterv1.ProviderNameLabel] = "metal3"
349380
crdName := "hardwaredata.metal3.io"
350381
err := LabelCRD(ctx, targetCluster.GetClient(), crdName, labels)
351382
Expect(err).ToNot(HaveOccurred(), "Cannot label HD CRDs")

0 commit comments

Comments
 (0)