Skip to content

Commit 76dbebc

Browse files
authored
OCPBUGS-32592: Ensure Agent isn't unbound if paused (#140)
Originally, the condition to not unbind the Agent was based on if the AgentMachine is paused AND if the AgentMachine had a deletionTimestamp. This caused the Agent to be unbound when the deletionTimestamp didn't exist yet on the AgentMachine, and is flawed logic. This change updates the condition to make sure we don't continue to unbind the Agent if the AgentMachine is at all paused.
1 parent 2de8dad commit 76dbebc

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

controllers/agentmachine_controller.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,11 @@ func (r *AgentMachineReconciler) handleDeletionHook(ctx context.Context, log log
208208
}
209209

210210
// Skip agent unbind if AgentMachine is paused
211-
if paused := agentMachine.Annotations[clusterv1.PausedAnnotation]; !agentMachine.ObjectMeta.DeletionTimestamp.IsZero() && paused == "true" {
211+
if paused := agentMachine.Annotations[clusterv1.PausedAnnotation]; paused == "true" {
212+
if agentMachine.ObjectMeta.DeletionTimestamp.IsZero() {
213+
log.Info("AgentMachine paused, but not being deleted yet")
214+
return nil, nil
215+
}
212216
log.Info("Skipping unbinding agent since agent machine is paused. Removing machine delete hook annotation")
213217
if err := r.removeHookAndFinalizer(ctx, machine, agentMachine); err != nil {
214218
log.Error(err)

controllers/agentmachine_controller_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,26 @@ var _ = Describe("agentmachine reconcile", func() {
646646
Expect(agent.Spec.ClusterDeploymentName).NotTo(BeNil())
647647
Expect(agent.Spec.ClusterDeploymentName.Name).To(BeEquivalentTo("cluster-deployment-agentMachine-1"))
648648
})
649+
650+
It("doesn't unbind the agent if the AgentMachine doesn't have a deletion timestamp", func() {
651+
agentMachine.ObjectMeta.Annotations = map[string]string{clusterv1.PausedAnnotation: "true"}
652+
controllerutil.AddFinalizer(agentMachine, AgentMachineFinalizerName)
653+
Expect(c.Update(ctx, agentMachine)).To(Succeed())
654+
655+
// mark the machine for deletion
656+
Expect(c.Get(ctx, types.NamespacedName{Namespace: machine.Namespace, Name: machine.Name}, machine)).To(BeNil())
657+
conditions.MarkFalse(machine, clusterv1.PreTerminateDeleteHookSucceededCondition, clusterv1.WaitingExternalHookReason, clusterv1.ConditionSeverityInfo, "")
658+
machine.Annotations = map[string]string{machineDeleteHookName: ""}
659+
Expect(c.Update(ctx, machine)).To(BeNil())
660+
661+
result, err := amr.Reconcile(ctx, newAgentMachineRequest(agentMachine))
662+
Expect(err).To(BeNil())
663+
Expect(result).To(Equal(ctrl.Result{}))
664+
665+
Expect(c.Get(ctx, types.NamespacedName{Name: "agent-1", Namespace: testNamespace}, agent)).To(Succeed())
666+
Expect(agent.Spec.ClusterDeploymentName).NotTo(BeNil())
667+
Expect(agent.Spec.ClusterDeploymentName.Name).To(BeEquivalentTo("cluster-deployment-agentMachine-1"))
668+
})
649669
})
650670
})
651671

0 commit comments

Comments
 (0)