diff --git a/internal/controller/controllers/bmh_agent_controller.go b/internal/controller/controllers/bmh_agent_controller.go index e97a0f99ddb5..fbcb29f069d5 100644 --- a/internal/controller/controllers/bmh_agent_controller.go +++ b/internal/controller/controllers/bmh_agent_controller.go @@ -880,6 +880,14 @@ func (r *BMACReconciler) reconcileBMH(ctx context.Context, log logrus.FieldLogge dirty = true } + if bmh.Spec.AutomatedCleaningMode != bmh_v1alpha1.CleaningModeDisabled { + // Disable AutomatedCleaningMode if the converged flow is not enabled + // since AutomatedCleaning requires IPA, but disabling the converged flow + // disables IPA. + bmh.Spec.AutomatedCleaningMode = bmh_v1alpha1.CleaningModeDisabled + dirty = true + } + proceed, stopReconcileLoop, requeuePeriod, reason := shouldReconcileBMH(bmh, infraEnv) if !proceed { diff --git a/internal/controller/controllers/bmh_agent_controller_test.go b/internal/controller/controllers/bmh_agent_controller_test.go index ba9482e7c1e9..318ea4e1a3c1 100644 --- a/internal/controller/controllers/bmh_agent_controller_test.go +++ b/internal/controller/controllers/bmh_agent_controller_test.go @@ -347,22 +347,23 @@ var _ = Describe("bmac reconcile", func() { Expect(host.ObjectMeta.Annotations[BMH_INSPECT_ANNOTATION]).To(Equal("disabled")) Expect(host.Spec.AutomatedCleaningMode).To(Equal(bmh_v1alpha1.CleaningModeDisabled)) - // Test that cleaning mode stays the same + // Test that cleaning mode is set to disabled host.Spec.AutomatedCleaningMode = bmh_v1alpha1.CleaningModeMetadata host.Status.Provisioning.State = bmh_v1alpha1.StateProvisioned result = bmhr.reconcileBMH(ctx, bmhr.Log, host, nil) - Expect(result).To(Equal(reconcileComplete{dirty: false, stop: true})) + Expect(result).To(Equal(reconcileComplete{dirty: true, stop: true})) + Expect(host.ObjectMeta.Annotations).To(HaveKey(BMH_INSPECT_ANNOTATION)) Expect(host.ObjectMeta.Annotations[BMH_INSPECT_ANNOTATION]).To(Equal("disabled")) - Expect(host.Spec.AutomatedCleaningMode).To(Equal(bmh_v1alpha1.CleaningModeMetadata)) + Expect(host.Spec.AutomatedCleaningMode).To(Equal(bmh_v1alpha1.CleaningModeDisabled)) // This should not return a dirty result because label is already set result = bmhr.reconcileBMH(ctx, bmhr.Log, host, nil) Expect(result).To(Equal(reconcileComplete{dirty: false, stop: true})) Expect(host.ObjectMeta.Annotations).To(HaveKey(BMH_INSPECT_ANNOTATION)) Expect(host.ObjectMeta.Annotations[BMH_INSPECT_ANNOTATION]).To(Equal("disabled")) - Expect(host.Spec.AutomatedCleaningMode).To(Equal(bmh_v1alpha1.CleaningModeMetadata)) + Expect(host.Spec.AutomatedCleaningMode).To(Equal(bmh_v1alpha1.CleaningModeDisabled)) }) It("should set the ISODownloadURL in the BMH", func() { @@ -376,7 +377,7 @@ var _ = Describe("bmac reconcile", func() { Expect(updatedHost.Spec.Image.URL).To(Equal(isoImageURL)) }) - It("should not disable cleaning and set online true in the BMH", func() { + It("should disable cleaning and set online true in the BMH", func() { result, err := bmhr.Reconcile(ctx, newBMHRequest(host)) Expect(err).To(BeNil()) Expect(result).To(Equal(ctrl.Result{})) @@ -385,8 +386,22 @@ var _ = Describe("bmac reconcile", func() { err = c.Get(ctx, types.NamespacedName{Name: "bmh-reconcile", Namespace: testNamespace}, updatedHost) Expect(err).To(BeNil()) Expect(updatedHost.Spec.Online).To(Equal(true)) - Expect(updatedHost.Spec.AutomatedCleaningMode).NotTo(Equal(bmh_v1alpha1.CleaningModeDisabled)) + Expect(updatedHost.Spec.AutomatedCleaningMode).To(Equal(bmh_v1alpha1.CleaningModeDisabled)) }) + + It("should disable cleaning when set to metadata by user in the BMH", func() { + host.Spec.AutomatedCleaningMode = bmh_v1alpha1.CleaningModeMetadata + result, err := bmhr.Reconcile(ctx, newBMHRequest(host)) + Expect(err).To(BeNil()) + Expect(result).To(Equal(ctrl.Result{})) + + updatedHost := &bmh_v1alpha1.BareMetalHost{} + err = c.Get(ctx, types.NamespacedName{Name: "bmh-reconcile", Namespace: testNamespace}, updatedHost) + Expect(err).To(BeNil()) + Expect(updatedHost.Spec.Online).To(Equal(true)) + Expect(updatedHost.Spec.AutomatedCleaningMode).To(Equal(bmh_v1alpha1.CleaningModeDisabled)) + }) + It("should not reconcile BMH if the updated image has not been around longer than the grace period", func() { // Reconcile with the original ISO _ = bmhr.reconcileBMH(ctx, bmhr.Log, host, nil)