Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischdi committed Feb 7, 2024
1 parent 81d7119 commit bdf09a2
Showing 1 changed file with 37 additions and 224 deletions.
261 changes: 37 additions & 224 deletions internal/webhooks/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1255,240 +1255,53 @@ func TestClusterTopologyValidation(t *testing.T) {
Build(),
},
{
name: "should return error when topology does not have class",
expectErr: true,
in: builder.Cluster("fooboo", "cluster1").
WithTopology(&clusterv1.Topology{}).
Build(),
},
{
name: "should return error when topology does not have valid version",
expectErr: true,
in: builder.Cluster("fooboo", "cluster1").
WithTopology(builder.ClusterTopology().
WithClass("foo").
WithVersion("invalid").Build()).
Build(),
},
{
name: "should return error when downgrading topology version - major",
expectErr: true,
old: builder.Cluster("fooboo", "cluster1").
WithTopology(builder.ClusterTopology().
WithClass("foo").
WithVersion("v2.2.3").
Build()).
Build(),
in: builder.Cluster("fooboo", "cluster1").
WithTopology(builder.ClusterTopology().
WithClass("foo").
WithVersion("v1.2.3").
Build()).
Build(),
},
{
name: "should return error when downgrading topology version - minor",
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.1.3").
Build()).
Build(),
},
{
name: "should return error when downgrading topology version - patch",
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.2.2").
Build()).
Build(),
},
{
name: "should return error when downgrading topology version - pre-release",
expectErr: true,
old: builder.Cluster("fooboo", "cluster1").
WithTopology(builder.ClusterTopology().
WithClass("foo").
WithVersion("v1.2.3-xyz.2").
Build()).
Build(),
in: builder.Cluster("fooboo", "cluster1").
WithTopology(builder.ClusterTopology().
WithClass("foo").
WithVersion("v1.2.3-xyz.1").
Build()).
Build(),
},
{
name: "should return error when downgrading topology version - build tag",
expectErr: true,
old: builder.Cluster("fooboo", "cluster1").
WithTopology(builder.ClusterTopology().
WithClass("foo").
WithVersion("v1.2.3+xyz.2").
Build()).
Build(),
in: builder.Cluster("fooboo", "cluster1").
WithTopology(builder.ClusterTopology().
WithClass("foo").
WithVersion("v1.2.3+xyz.1").
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,
in: builder.Cluster("fooboo", "cluster1").
WithTopology(builder.ClusterTopology().
WithClass("foo").
WithVersion("v1.19.1").
WithMachineDeployment(
builder.MachineDeploymentTopology("workers1").
WithClass("aa").
Build()).
WithMachineDeployment(
builder.MachineDeploymentTopology("workers1").
WithClass("bb").
Build()).
Build()).
Build(),
},
{
name: "should pass when MachineDeployments names in a Topology are unique",
expectErr: false,
in: builder.Cluster("fooboo", "cluster1").
WithTopology(builder.ClusterTopology().
WithClass("foo").
WithVersion("v1.19.1").
WithMachineDeployment(
builder.MachineDeploymentTopology("workers1").
WithClass("aa").
Build()).
WithMachineDeployment(
builder.MachineDeploymentTopology("workers2").
WithClass("bb").
Build()).
Build()).
Build(),
},
{
name: "should update",
name: "should update if cluster is fully upgraded and up to date",
expectErr: false,
old: builder.Cluster("fooboo", "cluster1").
WithControlPlane(builder.ControlPlane("fooboo", "cluster1-cp").
WithStatusFields(map[string]interface{}{"status": map[string]interface{}{"version": "v1.19.1"}}).
Build()).
WithTopology(builder.ClusterTopology().
WithClass("foo").
WithVersion("v1.19.1").
WithMachineDeployment(
builder.MachineDeploymentTopology("workers1").
WithClass("aa").
Build()).
WithMachineDeployment(
builder.MachineDeploymentTopology("workers2").
WithClass("bb").
Build()).
Build()).
Build(),
in: builder.Cluster("fooboo", "cluster1").
WithTopology(builder.ClusterTopology().
WithClass("foo").
WithVersion("v1.19.2").
WithMachineDeployment(
builder.MachineDeploymentTopology("workers1").
WithMachinePool(
builder.MachinePoolTopology("pool1").
WithClass("aa").
Build()).
WithMachineDeployment(
builder.MachineDeploymentTopology("workers2").
WithClass("bb").
Build()).
Build()).
Build(),
},
{
name: "should return error when upgrade concurrency annotation value is < 1",
expectErr: true,
in: builder.Cluster("fooboo", "cluster1").
WithAnnotations(map[string]string{
clusterv1.ClusterTopologyUpgradeConcurrencyAnnotation: "-1",
}).
WithTopology(builder.ClusterTopology().
WithClass("foo").
WithVersion("v1.19.2").
WithVersion("v1.20.2").
Build()).
Build(),
additionalObjects: []client.Object{
builder.ControlPlane("fooboo", "cluster1-cp").WithVersion("v1.19.1").Build(),
builder.MachineDeployment("fooboo", "cluster1-workers1").WithLabels(map[string]string{
clusterv1.ClusterNameLabel: "cluster1",
clusterv1.ClusterTopologyOwnedLabel: "",
clusterv1.ClusterTopologyMachineDeploymentNameLabel: "workers1",
}).WithVersion("v1.19.1").Build(),
builder.MachinePool("fooboo", "cluster1-pool1").WithLabels(map[string]string{
clusterv1.ClusterNameLabel: "cluster1",
clusterv1.ClusterTopologyOwnedLabel: "",
clusterv1.ClusterTopologyMachinePoolNameLabel: "pool1",
}).WithVersion("v1.19.1").Build(),
},
},
{
name: "should return error when upgrade concurrency annotation value is not numeric",
name: "should block update if cluster kcp is not yet provisioned",
expectErr: true,
in: builder.Cluster("fooboo", "cluster1").
WithAnnotations(map[string]string{
clusterv1.ClusterTopologyUpgradeConcurrencyAnnotation: "abc",
}).
WithTopology(builder.ClusterTopology().
WithClass("foo").
WithVersion("v1.19.2").
Build()).
Build(),
},
{
name: "should pass upgrade concurrency annotation value is >= 1",
expectErr: false,
in: builder.Cluster("fooboo", "cluster1").
WithAnnotations(map[string]string{
clusterv1.ClusterTopologyUpgradeConcurrencyAnnotation: "2",
}).
WithTopology(builder.ClusterTopology().
WithClass("foo").
WithVersion("v1.19.2").
Build()).
Build(),
},
{
name: "should update if cluster is fully upgraded and up to date",
expectErr: false,
old: builder.Cluster("fooboo", "cluster1").
WithControlPlane(builder.ControlPlane("fooboo", "cluster1-cp").Build()).
WithTopology(builder.ClusterTopology().
WithClass("foo").
WithVersion("v1.19.1").
WithMachineDeployment(
builder.MachineDeploymentTopology("workers1").
WithClass("aa").
Build()).
WithMachinePool(
builder.MachinePoolTopology("pool1").
WithClass("aa").
Build()).
Build()).
Build(),
in: builder.Cluster("fooboo", "cluster1").
Expand All @@ -1498,24 +1311,16 @@ func TestClusterTopologyValidation(t *testing.T) {
Build()).
Build(),
additionalObjects: []client.Object{
builder.ControlPlane("fooboo", "cluster1-cp").WithVersion("v1.19.1").Build(),
builder.MachineDeployment("fooboo", "cluster1-workers1").WithLabels(map[string]string{
clusterv1.ClusterNameLabel: "cluster1",
clusterv1.ClusterTopologyOwnedLabel: "",
clusterv1.ClusterTopologyMachineDeploymentNameLabel: "workers1",
}).WithVersion("v1.19.1").Build(),
builder.MachinePool("fooboo", "cluster1-pool1").WithLabels(map[string]string{
clusterv1.ClusterNameLabel: "cluster1",
clusterv1.ClusterTopologyOwnedLabel: "",
clusterv1.ClusterTopologyMachinePoolNameLabel: "pool1",
}).WithVersion("v1.19.1").Build(),
builder.ControlPlane("fooboo", "cluster1-cp").WithVersion("v1.18.1").Build(),
},
},
{
name: "should block update if cluster kcp is not yet upgraded",
expectErr: true,
old: builder.Cluster("fooboo", "cluster1").
WithControlPlane(builder.ControlPlane("fooboo", "cluster1-cp").Build()).
WithControlPlane(builder.ControlPlane("fooboo", "cluster1-cp").
WithStatusFields(map[string]interface{}{"status": map[string]interface{}{"version": "v1.19.1"}}).
Build()).
WithTopology(builder.ClusterTopology().
WithClass("foo").
WithVersion("v1.19.1").
Expand All @@ -1535,7 +1340,9 @@ func TestClusterTopologyValidation(t *testing.T) {
name: "should block update if md is not yet upgraded",
expectErr: true,
old: builder.Cluster("fooboo", "cluster1").
WithControlPlane(builder.ControlPlane("fooboo", "cluster1-cp").Build()).
WithControlPlane(builder.ControlPlane("fooboo", "cluster1-cp").
WithStatusFields(map[string]interface{}{"status": map[string]interface{}{"version": "v1.19.1"}}).
Build()).
WithTopology(builder.ClusterTopology().
WithClass("foo").
WithVersion("v1.19.1").
Expand Down Expand Up @@ -1564,7 +1371,9 @@ func TestClusterTopologyValidation(t *testing.T) {
name: "should block update if machine of md is not yet upgraded",
expectErr: true,
old: builder.Cluster("fooboo", "cluster1").
WithControlPlane(builder.ControlPlane("fooboo", "cluster1-cp").Build()).
WithControlPlane(builder.ControlPlane("fooboo", "cluster1-cp").
WithStatusFields(map[string]interface{}{"status": map[string]interface{}{"version": "v1.19.1"}}).
Build()).
WithTopology(builder.ClusterTopology().
WithClass("foo").
WithVersion("v1.19.1").
Expand Down Expand Up @@ -1599,7 +1408,9 @@ func TestClusterTopologyValidation(t *testing.T) {
name: "should block update if mp is not yet upgraded",
expectErr: true,
old: builder.Cluster("fooboo", "cluster1").
WithControlPlane(builder.ControlPlane("fooboo", "cluster1-cp").Build()).
WithControlPlane(builder.ControlPlane("fooboo", "cluster1-cp").
WithStatusFields(map[string]interface{}{"status": map[string]interface{}{"version": "v1.19.1"}}).
Build()).
WithTopology(builder.ClusterTopology().
WithClass("foo").
WithVersion("v1.19.1").
Expand Down Expand Up @@ -1628,7 +1439,9 @@ func TestClusterTopologyValidation(t *testing.T) {
name: "should block update if node of mp is not yet upgraded",
expectErr: true,
old: builder.Cluster("fooboo", "cluster1").
WithControlPlane(builder.ControlPlane("fooboo", "cluster1-cp").Build()).
WithControlPlane(builder.ControlPlane("fooboo", "cluster1-cp").
WithStatusFields(map[string]interface{}{"status": map[string]interface{}{"version": "v1.19.1"}}).
Build()).
WithTopology(builder.ClusterTopology().
WithClass("foo").
WithVersion("v1.19.1").
Expand Down

0 comments on commit bdf09a2

Please sign in to comment.