Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-ocm-2.8] MGMT-15559: Change detached annotation condition in non-converged flow #5503

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 6 additions & 15 deletions internal/controller/controllers/bmh_agent_controller.go
Expand Up @@ -306,7 +306,7 @@ func (r *BMACReconciler) Reconcile(origCtx context.Context, req ctrl.Request) (c
} else {
// After the agent has started installation, Ironic should not manage the host.
// Adding the detached annotation to the BMH stops Ironic from managing it.
result = r.addBMHDetachedAnnotationIfAgentHasStartedInstallation(log, bmh, agent)
result = r.addBMHDetachedAnnotationIfHostIsRebooting(log, bmh, agent)
}
if res := r.handleReconcileResult(ctx, log, result, bmh); res != nil {
return res.Result()
Expand Down Expand Up @@ -554,20 +554,11 @@ func (r *BMACReconciler) ensureBMHDetached(log logrus.FieldLogger, bmh *bmh_v1al
}

// The detached annotation is added if the installation of the agent associated with
// the host has started.
func (r *BMACReconciler) addBMHDetachedAnnotationIfAgentHasStartedInstallation(log logrus.FieldLogger, bmh *bmh_v1alpha1.BareMetalHost, agent *aiv1beta1.Agent) reconcileResult {
c := conditionsv1.FindStatusCondition(agent.Status.Conditions, aiv1beta1.InstalledCondition)
if c == nil {
log.Debugf("Skipping adding detached annotation. missing install condition \n %v", agent)
return reconcileComplete{}
}
installConditionReason := c.Reason

// Do nothing if InstalledCondition is not in Installed, InProgress, or Failed
if installConditionReason != aiv1beta1.InstallationInProgressReason &&
installConditionReason != aiv1beta1.InstalledReason &&
installConditionReason != aiv1beta1.InstallationFailedReason {
log.Debugf("Skipping adding detached annotation. host not in proper installation condition \n %v", agent)
// the host has reached stages Failed, Rebooting, or Joined
func (r *BMACReconciler) addBMHDetachedAnnotationIfHostIsRebooting(log logrus.FieldLogger, bmh *bmh_v1alpha1.BareMetalHost, agent *aiv1beta1.Agent) reconcileResult {
// Do nothing if host stage is not one of Failed, Rebooting, or Joined
if !funk.Contains([]models.HostStage{models.HostStageFailed, models.HostStageRebooting, models.HostStageJoined}, agent.Status.Progress.CurrentStage) {
log.Debugf("Skipping adding detached annotation. Host hasn't reached stage rebooted, joined, or failed. Current stage: %v", agent.Status.Progress.CurrentStage)
return reconcileComplete{}
}

Expand Down
37 changes: 7 additions & 30 deletions internal/controller/controllers/bmh_agent_controller_test.go
Expand Up @@ -1331,14 +1331,8 @@ var _ = Describe("bmac reconcile", func() {
Expect(updatedHost.ObjectMeta.Annotations).To(HaveKey(BMH_DETACHED_ANNOTATION))
Expect(updatedHost.ObjectMeta.Annotations[BMH_DETACHED_ANNOTATION]).To(Equal("some-other-value"))
})
It("should set the detached annotation if agent is installed", func() {
agent.Status.Conditions = []conditionsv1.Condition{
{
Type: v1beta1.InstalledCondition,
Status: corev1.ConditionTrue,
Reason: v1beta1.InstalledReason,
},
}
It("should set the detached annotation if agent started rebooting", func() {
agent.Status.Progress.CurrentStage = models.HostStageRebooting
Expect(c.Update(ctx, agent)).To(BeNil())

for range [3]int{} {
Expand All @@ -1354,14 +1348,9 @@ var _ = Describe("bmac reconcile", func() {
Expect(updatedHost.ObjectMeta.Annotations[BMH_DETACHED_ANNOTATION]).To(Equal("assisted-service-controller"))
})

It("should set the detached annotation if agent is installation is progressing", func() {
agent.Status.Conditions = []conditionsv1.Condition{
{
Type: v1beta1.InstalledCondition,
Status: corev1.ConditionFalse,
Reason: v1beta1.InstallationInProgressReason,
},
}
It("should set the detached annotation if agent has joined cluster", func() {
agent.Status.Progress.CurrentStage = models.HostStageJoined

Expect(c.Update(ctx, agent)).To(BeNil())

for range [3]int{} {
Expand All @@ -1378,13 +1367,7 @@ var _ = Describe("bmac reconcile", func() {
})

It("should set the detached annotation if agent is installation has failed", func() {
agent.Status.Conditions = []conditionsv1.Condition{
{
Type: v1beta1.InstalledCondition,
Status: corev1.ConditionFalse,
Reason: v1beta1.InstallationFailedReason,
},
}
agent.Status.Progress.CurrentStage = models.HostStageFailed
Expect(c.Update(ctx, agent)).To(BeNil())

for range [3]int{} {
Expand Down Expand Up @@ -1436,13 +1419,7 @@ var _ = Describe("bmac reconcile", func() {

Context("when BMH is detached", func() {
It("should not change the URL when it changes in the InfraEnv", func() {
agent.Status.Conditions = []conditionsv1.Condition{
{
Type: v1beta1.InstalledCondition,
Status: corev1.ConditionFalse,
Reason: v1beta1.InstallationFailedReason,
},
}
agent.Status.Progress.CurrentStage = models.HostStageFailed
Expect(c.Update(ctx, agent)).To(BeNil())

for range [3]int{} {
Expand Down