Skip to content

Commit 7db012e

Browse files
authored
Merge pull request #11928 from chrischdi/pr-machineset-precheck-topology-upgrade-pending
✨ machineset: Extend ControlPlaneIsStable preflight check to check for a pending topology based ControlPlane version upgrade
2 parents c950815 + 1e3d127 commit 7db012e

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

docs/book/src/tasks/experimental-features/machineset-preflight-checks.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Enabling `MachineSetPreflightChecks` provides safety in such circumstances by ma
1818

1919
### `ControlPlaneIsStable`
2020

21-
* This preflight check ensures that the ControlPlane is currently stable i.e. the ControlPlane is currently neither provisioning nor upgrading.
21+
* This preflight check ensures that the ControlPlane is currently stable i.e. the ControlPlane is currently neither provisioning, upgrading nor pending an upgrade.
2222
* This preflight check is only performed if:
2323
* The Cluster uses a ControlPlane provider.
2424
* ControlPlane version is defined (`ControlPlane.spec.version` is set).

internal/controllers/machineset/machineset_preflight.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (r *Reconciler) runPreflightChecks(ctx context.Context, cluster *clusterv1.
9191
preflightCheckErrs := []preflightCheckErrorMessage{}
9292
// Run the control-plane-stable preflight check.
9393
if !skipped.Has(clusterv1.MachineSetPreflightCheckControlPlaneIsStable) {
94-
preflightCheckErr, err := r.controlPlaneStablePreflightCheck(controlPlane)
94+
preflightCheckErr, err := r.controlPlaneStablePreflightCheck(controlPlane, cluster, *cpVersion)
9595
if err != nil {
9696
errList = append(errList, err)
9797
}
@@ -142,9 +142,15 @@ func (r *Reconciler) runPreflightChecks(ctx context.Context, cluster *clusterv1.
142142
return nil, nil
143143
}
144144

145-
func (r *Reconciler) controlPlaneStablePreflightCheck(controlPlane *unstructured.Unstructured) (preflightCheckErrorMessage, error) {
145+
func (r *Reconciler) controlPlaneStablePreflightCheck(controlPlane *unstructured.Unstructured, cluster *clusterv1.Cluster, controlPlaneVersion string) (preflightCheckErrorMessage, error) {
146146
cpKlogRef := klog.KRef(controlPlane.GetNamespace(), controlPlane.GetName())
147147

148+
if feature.Gates.Enabled(feature.ClusterTopology) {
149+
if cluster.Spec.Topology != nil && cluster.Spec.Topology.Version != controlPlaneVersion {
150+
return ptr.To(fmt.Sprintf("%s %s has a pending version upgrade to %s (%q preflight check failed)", controlPlane.GetKind(), cpKlogRef, cluster.Spec.Topology.Version, clusterv1.MachineSetPreflightCheckControlPlaneIsStable)), nil
151+
}
152+
}
153+
148154
// Check that the control plane is not provisioning.
149155
isProvisioning, err := contract.ControlPlane().IsProvisioning(controlPlane)
150156
if err != nil {

internal/controllers/machineset/machineset_preflight_test.go

+21
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
)
3737

3838
func TestMachineSetReconciler_runPreflightChecks(t *testing.T) {
39+
utilfeature.SetFeatureGateDuringTest(t, feature.Gates, feature.ClusterTopology, true)
3940
ns := "ns1"
4041

4142
controlPlaneWithNoVersion := builder.ControlPlane(ns, "cp1").Build()
@@ -169,6 +170,26 @@ func TestMachineSetReconciler_runPreflightChecks(t *testing.T) {
169170
},
170171
wantErr: false,
171172
},
173+
{
174+
name: "control plane preflight check: should fail if the cluster defines a different version than the control plane",
175+
cluster: &clusterv1.Cluster{
176+
ObjectMeta: metav1.ObjectMeta{
177+
Namespace: ns,
178+
},
179+
Spec: clusterv1.ClusterSpec{
180+
ControlPlaneRef: contract.ObjToRef(controlPlaneStable),
181+
Topology: &clusterv1.Topology{
182+
Version: "v1.27.2",
183+
},
184+
},
185+
},
186+
controlPlane: controlPlaneStable,
187+
machineSet: &clusterv1.MachineSet{},
188+
wantMessages: []string{
189+
"GenericControlPlane ns1/cp1 has a pending version upgrade to v1.27.2 (\"ControlPlaneIsStable\" preflight check failed)",
190+
},
191+
wantErr: false,
192+
},
172193
{
173194
name: "control plane preflight check: should pass if the control plane is upgrading but the preflight check is skipped",
174195
cluster: &clusterv1.Cluster{

0 commit comments

Comments
 (0)