@@ -201,7 +201,7 @@ func (r *Reconciler) reconcileTopologyReconciledCondition(s *scope.Scope, cluste
201201 reason := clusterv1 .ClusterTopologyReconciledClusterUpgradingReason
202202 v1Beta1Reason := clusterv1 .TopologyReconciledClusterUpgradingV1Beta1Reason
203203
204- cpVersion , err := contract .ControlPlane ().Version ().Get (s .Current .ControlPlane .Object )
204+ cpVersion , err := contract .ControlPlane ().Version ().Get (s .Desired .ControlPlane .Object )
205205 if err != nil {
206206 return errors .Wrap (err , "failed to get control plane spec version" )
207207 }
@@ -213,21 +213,15 @@ func (r *Reconciler) reconcileTopologyReconciledCondition(s *scope.Scope, cluste
213213
214214 // If control plane is upgrading surface it, otherwise surface the pending upgrade plan.
215215 if s .UpgradeTracker .ControlPlane .IsStartingUpgrade || s .UpgradeTracker .ControlPlane .IsUpgrading {
216- fmt .Fprintf (msgBuilder , "\n * %s upgrading to version %s" , s .Current .ControlPlane .Object .GetKind (), * cpVersion )
217- if len (s .UpgradeTracker .ControlPlane .UpgradePlan ) > 0 {
218- fmt .Fprintf (msgBuilder , " (%s pending)" , strings .Join (s .UpgradeTracker .ControlPlane .UpgradePlan , ", " ))
219- }
216+ fmt .Fprintf (msgBuilder , "\n * %s upgrading to version %s%s" , s .Current .ControlPlane .Object .GetKind (), * cpVersion , pendingVersions (s .UpgradeTracker .ControlPlane .UpgradePlan , * cpVersion ))
220217 } else if len (s .UpgradeTracker .ControlPlane .UpgradePlan ) > 0 {
221218 fmt .Fprintf (msgBuilder , "\n * %s pending upgrade to version %s" , s .Current .ControlPlane .Object .GetKind (), strings .Join (s .UpgradeTracker .ControlPlane .UpgradePlan , ", " ))
222219 }
223220
224221 // If MachineDeployments are upgrading surface it, if MachineDeployments are pending upgrades then surface the upgrade plans.
225222 upgradingMachineDeploymentNames , pendingMachineDeploymentNames , deferredMachineDeploymentNames := dedupNames (s .UpgradeTracker .MachineDeployments )
226223 if len (upgradingMachineDeploymentNames ) > 0 {
227- fmt .Fprintf (msgBuilder , "\n * %s upgrading to version %s" , nameList ("MachineDeployment" , "MachineDeployments" , upgradingMachineDeploymentNames ), * cpVersion )
228- if len (s .UpgradeTracker .ControlPlane .UpgradePlan ) > 0 {
229- fmt .Fprintf (msgBuilder , " (%s pending)" , strings .Join (s .UpgradeTracker .MachineDeployments .UpgradePlan , ", " ))
230- }
224+ fmt .Fprintf (msgBuilder , "\n * %s upgrading to version %s%s" , nameList ("MachineDeployment" , "MachineDeployments" , upgradingMachineDeploymentNames ), * cpVersion , pendingVersions (s .UpgradeTracker .MachineDeployments .UpgradePlan , * cpVersion ))
231225 }
232226
233227 if len (pendingMachineDeploymentNames ) > 0 && len (s .UpgradeTracker .MachineDeployments .UpgradePlan ) > 0 {
@@ -255,10 +249,7 @@ func (r *Reconciler) reconcileTopologyReconciledCondition(s *scope.Scope, cluste
255249 // If MachinePools are upgrading surface it, if MachinePools are pending upgrades then surface the upgrade plans.
256250 upgradingMachinePoolNames , pendingMachinePoolNames , deferredMachinePoolNames := dedupNames (s .UpgradeTracker .MachinePools )
257251 if len (upgradingMachinePoolNames ) > 0 {
258- fmt .Fprintf (msgBuilder , "\n * %s upgrading to version %s" , nameList ("MachinePool" , "MachinePools" , upgradingMachinePoolNames ), * cpVersion )
259- if len (s .UpgradeTracker .ControlPlane .UpgradePlan ) > 0 {
260- fmt .Fprintf (msgBuilder , " (%s pending)" , strings .Join (s .UpgradeTracker .MachinePools .UpgradePlan , ", " ))
261- }
252+ fmt .Fprintf (msgBuilder , "\n * %s upgrading to version %s%s" , nameList ("MachinePool" , "MachinePools" , upgradingMachinePoolNames ), * cpVersion , pendingVersions (s .UpgradeTracker .MachinePools .UpgradePlan , * cpVersion ))
262253 }
263254
264255 if len (pendingMachinePoolNames ) > 0 && len (s .UpgradeTracker .MachinePools .UpgradePlan ) > 0 {
@@ -315,6 +306,21 @@ func (r *Reconciler) reconcileTopologyReconciledCondition(s *scope.Scope, cluste
315306 return nil
316307}
317308
309+ // pendingVersion return a message with pending version in the upgrad plan.
310+ func pendingVersions (plan []string , version string ) string {
311+ // clone the plan to avoid side effects on the original object.
312+ planWithoutVersion := []string {}
313+ for _ , v := range plan {
314+ if v != version {
315+ planWithoutVersion = append (planWithoutVersion , v )
316+ }
317+ }
318+ if len (planWithoutVersion ) > 0 {
319+ return fmt .Sprintf (" (%s pending)" , strings .Join (planWithoutVersion , ", " ))
320+ }
321+ return ""
322+ }
323+
318324// dedupNames take care of names that might exist in multiple lists.
319325func dedupNames (t scope.WorkerUpgradeTracker ) ([]string , []string , []string ) {
320326 // upgrading names are preserved
0 commit comments