Skip to content

Commit 9d9b1f2

Browse files
author
Yuvaraj Kakaraparthi
committed
make topology upgrade sequential
1 parent 9bb071e commit 9d9b1f2

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

internal/controllers/topology/cluster/desired_state.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,11 @@ func computeControlPlaneVersion(s *scope.Scope) (string, error) {
333333
if s.Current.MachineDeployments.IsAnyRollingOut() {
334334
return *currentVersion, nil
335335
}
336+
// If any of the MachineDeployments are not at the desired version, then do not pick
337+
// up the desiredVersion yet. We will pick up the new version after all MachineDeployments are at the desired version.
338+
if !s.Current.MachineDeployments.AreAtVersion(*currentVersion) {
339+
return *currentVersion, nil
340+
}
336341

337342
// Control plane and machine deployments are stable.
338343
// Ready to pick up the topology version.
@@ -549,6 +554,16 @@ func computeMachineDeployment(_ context.Context, s *scope.Scope, desiredControlP
549554
// than the number of allowed concurrent upgrades.
550555
func computeMachineDeploymentVersion(s *scope.Scope, desiredControlPlaneState *scope.ControlPlaneState, currentMDState *scope.MachineDeploymentState) (string, error) {
551556
desiredVersion := s.Blueprint.Topology.Version
557+
// If there already exists a control plane then the MachineDeployment should always target to match the current version
558+
// of the control plane.
559+
if s.Current.ControlPlane.Object != nil {
560+
currentCPVersion, err := contract.ControlPlane().Version().Get(s.Current.ControlPlane.Object)
561+
if err != nil {
562+
return "", errors.Wrap(err, "failed to get version of current control plane")
563+
}
564+
desiredVersion = *currentCPVersion
565+
}
566+
552567
// If creating a new machine deployment, we can pick up the desired version
553568
// Note: We are not blocking the creation of new machine deployments when
554569
// the control plane or any of the machine deployments are upgrading/scaling.
@@ -611,6 +626,7 @@ func computeMachineDeploymentVersion(s *scope.Scope, desiredControlPlaneState *s
611626
// Check if we are about to upgrade the control plane. In that case, do not upgrade the machine deployment yet.
612627
// Wait for the new upgrade operation on the control plane to finish before picking up the new version for the
613628
// machine deployment.
629+
// TODO: We probably don't need this check anymore.
614630
currentCPVersion, err := contract.ControlPlane().Version().Get(s.Current.ControlPlane.Object)
615631
if err != nil {
616632
return "", errors.Wrap(err, "failed to get version of current control plane")

internal/controllers/topology/cluster/scope/state.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ func (mds MachineDeploymentsStateMap) RollingOut() []string {
6868
return names
6969
}
7070

71+
// AreAtVersion return true if all the machine deployments are the desired version.
72+
func (mds MachineDeploymentsStateMap) AreAtVersion(version string) bool {
73+
for _, md := range mds {
74+
if !md.IsAtVersion(version) {
75+
return false
76+
}
77+
}
78+
return true
79+
}
80+
7181
// IsAnyRollingOut returns true if at least one of the
7282
// machine deployments is rolling out. False, otherwise.
7383
func (mds MachineDeploymentsStateMap) IsAnyRollingOut() bool {
@@ -96,3 +106,12 @@ type MachineDeploymentState struct {
96106
func (md *MachineDeploymentState) IsRollingOut() bool {
97107
return !mdutil.DeploymentComplete(md.Object, &md.Object.Status) || *md.Object.Spec.Replicas != md.Object.Status.ReadyReplicas
98108
}
109+
110+
// IsAtVersion return true if the MachineDeployment spec version matches the version.
111+
// If the MachineDeployment does not support version then it returns false.
112+
func (md *MachineDeploymentState) IsAtVersion(version string) bool {
113+
if md.Object.Spec.Template.Spec.Version != nil {
114+
return version == *md.Object.Spec.Template.Spec.Version
115+
}
116+
return false
117+
}

0 commit comments

Comments
 (0)