@@ -19,6 +19,7 @@ package desiredstate
1919
2020import (
2121 "context"
22+ "fmt"
2223 "maps"
2324 "reflect"
2425 "time"
@@ -30,6 +31,7 @@ import (
3031 "k8s.io/apimachinery/pkg/runtime/schema"
3132 "k8s.io/klog/v2"
3233 "k8s.io/utils/ptr"
34+ ctrl "sigs.k8s.io/controller-runtime"
3335 "sigs.k8s.io/controller-runtime/pkg/client"
3436
3537 clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
@@ -507,6 +509,8 @@ func (g *generator) computeControlPlane(ctx context.Context, s *scope.Scope, inf
507509// The version is calculated using the state of the current machine deployments, the current control plane
508510// and the version defined in the topology.
509511func (g * generator ) computeControlPlaneVersion (ctx context.Context , s * scope.Scope ) (string , error ) {
512+ log := ctrl .LoggerFrom (ctx )
513+
510514 topologyVersion := s .Blueprint .Topology .Version
511515 // If we are creating the control plane object (current control plane is nil), use version from topology.
512516 if s .Current .ControlPlane == nil || s .Current .ControlPlane .Object == nil {
@@ -599,8 +603,7 @@ func (g *generator) computeControlPlaneVersion(ctx context.Context, s *scope.Sco
599603 // Also check if MachineDeployments/MachinePools are already upgrading.
600604 // If the MachineDeployments/MachinePools are upgrading, then do not pick up the next control plane version yet.
601605 // We will pick up the new version after the MachineDeployments/MachinePools finish upgrading.
602- if len (s .UpgradeTracker .MachineDeployments .UpgradingNames ()) > 0 ||
603- len (s .UpgradeTracker .MachinePools .UpgradingNames ()) > 0 {
606+ if s .UpgradeTracker .MachineDeployments .IsAnyUpgrading () || s .UpgradeTracker .MachinePools .IsAnyUpgrading () {
604607 return * currentVersion , nil
605608 }
606609
@@ -692,6 +695,11 @@ func (g *generator) computeControlPlaneVersion(ctx context.Context, s *scope.Sco
692695 s .UpgradeTracker .ControlPlane .IsStartingUpgrade = true
693696 s .UpgradeTracker .ControlPlane .IsPendingUpgrade = false
694697
698+ log .Info (fmt .Sprintf ("Control plane %s upgraded from version %s to version %s" , klog .KObj (s .Current .ControlPlane .Object ), * currentVersion , nextVersion ),
699+ "ControlPlaneUpgrades" , toUpgradeStep (s .UpgradeTracker .ControlPlane .UpgradePlan ),
700+ "WorkersUpgrades" , toUpgradeStep (s .UpgradeTracker .MachineDeployments .UpgradePlan , s .UpgradeTracker .MachinePools .UpgradePlan ),
701+ s .Current .ControlPlane .Object .GetKind (), klog .KObj (s .Current .ControlPlane .Object ),
702+ )
695703 return nextVersion , nil
696704}
697705
@@ -857,7 +865,7 @@ func (g *generator) computeMachineDeployment(ctx context.Context, s *scope.Scope
857865 // Add ClusterTopologyMachineDeploymentLabel to the generated InfrastructureMachine template
858866 infraMachineTemplateLabels [clusterv1 .ClusterTopologyMachineDeploymentNameLabel ] = machineDeploymentTopology .Name
859867 desiredMachineDeployment .InfrastructureMachineTemplate .SetLabels (infraMachineTemplateLabels )
860- version , err := g .computeMachineDeploymentVersion (s , machineDeploymentTopology , currentMachineDeployment )
868+ version , err := g .computeMachineDeploymentVersion (ctx , s , machineDeploymentTopology , currentMachineDeployment )
861869 if err != nil {
862870 return nil , err
863871 }
@@ -1039,7 +1047,9 @@ func (g *generator) computeMachineDeployment(ctx context.Context, s *scope.Scope
10391047// computeMachineDeploymentVersion calculates the version of the desired machine deployment.
10401048// The version is calculated using the state of the current machine deployments,
10411049// the current control plane and the version defined in the topology.
1042- func (g * generator ) computeMachineDeploymentVersion (s * scope.Scope , machineDeploymentTopology clusterv1.MachineDeploymentTopology , currentMDState * scope.MachineDeploymentState ) (string , error ) {
1050+ func (g * generator ) computeMachineDeploymentVersion (ctx context.Context , s * scope.Scope , machineDeploymentTopology clusterv1.MachineDeploymentTopology , currentMDState * scope.MachineDeploymentState ) (string , error ) {
1051+ log := ctrl .LoggerFrom (ctx )
1052+
10431053 topologyVersion := s .Blueprint .Topology .Version
10441054 // If creating a new machine deployment, mark it as pending if the control plane is not
10451055 // yet stable. Creating a new MD while the control plane is upgrading can lead to unexpected race conditions.
@@ -1111,6 +1121,12 @@ func (g *generator) computeMachineDeploymentVersion(s *scope.Scope, machineDeplo
11111121 s .UpgradeTracker .MachineDeployments .MarkUpgrading (currentMDState .Object .Name )
11121122
11131123 nextVersion := s .UpgradeTracker .MachineDeployments .UpgradePlan [0 ]
1124+
1125+ log .Info (fmt .Sprintf ("MachineDeployment %s upgraded from version %s to version %s" , klog .KObj (currentMDState .Object ), currentVersion , nextVersion ),
1126+ "ControlPlaneUpgrades" , toUpgradeStep (s .UpgradeTracker .ControlPlane .UpgradePlan ),
1127+ "WorkersUpgrades" , toUpgradeStep (s .UpgradeTracker .MachineDeployments .UpgradePlan , s .UpgradeTracker .MachinePools .UpgradePlan ),
1128+ "MachineDeployment" , klog .KObj (currentMDState .Object ),
1129+ )
11141130 return nextVersion , nil
11151131}
11161132
@@ -1165,7 +1181,7 @@ func (g *generator) computeMachinePools(ctx context.Context, s *scope.Scope) (sc
11651181// computeMachinePool computes the desired state for a MachinePoolTopology.
11661182// The generated machinePool object is calculated using the values from the machinePoolTopology and
11671183// the machinePool class.
1168- func (g * generator ) computeMachinePool (_ context.Context , s * scope.Scope , machinePoolTopology clusterv1.MachinePoolTopology ) (* scope.MachinePoolState , error ) {
1184+ func (g * generator ) computeMachinePool (ctx context.Context , s * scope.Scope , machinePoolTopology clusterv1.MachinePoolTopology ) (* scope.MachinePoolState , error ) {
11691185 desiredMachinePool := & scope.MachinePoolState {}
11701186
11711187 // Gets the blueprint for the MachinePool class.
@@ -1243,7 +1259,7 @@ func (g *generator) computeMachinePool(_ context.Context, s *scope.Scope, machin
12431259 // Add ClusterTopologyMachinePoolLabel to the generated InfrastructureMachinePool object
12441260 infraMachinePoolObjectLabels [clusterv1 .ClusterTopologyMachinePoolNameLabel ] = machinePoolTopology .Name
12451261 desiredMachinePool .InfrastructureMachinePoolObject .SetLabels (infraMachinePoolObjectLabels )
1246- version , err := g .computeMachinePoolVersion (s , machinePoolTopology , currentMachinePool )
1262+ version , err := g .computeMachinePoolVersion (ctx , s , machinePoolTopology , currentMachinePool )
12471263 if err != nil {
12481264 return nil , err
12491265 }
@@ -1359,7 +1375,9 @@ func (g *generator) computeMachinePool(_ context.Context, s *scope.Scope, machin
13591375// computeMachinePoolVersion calculates the version of the desired machine pool.
13601376// The version is calculated using the state of the current machine pools,
13611377// the current control plane and the version defined in the topology.
1362- func (g * generator ) computeMachinePoolVersion (s * scope.Scope , machinePoolTopology clusterv1.MachinePoolTopology , currentMPState * scope.MachinePoolState ) (string , error ) {
1378+ func (g * generator ) computeMachinePoolVersion (ctx context.Context , s * scope.Scope , machinePoolTopology clusterv1.MachinePoolTopology , currentMPState * scope.MachinePoolState ) (string , error ) {
1379+ log := ctrl .LoggerFrom (ctx )
1380+
13631381 topologyVersion := s .Blueprint .Topology .Version
13641382 // If creating a new machine pool, mark it as pending if the control plane is not
13651383 // yet stable. Creating a new MP while the control plane is upgrading can lead to unexpected race conditions.
@@ -1431,6 +1449,12 @@ func (g *generator) computeMachinePoolVersion(s *scope.Scope, machinePoolTopolog
14311449 s .UpgradeTracker .MachinePools .MarkUpgrading (currentMPState .Object .Name )
14321450
14331451 nextVersion := s .UpgradeTracker .MachinePools .UpgradePlan [0 ]
1452+
1453+ log .Info (fmt .Sprintf ("MachinePool %s upgraded from version %s to version %s" , klog .KObj (currentMPState .Object ), currentVersion , nextVersion ),
1454+ "ControlPlaneUpgrades" , toUpgradeStep (s .UpgradeTracker .ControlPlane .UpgradePlan ),
1455+ "WorkersUpgrades" , toUpgradeStep (s .UpgradeTracker .MachineDeployments .UpgradePlan , s .UpgradeTracker .MachinePools .UpgradePlan ),
1456+ "MachinePool" , klog .KObj (currentMPState .Object ),
1457+ )
14341458 return nextVersion , nil
14351459}
14361460
0 commit comments