Skip to content

Commit ac77773

Browse files
committed
e2e: adds flavor and e2e test for nodeadm clusterclass
1 parent fd62f07 commit ac77773

File tree

8 files changed

+288
-1
lines changed

8 files changed

+288
-1
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ endif
188188
# infrastructure reconciliation
189189

190190
# Instead, you can run a quick smoke test, it should run fast (9 minutes)...
191-
# GINKGO_FOCUS := "\\[smoke\\]"
191+
GINKGO_FOCUS := "\\[nodeadm\\]"
192192
# For running CAPI e2e tests: GINKGO_FOCUS := "\\[Cluster API Framework\\]"
193193
# For running CAPI blocking e2e test: GINKGO_FOCUS := "\\[PR-Blocking\\]"
194194
ifdef GINKGO_FOCUS
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
apiVersion: cluster.x-k8s.io/v1beta1
2+
kind: ClusterClass
3+
metadata:
4+
name: ${CLUSTER_CLASS_NAME}
5+
spec:
6+
controlPlane:
7+
ref:
8+
apiVersion: controlplane.cluster.x-k8s.io/v1beta2
9+
kind: AWSManagedControlPlaneTemplate
10+
name: "${CLUSTER_CLASS_NAME}-control-plane"
11+
infrastructure:
12+
ref:
13+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
14+
kind: AWSManagedClusterTemplate
15+
name: "${CLUSTER_CLASS_NAME}"
16+
workers:
17+
machineDeployments:
18+
- class: default-worker
19+
template:
20+
bootstrap:
21+
ref:
22+
name: "${CLUSTER_CLASS_NAME}-md-0"
23+
apiVersion: bootstrap.cluster.x-k8s.io/v1beta2
24+
kind: EKSConfigTemplate
25+
infrastructure:
26+
ref:
27+
name: "${CLUSTER_CLASS_NAME}-md-0"
28+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
29+
kind: AWSMachineTemplate
30+
---
31+
kind: AWSManagedClusterTemplate
32+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
33+
metadata:
34+
name: "${CLUSTER_CLASS_NAME}"
35+
spec:
36+
template:
37+
spec: {}
38+
---
39+
kind: AWSManagedControlPlaneTemplate
40+
apiVersion: controlplane.cluster.x-k8s.io/v1beta2
41+
metadata:
42+
name: "${CLUSTER_CLASS_NAME}-control-plane"
43+
spec:
44+
template:
45+
spec:
46+
region: "${AWS_REGION}"
47+
sshKeyName: "${AWS_SSH_KEY_NAME}"
48+
version: "${KUBERNETES_VERSION}"
49+
---
50+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
51+
kind: AWSMachineTemplate
52+
metadata:
53+
name: "${CLUSTER_CLASS_NAME}-md-0"
54+
spec:
55+
template:
56+
spec:
57+
ami:
58+
eksLookupType: AmazonLinux2023
59+
cloudInit:
60+
insecureSkipSecretsManager: true
61+
instanceType: "${AWS_NODE_MACHINE_TYPE}"
62+
iamInstanceProfile: "nodes.cluster-api-provider-aws.sigs.k8s.io"
63+
sshKeyName: "${AWS_SSH_KEY_NAME}"
64+
---
65+
apiVersion: bootstrap.cluster.x-k8s.io/v1beta2
66+
kind: NodeadmConfigTemplate
67+
metadata:
68+
name: "${CLUSTER_CLASS_NAME}-md-0"
69+
spec:
70+
template: {}

test/e2e/data/e2e_eks_conf.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ providers:
124124
targetName: "cluster-template-eks-auth-bootstrap-disabled.yaml"
125125
- sourcePath: "./infrastructure-aws/withclusterclass/kustomize_sources/eks-clusterclass/clusterclass-eks-e2e.yaml"
126126
- sourcePath: "./infrastructure-aws/withclusterclass/generated/cluster-template-eks-clusterclass.yaml"
127+
- sourcePath: "./infrastructure-aws/withclusterclass/kustomize_sources/eks-nodeadm-clusterclass/clusterclass-eks-nodeadm-clusterclass.yaml"
128+
- sourcePath: "./infrastructure-aws/withclusterclass/generated/cluster-template-eks-nodeadm-clusterclass.yaml"
127129

128130
variables:
129131
KUBERNETES_VERSION: "v1.32.0"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: cluster.x-k8s.io/v1beta1
2+
kind: Cluster
3+
metadata:
4+
name: "${CLUSTER_NAME}"
5+
spec:
6+
clusterNetwork:
7+
pods:
8+
cidrBlocks:
9+
- 192.168.0.0/16
10+
topology:
11+
class: eks-nodeadm-e2e
12+
version: "${KUBERNETES_VERSION}"
13+
workers:
14+
machineDeployments:
15+
- class: default-worker
16+
name: md-0
17+
replicas: ${WORKER_MACHINE_COUNT}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
apiVersion: cluster.x-k8s.io/v1beta1
2+
kind: ClusterClass
3+
metadata:
4+
name: eks-nodeadm-e2e
5+
spec:
6+
controlPlane:
7+
ref:
8+
apiVersion: controlplane.cluster.x-k8s.io/v1beta2
9+
kind: AWSManagedControlPlaneTemplate
10+
name: "${CLUSTER_NAME}-control-plane"
11+
infrastructure:
12+
ref:
13+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
14+
kind: AWSManagedClusterTemplate
15+
name: "${CLUSTER_NAME}"
16+
workers:
17+
machineDeployments:
18+
- class: default-worker
19+
template:
20+
bootstrap:
21+
ref:
22+
name: "${CLUSTER_NAME}-md-0"
23+
apiVersion: bootstrap.cluster.x-k8s.io/v1beta2
24+
kind: NodeadmConfigTemplate
25+
infrastructure:
26+
ref:
27+
name: "${CLUSTER_NAME}-md-0"
28+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
29+
kind: AWSMachineTemplate
30+
---
31+
kind: AWSManagedClusterTemplate
32+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
33+
metadata:
34+
name: "${CLUSTER_NAME}"
35+
spec:
36+
template:
37+
spec: {}
38+
---
39+
kind: AWSManagedControlPlaneTemplate
40+
apiVersion: controlplane.cluster.x-k8s.io/v1beta2
41+
metadata:
42+
name: "${CLUSTER_NAME}-control-plane"
43+
spec:
44+
template:
45+
spec:
46+
region: "${AWS_REGION}"
47+
sshKeyName: "${AWS_SSH_KEY_NAME}"
48+
version: "${KUBERNETES_VERSION}"
49+
---
50+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
51+
kind: AWSMachineTemplate
52+
metadata:
53+
name: "${CLUSTER_NAME}-md-0"
54+
spec:
55+
template:
56+
spec:
57+
ami:
58+
eksLookupType: AmazonLinux2023
59+
cloudInit:
60+
insecureSkipSecretsManager: true
61+
instanceType: "${AWS_NODE_MACHINE_TYPE}"
62+
iamInstanceProfile: "nodes.cluster-api-provider-aws.sigs.k8s.io"
63+
sshKeyName: "${AWS_SSH_KEY_NAME}"
64+
---
65+
apiVersion: bootstrap.cluster.x-k8s.io/v1beta2
66+
kind: NodeadmConfigTemplate
67+
metadata:
68+
name: "${CLUSTER_NAME}-md-0"
69+
spec:
70+
template: {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
resources:
2+
- cluster-template.yaml
3+
generatorOptions:
4+
disableNameSuffixHash: true
5+
labels:
6+
type: generated
7+
annotations:
8+
note: generated
9+
10+
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
//go:build e2e
2+
// +build e2e
3+
4+
/*
5+
Copyright 2025 The Kubernetes Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
*/
19+
20+
package managed
21+
22+
import (
23+
"context"
24+
"fmt"
25+
26+
"github.com/onsi/ginkgo/v2"
27+
. "github.com/onsi/gomega"
28+
corev1 "k8s.io/api/core/v1"
29+
crclient "sigs.k8s.io/controller-runtime/pkg/client"
30+
31+
infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
32+
ekscontrolplanev1 "sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/eks/api/v1beta2"
33+
"sigs.k8s.io/cluster-api-provider-aws/v2/test/e2e/shared"
34+
"sigs.k8s.io/cluster-api/test/framework"
35+
"sigs.k8s.io/cluster-api/util"
36+
)
37+
38+
// Validates the eks-nodeadm-clusterclass flavor provisions a cluster with Nodeadm bootstrap and expected machine template settings.
39+
var _ = ginkgo.Describe("[managed] [general] EKS nodeadm ClusterClass tests", func() {
40+
var (
41+
namespace *corev1.Namespace
42+
ctx context.Context
43+
specName = "eks-nodeadm-clusterclass"
44+
clusterName string
45+
)
46+
47+
shared.ConditionalIt(runGeneralTests, "should create a cluster using Nodeadm ClusterClass and validate configuration", func() {
48+
ginkgo.By("should have a valid test configuration")
49+
Expect(e2eCtx.Environment.BootstrapClusterProxy).ToNot(BeNil(), "BootstrapClusterProxy can't be nil")
50+
Expect(e2eCtx.E2EConfig).ToNot(BeNil(), "E2EConfig can't be nil")
51+
Expect(e2eCtx.E2EConfig.Variables).To(HaveKey(shared.KubernetesVersion))
52+
53+
ctx = context.TODO()
54+
namespace = shared.SetupSpecNamespace(ctx, specName, e2eCtx)
55+
clusterName = fmt.Sprintf("%s-%s", specName, util.RandomString(6))
56+
eksClusterName := getEKSClusterName(namespace.Name, clusterName)
57+
58+
ginkgo.By("default iam role should exist")
59+
VerifyRoleExistsAndOwned(ctx, ekscontrolplanev1.DefaultEKSControlPlaneRole, eksClusterName, false, e2eCtx.AWSSession)
60+
61+
ginkgo.By("should create a cluster from the nodeadm ClusterClass flavor")
62+
ManagedClusterSpec(ctx, func() ManagedClusterSpecInput {
63+
return ManagedClusterSpecInput{
64+
E2EConfig: e2eCtx.E2EConfig,
65+
ConfigClusterFn: defaultConfigCluster,
66+
BootstrapClusterProxy: e2eCtx.Environment.BootstrapClusterProxy,
67+
AWSSession: e2eCtx.BootstrapUserAWSSession,
68+
Namespace: namespace,
69+
ClusterName: clusterName,
70+
Flavour: EKSNodeadmClusterClassFlavor,
71+
ControlPlaneMachineCount: 1, // required by clusterctl
72+
WorkerMachineCount: 1,
73+
}
74+
})
75+
76+
ginkgo.By("validating the MachineDeployment uses Nodeadm bootstrap and AWSMachineTemplate settings")
77+
cluster := framework.GetClusterByName(ctx, framework.GetClusterByNameInput{
78+
Getter: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
79+
Namespace: namespace.Name,
80+
Name: clusterName,
81+
})
82+
Expect(cluster).NotTo(BeNil(), "cluster should exist")
83+
84+
mds := framework.DiscoveryAndWaitForMachineDeployments(ctx, framework.DiscoveryAndWaitForMachineDeploymentsInput{
85+
Lister: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
86+
Cluster: cluster,
87+
}, e2eCtx.E2EConfig.GetIntervals("", "wait-worker-nodes")...)
88+
Expect(mds).ToNot(BeEmpty(), "expected at least one MachineDeployment")
89+
md := mds[0]
90+
91+
Expect(md.Spec.Template.Spec.Bootstrap.ConfigRef).ToNot(BeNil(), "bootstrap config ref must be set")
92+
Expect(md.Spec.Template.Spec.Bootstrap.ConfigRef.Kind).To(Equal("NodeadmConfigTemplate"), "bootstrap config kind should be NodeadmConfigTemplate")
93+
94+
Expect(md.Spec.Template.Spec.InfrastructureRef.Kind).To(Equal("AWSMachineTemplate"), "infrastructure ref should be AWSMachineTemplate")
95+
awsMT := &infrav1.AWSMachineTemplate{}
96+
Expect(e2eCtx.Environment.BootstrapClusterProxy.GetClient().Get(ctx, crclient.ObjectKey{
97+
Namespace: namespace.Name,
98+
Name: md.Spec.Template.Spec.InfrastructureRef.Name,
99+
}, awsMT)).To(Succeed(), "expected to fetch AWSMachineTemplate")
100+
101+
Expect(awsMT.Spec.Template.Spec.CloudInit.InsecureSkipSecretsManager).To(BeTrue(), "cloudInit.insecureSkipSecretsManager should be true")
102+
Expect(awsMT.Spec.Template.Spec.AMI.EKSOptimizedLookupType).ToNot(BeNil(), "AMI.EKSOptimizedLookupType should be set")
103+
Expect(*awsMT.Spec.Template.Spec.AMI.EKSOptimizedLookupType).To(Equal(infrav1.AmazonLinux2023), "AMI lookup type should be AmazonLinux2023")
104+
105+
ginkgo.By("deleting the cluster")
106+
framework.DeleteCluster(ctx, framework.DeleteClusterInput{
107+
Deleter: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
108+
Cluster: cluster,
109+
})
110+
framework.WaitForClusterDeleted(ctx, framework.WaitForClusterDeletedInput{
111+
ClusterProxy: e2eCtx.Environment.BootstrapClusterProxy,
112+
Cluster: cluster,
113+
ClusterctlConfigPath: e2eCtx.Environment.ClusterctlConfigPath,
114+
ArtifactFolder: e2eCtx.Settings.ArtifactFolder,
115+
}, e2eCtx.E2EConfig.GetIntervals("", "wait-delete-cluster")...)
116+
})
117+
})

test/e2e/suites/managed/helpers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const (
5353
EKSClusterClassFlavor = "eks-clusterclass"
5454
EKSAuthAPIAndConfigMapFlavor = "eks-auth-api-and-config-map"
5555
EKSAuthBootstrapDisabledFlavor = "eks-auth-bootstrap-disabled"
56+
EKSNodeadmClusterClassFlavor = "eks-nodeadm-clusterclass"
5657
)
5758

5859
const (

0 commit comments

Comments
 (0)