Skip to content

Commit

Permalink
Merge pull request #5935 from ykakarap/block_2_minor_upgrades
Browse files Browse the repository at this point in the history
🌱 block +2 minor version upgrade in cluster topology
  • Loading branch information
k8s-ci-robot authored Jan 17, 2022
2 parents 62e4751 + 3f1efe5 commit 32c2c16
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Change `1.21.2` to `1.22.0` as below.
```bash
kubectl patch cluster clusterclass-quickstart --type json --patch '[{"op": "replace", "path": "/spec/topology/version", "value": "v1.22.0"}]'
```
**Important Note**: A +2 minor Kubernetes version upgrade is not allowed in Cluster Topologies. This is to align with existing control plane providers, like KubeadmControlPlane provider, that limit a +2 minor version upgrade. Example: Upgrading from `1.21.2` to `1.23.0` is not allowed.

The upgrade will take some time to roll out as it will take place machine by machine with older versions of the machines only being removed after healthy newer versions come online.

Expand Down
15 changes: 15 additions & 0 deletions internal/webhooks/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,21 @@ func (webhook *Cluster) validateTopology(ctx context.Context, oldCluster, newClu
),
)
}
// A +2 minor version upgrade is not allowed.
ceilVersion := semver.Version{
Major: oldVersion.Major,
Minor: oldVersion.Minor + 2,
Patch: 0,
}
if inVersion.GTE(ceilVersion) {
allErrs = append(
allErrs,
field.Forbidden(
field.NewPath("spec", "topology", "version"),
fmt.Sprintf("version cannot be increased from %q to %q", oldVersion, inVersion),
),
)
}

// If the ClusterClass referenced in the Topology has changed compatibility checks are needed.
if oldCluster.Spec.Topology.Class != newCluster.Spec.Topology.Class {
Expand Down
16 changes: 16 additions & 0 deletions internal/webhooks/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,22 @@ func TestClusterTopologyValidation(t *testing.T) {
Build()).
Build(),
},
{
name: "should return error when upgrading +2 minor version",
expectErr: true,
old: builder.Cluster("fooboo", "cluster1").
WithTopology(builder.ClusterTopology().
WithClass("foo").
WithVersion("v1.2.3").
Build()).
Build(),
in: builder.Cluster("fooboo", "cluster1").
WithTopology(builder.ClusterTopology().
WithClass("foo").
WithVersion("v1.4.0").
Build()).
Build(),
},
{
name: "should return error when duplicated MachineDeployments names exists in a Topology",
expectErr: true,
Expand Down

0 comments on commit 32c2c16

Please sign in to comment.