Skip to content

Commit 62a2dba

Browse files
committed
fixup! test(e2e): Use long cluster names
1 parent faac093 commit 62a2dba

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

test/e2e/clusterautoscaler_helpers.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ func WaitForClusterAutoscalerToBeReadyForWorkloadCluster(
8585
Deployment: &appsv1.Deployment{
8686
ObjectMeta: metav1.ObjectMeta{
8787
Name: fmt.Sprintf(
88-
"%s-%s",
89-
clusterAutoscalerReleaseName,
88+
"cluster-autoscaler-%s",
9089
input.WorkloadCluster.Name,
9190
),
9291
Namespace: input.WorkloadCluster.Namespace,

test/e2e/framework/self_hosted.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
corev1 "k8s.io/api/core/v1"
1919
"k8s.io/apimachinery/pkg/runtime/schema"
2020
"k8s.io/klog/v2"
21+
"k8s.io/utils/ptr"
2122
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2223
clusterctlv1 "sigs.k8s.io/cluster-api/cmd/clusterctl/api/v1alpha3"
2324
capie2e "sigs.k8s.io/cluster-api/test/e2e"
@@ -38,6 +39,10 @@ type SelfHostedSpecInput struct {
3839
ControlPlaneWaiters clusterctl.ControlPlaneWaiters
3940
Flavor string
4041

42+
// Cluster name allows to specify a deterministic clusterName.
43+
// If not set, a random one will be generated.
44+
ClusterName *string
45+
4146
// InfrastructureProviders specifies the infrastructure to use for clusterctl
4247
// operations (Example: get cluster templates).
4348
// Note: In most cases this need not be specified. It only needs to be specified when
@@ -109,6 +114,10 @@ func SelfHostedSpec(ctx context.Context, inputGetter func() SelfHostedSpecInput)
109114
Succeed(),
110115
"Invalid argument. input.ArtifactFolder can't be created for %s spec", specName,
111116
)
117+
Expect(len(ptr.Deref(input.ClusterName, ""))).To(
118+
BeNumerically("<=", 63),
119+
"Invalid argument. input.ClusterName %q can't be longer than 63 characters", input.ClusterName,
120+
)
112121

113122
// Use KubernetesVersion if no upgrade step is defined by test input.
114123
Expect(input.E2EConfig.Variables).To(HaveKey(capie2e.KubernetesVersion))
@@ -140,6 +149,10 @@ func SelfHostedSpec(ctx context.Context, inputGetter func() SelfHostedSpecInput)
140149
By("Creating a workload cluster")
141150

142151
workloadClusterName := fmt.Sprintf("%s-%s", specName, util.RandomString(6))
152+
if input.ClusterName != nil {
153+
workloadClusterName = *input.ClusterName
154+
}
155+
143156
clusterctlVariables := map[string]string{}
144157

145158
// In case the infrastructure-docker provider is installed, ensure to add the preload images variable to load the

test/e2e/quick_start_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
capie2e "sigs.k8s.io/cluster-api/test/e2e"
2121
capiframework "sigs.k8s.io/cluster-api/test/framework"
2222
"sigs.k8s.io/cluster-api/test/framework/clusterctl"
23+
"sigs.k8s.io/cluster-api/util"
2324

2425
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
2526
apivariables "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/variables"
@@ -129,7 +130,30 @@ var _ = Describe("Quick start", func() {
129130
))
130131
}
131132

133+
clusterNamePrefix := "quick-start-"
134+
// To be able to test the self-hosted cluster with long name, we need to set the
135+
// maxClusterNameength to 63 which is the maximum length of a cluster name.
136+
maxClusterNameLength := 63
137+
// However, if the provider is Docker, we need to reduce the maxClusterNameLength
138+
// because CAPI adds multiple random suffixes to the cluster name which are used in
139+
// Docker cluster, and then in MachineDeployment, and finally in the machine names,
140+
// resulting in 23 extra characters added to the cluster name for the actual worker node
141+
// machine names. These machine names are used for Docker container names. The Docker
142+
// image used by KinD have a maximum hostname length of 64 characters. This can be
143+
// determined by running `getconf HOST_NAME_MAX` in a Docker container and is different
144+
// from the host which generally allows 255 characters nowadays.
145+
// Any longer than this prevents the container from starting, returning an error such
146+
// as `error during container init: sethostname: invalid argument: unknown`.
147+
// Therefore we reduce the maximum cluster to 64 (max hostname length) - 23 (random suffixes).
148+
if lowercaseProvider == "docker" {
149+
maxClusterNameLength = 64 - 23
150+
}
151+
132152
return capie2e.QuickStartSpecInput{
153+
ClusterName: ptr.To(clusterNamePrefix +
154+
util.RandomString(
155+
maxClusterNameLength-len(clusterNamePrefix),
156+
)),
133157
E2EConfig: testE2EConfig,
134158
ClusterctlConfigPath: clusterLocalClusterctlConfigPath,
135159
BootstrapClusterProxy: bootstrapClusterProxy,

test/e2e/self_hosted_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"k8s.io/utils/ptr"
1515
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
1616
capiframework "sigs.k8s.io/cluster-api/test/framework"
17+
"sigs.k8s.io/cluster-api/util"
1718

1819
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
1920
apivariables "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/variables"
@@ -57,6 +58,25 @@ var _ = Describe("Self-hosted", Serial, func() {
5758
framework.SelfHostedSpec(
5859
ctx,
5960
func() framework.SelfHostedSpecInput {
61+
clusterNamePrefix := "self-hosted-"
62+
// To be able to test the self-hosted cluster with long name, we need to set the
63+
// maxClusterNameLength to 63 which is the maximum length of a cluster name.
64+
maxClusterNameLength := 63
65+
// However, if the provider is Docker, we need to reduce the maxClusterNameLength
66+
// because CAPI adds multiple random suffixes to the cluster name which are used in
67+
// Docker cluster, and then in MachineDeployment, and finally in the machine names,
68+
// resulting in 23 extra characters added to the cluster name for the actual worker node
69+
// machine names. These machine names are used for Docker container names. The Docker
70+
// image used by KinD have a maximum hostname length of 64 characters. This can be
71+
// determined by running `getconf HOST_NAME_MAX` in a Docker container and is different
72+
// from the host which generally allows 255 characters nowadays.
73+
// Any longer than this prevents the container from starting, returning an error such
74+
// as `error during container init: sethostname: invalid argument: unknown`.
75+
// Therefore we reduce the maximum cluster to 64 (max hostname length) - 23 (random suffixes).
76+
if lowercaseProvider == "docker" {
77+
maxClusterNameLength = 64 - 23
78+
}
79+
6080
return framework.SelfHostedSpecInput{
6181
E2EConfig: e2eConfig,
6282
ClusterctlConfigPath: clusterctlConfigPath,
@@ -65,6 +85,10 @@ var _ = Describe("Self-hosted", Serial, func() {
6585
SkipCleanup: skipCleanup,
6686
Flavor: flavour,
6787
InfrastructureProvider: ptr.To(lowercaseProvider),
88+
ClusterName: ptr.To(clusterNamePrefix +
89+
util.RandomString(
90+
maxClusterNameLength-len(clusterNamePrefix),
91+
)),
6892
PostClusterMoved: func(proxy capiframework.ClusterProxy, cluster *clusterv1.Cluster) {
6993
By(
7094
"Waiting for all requested addons to be ready in workload cluster",

0 commit comments

Comments
 (0)