Skip to content

Commit 6be808c

Browse files
committed
Add EKS ClusterClass example and replace EKS Cluster e2e test with ClusterClass
Signed-off-by: Parthvi Vala <[email protected]>
1 parent a1e5677 commit 6be808c

File tree

5 files changed

+212
-81
lines changed

5 files changed

+212
-81
lines changed
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
apiVersion: cluster.x-k8s.io/v1beta1
2+
kind: ClusterClass
3+
metadata:
4+
name: aws-eks-example
5+
spec:
6+
controlPlane:
7+
ref:
8+
apiVersion: controlplane.cluster.x-k8s.io/v1beta2
9+
kind: AWSManagedControlPlaneTemplate
10+
name: "eks-control-plane"
11+
infrastructure:
12+
ref:
13+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
14+
kind: AWSManagedClusterTemplate
15+
name: "eks-cluster"
16+
workers:
17+
machineDeployments:
18+
- class: default-worker
19+
template:
20+
bootstrap:
21+
ref:
22+
name: "eks-md-0"
23+
apiVersion: bootstrap.cluster.x-k8s.io/v1beta2
24+
kind: EKSConfigTemplate
25+
infrastructure:
26+
ref:
27+
name: "eks-md-0"
28+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
29+
kind: AWSMachineTemplate
30+
variables:
31+
- name: region
32+
required: true
33+
schema:
34+
openAPIV3Schema:
35+
description: "The AWS region where the Cluster will be created"
36+
type: string
37+
- name: sshKeyName
38+
required: false
39+
schema:
40+
openAPIV3Schema:
41+
description: "AWS SSH key name to use"
42+
type: string
43+
default: ''
44+
- name: instanceType
45+
required: false
46+
schema:
47+
openAPIV3Schema:
48+
description: "AWS instance type to use"
49+
type: string
50+
default: "t3.xlarge"
51+
- name: eksClusterName
52+
required: false
53+
schema:
54+
openAPIV3Schema:
55+
description: "EKS cluster name"
56+
type: string
57+
default: ''
58+
- name: awsClusterIdentityName
59+
required: true
60+
schema:
61+
openAPIV3Schema:
62+
description: The AWSClusterStaticIdentity resource name referencing the credentials to create the Cluster.
63+
type: string
64+
default: cluster-identity
65+
patches:
66+
- name: awsManagedControlPlaneTemplate
67+
definitions:
68+
- selector:
69+
apiVersion: controlplane.cluster.x-k8s.io/v1beta2
70+
kind: AWSManagedControlPlaneTemplate
71+
matchResources:
72+
controlPlane: true
73+
jsonPatches:
74+
- op: add
75+
enabledIf: '{{ ne .eksClusterName }}'
76+
path: /spec/template/spec/eksClusterName
77+
valueFrom:
78+
variable: eksClusterName
79+
- op: add
80+
path: /spec/template/spec/region
81+
valueFrom:
82+
variable: region
83+
- op: add
84+
enabledIf: '{{ ne .sshKeyName }}'
85+
path: /spec/template/spec/sshKeyName
86+
valueFrom:
87+
variable: sshKeyName
88+
- op: add
89+
path: /spec/template/spec/identityRef/name
90+
valueFrom:
91+
variable: awsClusterIdentityName
92+
# Builtins
93+
- op: add
94+
path: "/spec/template/spec/version"
95+
valueFrom:
96+
variable: builtin.cluster.topology.version
97+
- name: awsMachineTemplate
98+
definitions:
99+
- selector:
100+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
101+
kind: AWSMachineTemplate
102+
matchResources:
103+
machineDeploymentClass:
104+
names:
105+
- default-worker
106+
jsonPatches:
107+
- op: add
108+
enabledIf: '{{ ne .sshKeyName }}'
109+
path: /spec/template/spec/sshKeyName
110+
valueFrom:
111+
variable: sshKeyName
112+
- op: add
113+
path: /spec/template/spec/instanceType
114+
valueFrom:
115+
variable: instanceType
116+
---
117+
kind: AWSManagedClusterTemplate
118+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
119+
metadata:
120+
name: "eks-cluster"
121+
spec:
122+
template:
123+
spec: {}
124+
---
125+
kind: AWSManagedControlPlaneTemplate
126+
apiVersion: controlplane.cluster.x-k8s.io/v1beta2
127+
metadata:
128+
name: "eks-control-plane"
129+
spec:
130+
template:
131+
spec:
132+
region: "replaced_by_patch"
133+
version: "v0.0.0" # To be replaced by patch
134+
identityRef:
135+
kind: AWSClusterStaticIdentity
136+
name: cluster-identity
137+
---
138+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
139+
kind: AWSMachineTemplate
140+
metadata:
141+
name: "eks-md-0"
142+
spec:
143+
template:
144+
spec:
145+
instanceType: "replaced_by_patch"
146+
iamInstanceProfile: "nodes.cluster-api-provider-aws.sigs.k8s.io"
147+
---
148+
apiVersion: bootstrap.cluster.x-k8s.io/v1beta2
149+
kind: EKSConfigTemplate
150+
metadata:
151+
name: "eks-md-0"
152+
spec:
153+
template:
154+
spec: {}

test/e2e/const.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ var (
8787
//go:embed data/cluster-templates/docker-rke2-topology.yaml
8888
CAPIDockerRKE2Topology []byte
8989

90-
//go:embed data/cluster-templates/aws-eks-mmp.yaml
91-
CAPIAwsEKSMMP []byte
90+
//go:embed data/cluster-templates/aws-eks-topology.yaml
91+
CAPIAwsEKSTopology []byte
9292

9393
//go:embed data/cluster-templates/aws-ec2-rke2-topology.yaml
9494
CAPIAwsEC2RKE2Topology []byte

test/e2e/data/cluster-templates/aws-eks-mmp.yaml

Lines changed: 0 additions & 77 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
2+
kind: AWSClusterStaticIdentity
3+
metadata:
4+
name: cluster-identity
5+
spec:
6+
secretRef: cluster-identity
7+
allowedNamespaces: {}
8+
---
9+
apiVersion: cluster.x-k8s.io/v1beta1
10+
kind: Cluster
11+
metadata:
12+
name: ${CLUSTER_NAME}
13+
namespace: "${NAMESPACE}"
14+
labels:
15+
cluster-api.cattle.io/rancher-auto-import: "true"
16+
spec:
17+
clusterNetwork:
18+
pods:
19+
cidrBlocks:
20+
- 192.168.0.0/16
21+
topology:
22+
class: aws-eks-example
23+
classNamespace: ${TOPOLOGY_NAMESPACE}
24+
version: ${AWS_KUBERNETES_VERSION}
25+
variables:
26+
- name: region
27+
value: ${AWS_REGION}
28+
- name: sshKeyName
29+
value: ${AWS_SSH_KEY_NAME}
30+
- name: instanceType
31+
value: t3.xlarge
32+
- name: awsClusterIdentityName
33+
value: cluster-identity
34+
workers:
35+
machineDeployments:
36+
- class: default-worker
37+
name: md-0
38+
replicas: ${WORKER_MACHINE_COUNT}

test/e2e/suites/import-gitops/import_gitops_test.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,17 +261,21 @@ var _ = Describe("[Azure] [RKE2] Create and delete CAPI cluster from cluster cla
261261
})
262262
})
263263

264-
var _ = Describe("[AWS] [EKS] Create and delete CAPI cluster functionality should work with namespace auto-import", Label(e2e.FullTestLabel), func() {
264+
var _ = Describe("[AWS] [EKS] Create and delete CAPI cluster from cluster class", Label(e2e.FullTestLabel), func() {
265+
var topologyNamespace string
266+
265267
BeforeEach(func() {
266268
komega.SetClient(bootstrapClusterProxy.GetClient())
267269
komega.SetContext(ctx)
270+
271+
topologyNamespace = "creategitops-aws-eks"
268272
})
269273

270274
specs.CreateUsingGitOpsSpec(ctx, func() specs.CreateUsingGitOpsSpecInput {
271275
return specs.CreateUsingGitOpsSpecInput{
272276
E2EConfig: e2e.LoadE2EConfig(),
273277
BootstrapClusterProxy: bootstrapClusterProxy,
274-
ClusterTemplate: e2e.CAPIAwsEKSMMP,
278+
ClusterTemplate: e2e.CAPIAwsEKSTopology,
275279
ClusterName: "cluster-eks",
276280
ControlPlaneMachineCount: ptr.To(1),
277281
WorkerMachineCount: ptr.To(1),
@@ -282,6 +286,18 @@ var _ = Describe("[AWS] [EKS] Create and delete CAPI cluster functionality shoul
282286
CapiClusterOwnerLabel: e2e.CapiClusterOwnerLabel,
283287
CapiClusterOwnerNamespaceLabel: e2e.CapiClusterOwnerNamespaceLabel,
284288
OwnedLabelName: e2e.OwnedLabelName,
289+
TopologyNamespace: topologyNamespace,
290+
AdditionalTemplateVariables: map[string]string{
291+
e2e.KubernetesVersionVar: e2e.LoadE2EConfig().GetVariableOrEmpty(e2e.AWSKubernetesVersionVar), // override the default k8s version
292+
},
293+
AdditionalFleetGitRepos: []turtlesframework.FleetCreateGitRepoInput{
294+
{
295+
Name: "aws-cluster-classes-eks",
296+
Paths: []string{"examples/clusterclasses/aws/eks"},
297+
ClusterProxy: bootstrapClusterProxy,
298+
TargetNamespace: topologyNamespace,
299+
},
300+
},
285301
}
286302
})
287303
})

0 commit comments

Comments
 (0)