Skip to content

Commit 338a058

Browse files
committed
fixup! Add tests that fail when a worker topology name causes invalid Kubernetes resource name
Add tests to check package
1 parent a686606 commit 338a058

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed

internal/topology/check/compatibility_test.go

+120
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,66 @@ func TestMachineDeploymentTopologiesAreUniqueAndDefinedInClusterClass(t *testing
14021402
Build(),
14031403
wantErr: true,
14041404
},
1405+
{
1406+
name: "fail if MachineDeploymentTopology name is not a valid Kubernetes resource name",
1407+
clusterClass: builder.ClusterClass(metav1.NamespaceDefault, "class1").
1408+
WithInfrastructureClusterTemplate(
1409+
builder.InfrastructureClusterTemplate(metav1.NamespaceDefault, "infra1").Build()).
1410+
WithControlPlaneTemplate(
1411+
builder.ControlPlane(metav1.NamespaceDefault, "cp1").Build()).
1412+
WithControlPlaneInfrastructureMachineTemplate(
1413+
builder.InfrastructureMachineTemplate(metav1.NamespaceDefault, "cpinfra1").Build()).
1414+
WithWorkerMachineDeploymentClasses(
1415+
*builder.MachineDeploymentClass("aa").
1416+
WithInfrastructureTemplate(
1417+
builder.InfrastructureMachineTemplate(metav1.NamespaceDefault, "infra1").Build()).
1418+
WithBootstrapTemplate(
1419+
builder.BootstrapTemplate(metav1.NamespaceDefault, "bootstrap1").Build()).
1420+
Build()).
1421+
Build(),
1422+
cluster: builder.Cluster(metav1.NamespaceDefault, "cluster1").
1423+
WithTopology(
1424+
builder.ClusterTopology().
1425+
WithClass("class1").
1426+
WithVersion("v1.22.2").
1427+
WithMachineDeployment(
1428+
builder.MachineDeploymentTopology("under_score").
1429+
WithClass("aa").
1430+
Build()).
1431+
Build()).
1432+
Build(),
1433+
wantErr: true,
1434+
},
1435+
{
1436+
name: "fail if MachineDeploymentTopology name is not a valid Kubernetes label value",
1437+
clusterClass: builder.ClusterClass(metav1.NamespaceDefault, "class1").
1438+
WithInfrastructureClusterTemplate(
1439+
builder.InfrastructureClusterTemplate(metav1.NamespaceDefault, "infra1").Build()).
1440+
WithControlPlaneTemplate(
1441+
builder.ControlPlane(metav1.NamespaceDefault, "cp1").Build()).
1442+
WithControlPlaneInfrastructureMachineTemplate(
1443+
builder.InfrastructureMachineTemplate(metav1.NamespaceDefault, "cpinfra1").Build()).
1444+
WithWorkerMachineDeploymentClasses(
1445+
*builder.MachineDeploymentClass("aa").
1446+
WithInfrastructureTemplate(
1447+
builder.InfrastructureMachineTemplate(metav1.NamespaceDefault, "infra1").Build()).
1448+
WithBootstrapTemplate(
1449+
builder.BootstrapTemplate(metav1.NamespaceDefault, "bootstrap1").Build()).
1450+
Build()).
1451+
Build(),
1452+
cluster: builder.Cluster(metav1.NamespaceDefault, "cluster1").
1453+
WithTopology(
1454+
builder.ClusterTopology().
1455+
WithClass("class1").
1456+
WithVersion("v1.22.2").
1457+
WithMachineDeployment(
1458+
builder.MachineDeploymentTopology("forward/slash").
1459+
WithClass("aa").
1460+
Build()).
1461+
Build()).
1462+
Build(),
1463+
wantErr: true,
1464+
},
14051465
}
14061466
for _, tt := range tests {
14071467
t.Run(tt.name, func(t *testing.T) {
@@ -1609,6 +1669,66 @@ func TestMachinePoolTopologiesAreUniqueAndDefinedInClusterClass(t *testing.T) {
16091669
Build(),
16101670
wantErr: true,
16111671
},
1672+
{
1673+
name: "fail if MachinePoolTopology name is not a valid Kubernetes resource name",
1674+
clusterClass: builder.ClusterClass(metav1.NamespaceDefault, "class1").
1675+
WithInfrastructureClusterTemplate(
1676+
builder.InfrastructureClusterTemplate(metav1.NamespaceDefault, "infra1").Build()).
1677+
WithControlPlaneTemplate(
1678+
builder.ControlPlane(metav1.NamespaceDefault, "cp1").Build()).
1679+
WithControlPlaneInfrastructureMachineTemplate(
1680+
builder.InfrastructureMachinePoolTemplate(metav1.NamespaceDefault, "cpinfra1").Build()).
1681+
WithWorkerMachinePoolClasses(
1682+
*builder.MachinePoolClass("aa").
1683+
WithInfrastructureTemplate(
1684+
builder.InfrastructureMachinePoolTemplate(metav1.NamespaceDefault, "infra1").Build()).
1685+
WithBootstrapTemplate(
1686+
builder.BootstrapTemplate(metav1.NamespaceDefault, "bootstrap1").Build()).
1687+
Build()).
1688+
Build(),
1689+
cluster: builder.Cluster(metav1.NamespaceDefault, "cluster1").
1690+
WithTopology(
1691+
builder.ClusterTopology().
1692+
WithClass("class1").
1693+
WithVersion("v1.22.2").
1694+
WithMachinePool(
1695+
builder.MachinePoolTopology("under_score").
1696+
WithClass("aa").
1697+
Build()).
1698+
Build()).
1699+
Build(),
1700+
wantErr: true,
1701+
},
1702+
{
1703+
name: "fail if MachinePoolTopology name is not a valid Kubernetes label value",
1704+
clusterClass: builder.ClusterClass(metav1.NamespaceDefault, "class1").
1705+
WithInfrastructureClusterTemplate(
1706+
builder.InfrastructureClusterTemplate(metav1.NamespaceDefault, "infra1").Build()).
1707+
WithControlPlaneTemplate(
1708+
builder.ControlPlane(metav1.NamespaceDefault, "cp1").Build()).
1709+
WithControlPlaneInfrastructureMachineTemplate(
1710+
builder.InfrastructureMachinePoolTemplate(metav1.NamespaceDefault, "cpinfra1").Build()).
1711+
WithWorkerMachinePoolClasses(
1712+
*builder.MachinePoolClass("aa").
1713+
WithInfrastructureTemplate(
1714+
builder.InfrastructureMachinePoolTemplate(metav1.NamespaceDefault, "infra1").Build()).
1715+
WithBootstrapTemplate(
1716+
builder.BootstrapTemplate(metav1.NamespaceDefault, "bootstrap1").Build()).
1717+
Build()).
1718+
Build(),
1719+
cluster: builder.Cluster(metav1.NamespaceDefault, "cluster1").
1720+
WithTopology(
1721+
builder.ClusterTopology().
1722+
WithClass("class1").
1723+
WithVersion("v1.22.2").
1724+
WithMachinePool(
1725+
builder.MachinePoolTopology("forward/slash").
1726+
WithClass("aa").
1727+
Build()).
1728+
Build()).
1729+
Build(),
1730+
wantErr: true,
1731+
},
16121732
}
16131733
for _, tt := range tests {
16141734
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)