@@ -333,6 +333,11 @@ func computeControlPlaneVersion(s *scope.Scope) (string, error) {
333
333
if s .Current .MachineDeployments .IsAnyRollingOut () {
334
334
return * currentVersion , nil
335
335
}
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
+ }
336
341
337
342
// Control plane and machine deployments are stable.
338
343
// Ready to pick up the topology version.
@@ -549,6 +554,16 @@ func computeMachineDeployment(_ context.Context, s *scope.Scope, desiredControlP
549
554
// than the number of allowed concurrent upgrades.
550
555
func computeMachineDeploymentVersion (s * scope.Scope , desiredControlPlaneState * scope.ControlPlaneState , currentMDState * scope.MachineDeploymentState ) (string , error ) {
551
556
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
+
552
567
// If creating a new machine deployment, we can pick up the desired version
553
568
// Note: We are not blocking the creation of new machine deployments when
554
569
// the control plane or any of the machine deployments are upgrading/scaling.
@@ -611,6 +626,7 @@ func computeMachineDeploymentVersion(s *scope.Scope, desiredControlPlaneState *s
611
626
// Check if we are about to upgrade the control plane. In that case, do not upgrade the machine deployment yet.
612
627
// Wait for the new upgrade operation on the control plane to finish before picking up the new version for the
613
628
// machine deployment.
629
+ // TODO: We probably don't need this check anymore.
614
630
currentCPVersion , err := contract .ControlPlane ().Version ().Get (s .Current .ControlPlane .Object )
615
631
if err != nil {
616
632
return "" , errors .Wrap (err , "failed to get version of current control plane" )
0 commit comments