Skip to content

Commit

Permalink
Move failed upgrade handling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
HomayoonAlimohammadi committed Oct 17, 2024
1 parent 3e5e588 commit 8e9c788
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions controlplane/controllers/orchestrated_inplace_upgrade_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,33 +104,42 @@ func (r *OrchestratedInPlaceUpgradeController) Reconcile(ctx context.Context, re
return ctrl.Result{}, fmt.Errorf("failed to create scope: %w", err)
}

lockedMachine, err := r.lock.IsLocked(ctx, scope.cluster)
upgradingMachine, err := r.lock.IsLocked(ctx, scope.cluster)
if err != nil {
return ctrl.Result{}, fmt.Errorf("failed to check if upgrade is locked: %w", err)
}

// Upgrade is locked and a machine is already upgrading
if lockedMachine != nil {
if upgradingMachine != nil {
// NOTE(Hue): Maybe none of the `upgrade-to` and `release` annotations are set on the machine.
// If that's the case, the machine will never get upgraded.
// We consider this a stale lock and unlock the upgrade process.
if inplace.GetUpgradeInstructions(lockedMachine) != scope.upgradeTo {
log.V(1).Info("Machine does not have expected upgrade instructions, unlocking...", "machine", lockedMachine.Name)
if inplace.GetUpgradeInstructions(upgradingMachine) != scope.upgradeTo {
log.V(1).Info("Machine does not have expected upgrade instructions, unlocking...", "machine", upgradingMachine.Name)
if err := r.lock.Unlock(ctx, scope.cluster); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to unlock upgrade: %w", err)
}
return ctrl.Result{Requeue: true}, nil
}

if inplace.IsUpgraded(lockedMachine, scope.upgradeTo) {
if inplace.IsUpgraded(upgradingMachine, scope.upgradeTo) {
if err := r.lock.Unlock(ctx, scope.cluster); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to unlock upgrade: %w", err)
}

return ctrl.Result{Requeue: true}, nil
}

log.V(1).Info("Upgrade is locked, requeuing...", "machine", lockedMachine.Name)
if inplace.IsMachineUpgradeFailed(upgradingMachine) {
log.Info("Machine upgrade failed for machine, requeuing...", "machine", upgradingMachine.Name)
if err := r.markUpgradeFailed(ctx, scope, upgradingMachine); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to mark upgrade as failed: %w", err)
}

return ctrl.Result{RequeueAfter: 5 * time.Second}, nil
}

log.V(1).Info("Upgrade is locked, a machine is upgrading, requeuing...", "machine", upgradingMachine.Name)
return ctrl.Result{RequeueAfter: 5 * time.Second}, nil
}

Expand All @@ -148,15 +157,6 @@ func (r *OrchestratedInPlaceUpgradeController) Reconcile(ctx context.Context, re
return ctrl.Result{RequeueAfter: 5 * time.Second}, nil
}

if inplace.IsMachineUpgradeFailed(m) {
log.Info("Machine upgrade failed for machine, requeuing...", "machine", m.Name)
if err := r.markUpgradeFailed(ctx, scope, m); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to mark upgrade as failed: %w", err)
}

return ctrl.Result{RequeueAfter: 5 * time.Second}, nil
}

// Lock the process for the machine and start the upgrade
if err := r.lock.Lock(ctx, scope.cluster, m); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to lock upgrade for machine %q: %w", m.Name, err)
Expand Down

0 comments on commit 8e9c788

Please sign in to comment.