Skip to content

Commit

Permalink
Don't attempt to contact spoke while unbinding a day2 host (openshift…
Browse files Browse the repository at this point in the history
…#5383)

If an agent is unbound while it is installing the transition will fail,
but the agent spec will still have no cluster deployment reference.
The agent controller should not attempt to contact the spoke cluster in
this case.

Previously unbinding a day-2 host that was installing could cause a
panic. This patch guards against that situation.

https://issues.redhat.com/browse/MGMT-15349
  • Loading branch information
carbonin authored and CrystalChun committed Aug 25, 2023
1 parent 02bb34b commit 0140d9b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/controller/controllers/agent_controller.go
Expand Up @@ -758,7 +758,8 @@ func (r *AgentReconciler) updateStatus(ctx context.Context, log logrus.FieldLogg
if h.Progress != nil && h.Progress.CurrentStage != "" {
// In case the node didn't reboot yet, we get the stage from the host (else)
if swag.StringValue(h.Kind) == models.HostKindAddToExistingClusterHost &&
funk.Contains([]models.HostStage{models.HostStageRebooting, models.HostStageJoined, models.HostStageConfiguring}, h.Progress.CurrentStage) {
funk.Contains([]models.HostStage{models.HostStageRebooting, models.HostStageJoined, models.HostStageConfiguring}, h.Progress.CurrentStage) &&
agent.Spec.ClusterDeploymentName != nil {

spokeClient, err = r.spokeKubeClient(ctx, agent.Spec.ClusterDeploymentName)
if err != nil {
Expand Down
34 changes: 34 additions & 0 deletions internal/controller/controllers/agent_controller_test.go
Expand Up @@ -1148,6 +1148,40 @@ var _ = Describe("agent reconcile", func() {
Expect(result).To(Equal(ctrl.Result{}))
})

It("Agent status update does not panic when running unbind during day2 install", func() {
hostId := strfmt.UUID(uuid.New().String())
infraEnvId := strfmt.UUID(uuid.New().String())
logCollectionTime, _ := strfmt.ParseDateTime("2022-02-17T21:41:51Z")
hostKind := models.HostKindAddToExistingClusterHost
host := &common.Host{
Host: models.Host{
ID: &hostId,
Kind: &hostKind,
ClusterID: &sId,
InfraEnvID: infraEnvId,
Inventory: common.GenerateTestDefaultInventory(),
Status: swag.String(models.HostStatusInstallingInProgress),
StatusInfo: swag.String("Some status info"),
LogsCollectedAt: logCollectionTime,
Progress: &models.HostProgressInfo{
CurrentStage: models.HostStageConfiguring,
InstallationPercentage: 44,
},
},
}
agent := newAgent(hostId.String(), testNamespace, v1beta1.AgentSpec{ClusterDeploymentName: nil})
Expect(c.Create(ctx, agent)).To(BeNil())

mockInstallerInternal.EXPECT().GetHostByKubeKey(gomock.Any()).Return(host, nil).AnyTimes()
mockInstallerInternal.EXPECT().GetClusterInternal(gomock.Any(), installer.V2GetClusterParams{ClusterID: sId}).Return(backEndCluster, nil).AnyTimes()
mockInstallerInternal.EXPECT().UnbindHostInternal(gomock.Any(), gomock.Any(), false, bminventory.NonInteractive).Return(host, fmt.Errorf("no condition found to run transition"))
allowGetInfraEnvInternal(mockInstallerInternal, infraEnvId, "infraEnvName")

result, err := hr.Reconcile(ctx, newHostRequest(agent))
Expect(err).To(BeNil())
Expect(result).To(Equal(ctrl.Result{RequeueAfter: defaultRequeueAfterOnError}))
})

It("Agent bind", func() {
hostId := strfmt.UUID(uuid.New().String())
infraEnvId := strfmt.UUID(uuid.New().String())
Expand Down

0 comments on commit 0140d9b

Please sign in to comment.