Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions hypershift-operator/controllers/nodepool/capi.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func (c *CAPI) Reconcile(ctx context.Context) error {
} else {
log.Info("Reconciled MachineDeployment", "result", result)
}
c.reconcileMachineDeploymentStatus(ctx, log, md, template)
}

mhc := c.machineHealthCheck()
Expand Down Expand Up @@ -473,12 +474,7 @@ func (c *CAPI) reconcileMachineDeployment(ctx context.Context, log logr.Logger,
}

setMachineDeploymentReplicas(nodePool, machineDeployment)

if updated := c.propagateVersionAndTemplate(log, machineDeployment, machineTemplateCR); updated {
return nil
}

c.reconcileMachineDeploymentStatus(log, machineDeployment, machineTemplateCR)
c.propagateVersionAndTemplate(log, machineDeployment, machineTemplateCR)

return nil
}
Expand Down Expand Up @@ -563,12 +559,11 @@ func (c *CAPI) propagateLabelsAndTaintsToMachines(ctx context.Context, log logr.
return nil
}

func (c *CAPI) propagateVersionAndTemplate(log logr.Logger, machineDeployment *capiv1.MachineDeployment, machineTemplateCR client.Object) bool {
func (c *CAPI) propagateVersionAndTemplate(log logr.Logger, machineDeployment *capiv1.MachineDeployment, machineTemplateCR client.Object) {
nodePool := c.nodePool
userDataSecret := c.UserDataSecret()
targetVersion := c.Version()
targetConfigHash := c.HashWithoutVersion()
isUpdating := false

if userDataSecret.Name != ptr.Deref(machineDeployment.Spec.Template.Spec.Bootstrap.DataSecretName, "") {
log.Info("New user data Secret has been generated",
Expand All @@ -586,29 +581,25 @@ func (c *CAPI) propagateVersionAndTemplate(log logr.Logger, machineDeployment *c
}
machineDeployment.Spec.Template.Spec.Version = &targetVersion
machineDeployment.Spec.Template.Spec.Bootstrap.DataSecretName = ptr.To(userDataSecret.Name)
isUpdating = true
}

if machineTemplateCR.GetName() != machineDeployment.Spec.Template.Spec.InfrastructureRef.Name {
log.Info("New machine template has been generated",
"current", machineDeployment.Spec.Template.Spec.InfrastructureRef.Name,
"target", machineTemplateCR.GetName())
machineDeployment.Spec.Template.Spec.InfrastructureRef.Name = machineTemplateCR.GetName()
isUpdating = true
}

return isUpdating
}

func (c *CAPI) reconcileMachineDeploymentStatus(log logr.Logger, machineDeployment *capiv1.MachineDeployment, machineTemplateCR client.Object) {
func (c *CAPI) reconcileMachineDeploymentStatus(ctx context.Context, log logr.Logger, machineDeployment *capiv1.MachineDeployment, machineTemplateCR client.Object) {
nodePool := c.nodePool
targetVersion := c.Version()
targetConfigHash := c.HashWithoutVersion()
targetConfigVersionHash := c.Hash()

// If the MachineDeployment is now processing we know
// is at the expected version (spec.version) and config (userData Secret) so we reconcile status and annotation.
if MachineDeploymentComplete(machineDeployment) {
if MachineDeploymentComplete(ctx, c.Client, machineDeployment, machineTemplateCR.GetName()) {
if nodePool.Status.Version != targetVersion {
log.Info("Version update complete",
"previous", nodePool.Status.Version, "new", targetVersion)
Expand Down
Loading