Skip to content

Commit b9d6f26

Browse files
committed
Don't allow concurrent patch uppgrades
Signed-off-by: Stefan Büringer [email protected]
1 parent 3a8728f commit b9d6f26

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

internal/webhooks/cluster.go

+6-13
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,11 @@ func (webhook *Cluster) validateTopology(ctx context.Context, oldCluster, newClu
446446
}
447447

448448
func (webhook *Cluster) validateTopologyVersion(ctx context.Context, fldPath *field.Path, fldValue string, inVersion, oldVersion semver.Version, oldCluster *clusterv1.Cluster) *field.Error {
449+
// Nothing to do if the version doesn't change.
450+
if version.Compare(inVersion, oldVersion, version.WithBuildTags()) == 0 {
451+
return nil
452+
}
453+
449454
// Version could only be increased.
450455
if inVersion.NE(semver.Version{}) && oldVersion.NE(semver.Version{}) && version.Compare(inVersion, oldVersion, version.WithBuildTags()) == -1 {
451456
return field.Invalid(
@@ -469,18 +474,6 @@ func (webhook *Cluster) validateTopologyVersion(ctx context.Context, fldPath *fi
469474
)
470475
}
471476

472-
// Only check the following cases if the minor version increases by 1 (we already return above for >= 2).
473-
ceilVersion = semver.Version{
474-
Major: oldVersion.Major,
475-
Minor: oldVersion.Minor + 1,
476-
Patch: 0,
477-
}
478-
479-
// Return early if its not a minor version upgrade.
480-
if !inVersion.GTE(ceilVersion) {
481-
return nil
482-
}
483-
484477
allErrs := []error{}
485478
// minor version cannot be increased if control plane is upgrading or not yet on the current version
486479
if err := validateTopologyControlPlaneVersion(ctx, webhook.Client, oldCluster, oldVersion); err != nil {
@@ -501,7 +494,7 @@ func (webhook *Cluster) validateTopologyVersion(ctx context.Context, fldPath *fi
501494
return field.Invalid(
502495
fldPath,
503496
fldValue,
504-
fmt.Sprintf("minor version update cannot happen at this time: %v", kerrors.NewAggregate(allErrs)),
497+
fmt.Sprintf("version update cannot happen at this time: %v", kerrors.NewAggregate(allErrs)),
505498
)
506499
}
507500

internal/webhooks/cluster_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -1833,6 +1833,7 @@ func TestClusterTopologyValidation(t *testing.T) {
18331833
name: "should update",
18341834
expectErr: false,
18351835
old: builder.Cluster("fooboo", "cluster1").
1836+
WithControlPlane(builder.ControlPlane("fooboo", "cluster1-cp").Build()).
18361837
WithTopology(builder.ClusterTopology().
18371838
WithClass("foo").
18381839
WithVersion("v1.19.1").
@@ -1855,6 +1856,7 @@ func TestClusterTopologyValidation(t *testing.T) {
18551856
Build()).
18561857
Build(),
18571858
in: builder.Cluster("fooboo", "cluster1").
1859+
WithControlPlane(builder.ControlPlane("fooboo", "cluster1-cp").Build()).
18581860
WithTopology(builder.ClusterTopology().
18591861
WithClass("foo").
18601862
WithVersion("v1.19.2").
@@ -1876,6 +1878,21 @@ func TestClusterTopologyValidation(t *testing.T) {
18761878
Build()).
18771879
Build()).
18781880
Build(),
1881+
additionalObjects: []client.Object{
1882+
builder.ControlPlane("fooboo", "cluster1-cp").WithVersion("v1.19.1").
1883+
WithStatusFields(map[string]interface{}{"status.version": "v1.19.1"}).
1884+
Build(),
1885+
builder.MachineDeployment("fooboo", "cluster1-workers1").WithLabels(map[string]string{
1886+
clusterv1.ClusterNameLabel: "cluster1",
1887+
clusterv1.ClusterTopologyOwnedLabel: "",
1888+
clusterv1.ClusterTopologyMachineDeploymentNameLabel: "workers1",
1889+
}).WithVersion("v1.19.1").Build(),
1890+
builder.MachinePool("fooboo", "cluster1-pool1").WithLabels(map[string]string{
1891+
clusterv1.ClusterNameLabel: "cluster1",
1892+
clusterv1.ClusterTopologyOwnedLabel: "",
1893+
clusterv1.ClusterTopologyMachinePoolNameLabel: "pool1",
1894+
}).WithVersion("v1.19.1").Build(),
1895+
},
18791896
},
18801897
{
18811898
name: "should return error when upgrade concurrency annotation value is < 1",

0 commit comments

Comments
 (0)