Skip to content

Commit 3caa2d4

Browse files
authored
Merge pull request #12607 from sbueringer/pr-mp-error
🐛 Fix MP error in desired state calculation during Cluster creation
2 parents 49912a8 + fd8c411 commit 3caa2d4

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

exp/topology/desiredstate/desired_state.go

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,30 @@ func (g *generator) Generate(ctx context.Context, s *scope.Scope) (*scope.Cluste
124124
// - Make upgrade decisions on the control plane.
125125
// - Making upgrade decisions on machine pools.
126126
if len(s.Current.MachinePools) > 0 {
127-
client, err := g.ClusterCache.GetClient(ctx, client.ObjectKeyFromObject(s.Current.Cluster))
128-
if err != nil {
129-
return nil, errors.Wrap(err, "failed to check if any MachinePool is upgrading")
127+
machinePoolsHaveMachines := false
128+
for _, mp := range s.Current.MachinePools {
129+
if len(mp.Object.Status.NodeRefs) > 0 {
130+
machinePoolsHaveMachines = true
131+
break
132+
}
130133
}
131-
// Mark all the MachinePools that are currently upgrading.
132-
mpUpgradingNames, err := s.Current.MachinePools.Upgrading(ctx, client)
133-
if err != nil {
134-
return nil, errors.Wrap(err, "failed to check if any MachinePool is upgrading")
134+
135+
// MachinePools can only be upgrading if they have Machines.
136+
// Skipping over the check if they have no Machines, also to avoid failing
137+
// desired state calculation during Cluster creation where there is no
138+
// connection to the workload cluster yet.
139+
if machinePoolsHaveMachines {
140+
client, err := g.ClusterCache.GetClient(ctx, client.ObjectKeyFromObject(s.Current.Cluster))
141+
if err != nil {
142+
return nil, errors.Wrap(err, "failed to check if any MachinePool is upgrading")
143+
}
144+
// Mark all the MachinePools that are currently upgrading.
145+
mpUpgradingNames, err := s.Current.MachinePools.Upgrading(ctx, client)
146+
if err != nil {
147+
return nil, errors.Wrap(err, "failed to check if any MachinePool is upgrading")
148+
}
149+
s.UpgradeTracker.MachinePools.MarkUpgrading(mpUpgradingNames...)
135150
}
136-
s.UpgradeTracker.MachinePools.MarkUpgrading(mpUpgradingNames...)
137151
}
138152

139153
// Compute the desired state of the ControlPlane object, eventually adding a reference to the

0 commit comments

Comments
 (0)