Skip to content

Commit 6ab2448

Browse files
committed
Add EKS ClusterClass example
1 parent a1e5677 commit 6ab2448

File tree

4 files changed

+228
-0
lines changed

4 files changed

+228
-0
lines changed
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
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+
patches:
59+
- name: awsManagedControlPlaneTemplate
60+
definitions:
61+
- selector:
62+
apiVersion: controlplane.cluster.x-k8s.io/v1beta2
63+
kind: AWSManagedControlPlaneTemplate
64+
matchResources:
65+
controlPlane: true
66+
jsonPatches:
67+
- op: add
68+
enabledIf: '{{ ne .eksClusterName }}'
69+
path: /spec/template/spec/eksClusterName
70+
valueFrom:
71+
variable: eksClusterName
72+
- op: add
73+
path: /spec/template/spec/region
74+
valueFrom:
75+
variable: region
76+
- op: add
77+
enabledIf: '{{ ne .sshKeyName }}'
78+
path: /spec/template/spec/sshKeyName
79+
valueFrom:
80+
variable: sshKeyName
81+
# Builtins
82+
- op: add
83+
path: "/spec/template/spec/version"
84+
valueFrom:
85+
variable: builtin.cluster.topology.version
86+
- name: awsMachineTemplate
87+
definitions:
88+
- selector:
89+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
90+
kind: AWSMachineTemplate
91+
matchResources:
92+
machineDeploymentClass:
93+
names:
94+
- default-worker
95+
jsonPatches:
96+
- op: add
97+
enabledIf: '{{ ne .sshKeyName }}'
98+
path: /spec/template/spec/sshKeyName
99+
valueFrom:
100+
variable: sshKeyName
101+
- op: add
102+
path: /spec/template/spec/instanceType
103+
valueFrom:
104+
variable: instanceType
105+
---
106+
kind: AWSManagedClusterTemplate
107+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
108+
metadata:
109+
name: "eks-cluster"
110+
spec:
111+
template:
112+
spec: {}
113+
---
114+
kind: AWSManagedControlPlaneTemplate
115+
apiVersion: controlplane.cluster.x-k8s.io/v1beta2
116+
metadata:
117+
name: "eks-control-plane"
118+
spec:
119+
template:
120+
spec:
121+
region: "replaced_by_patch"
122+
version: "v0.0.0" # To be replaced by patch
123+
---
124+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
125+
kind: AWSMachineTemplate
126+
metadata:
127+
name: "eks-md-0"
128+
spec:
129+
template:
130+
spec:
131+
instanceType: "replaced_by_patch"
132+
iamInstanceProfile: "nodes.cluster-api-provider-aws.sigs.k8s.io"
133+
---
134+
apiVersion: bootstrap.cluster.x-k8s.io/v1beta2
135+
kind: EKSConfigTemplate
136+
metadata:
137+
name: "eks-md-0"
138+
spec:
139+
template:
140+
spec: {}

test/e2e/const.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ var (
9090
//go:embed data/cluster-templates/aws-eks-mmp.yaml
9191
CAPIAwsEKSMMP []byte
9292

93+
//go:embed data/cluster-templates/aws-eks-topology.yaml
94+
CAPIAwsEKSTopology []byte
95+
9396
//go:embed data/cluster-templates/aws-ec2-rke2-topology.yaml
9497
CAPIAwsEC2RKE2Topology []byte
9598

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

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,64 @@ var _ = Describe("[AWS] [EKS] Create and delete CAPI cluster functionality shoul
286286
})
287287
})
288288

289+
var _ = FDescribe("[AWS] [EKS] Create and delete CAPI cluster from cluster class", Label(e2e.FullTestLabel), func() {
290+
var topologyNamespace string
291+
292+
BeforeEach(func() {
293+
komega.SetClient(bootstrapClusterProxy.GetClient())
294+
komega.SetContext(ctx)
295+
296+
topologyNamespace = "creategitops-aws-eks"
297+
})
298+
299+
specs.CreateMgmtV3UsingGitOpsSpec(ctx, func() specs.CreateMgmtV3UsingGitOpsSpecInput {
300+
testenv.CAPIOperatorDeployProvider(ctx, testenv.CAPIOperatorDeployProviderInput{
301+
BootstrapClusterProxy: bootstrapClusterProxy,
302+
CAPIProvidersSecretsYAML: [][]byte{
303+
e2e.AWSIdentitySecret,
304+
},
305+
CAPIProvidersYAML: [][]byte{
306+
e2e.AWSProvider,
307+
},
308+
WaitForDeployments: []testenv.NamespaceName{
309+
{
310+
Name: "capa-controller-manager",
311+
Namespace: "capa-system",
312+
},
313+
},
314+
})
315+
316+
return specs.CreateMgmtV3UsingGitOpsSpecInput{
317+
E2EConfig: e2e.LoadE2EConfig(),
318+
BootstrapClusterProxy: bootstrapClusterProxy,
319+
ClusterTemplate: e2e.CAPIAwsEKSTopology,
320+
ClusterName: "cluster-eks",
321+
ControlPlaneMachineCount: ptr.To(1),
322+
WorkerMachineCount: ptr.To(1),
323+
LabelNamespace: true,
324+
RancherServerURL: hostName,
325+
CAPIClusterCreateWaitName: "wait-capa-create-cluster",
326+
DeleteClusterWaitName: "wait-eks-delete",
327+
CapiClusterOwnerLabel: e2e.CapiClusterOwnerLabel,
328+
CapiClusterOwnerNamespaceLabel: e2e.CapiClusterOwnerNamespaceLabel,
329+
OwnedLabelName: e2e.OwnedLabelName,
330+
TopologyNamespace: topologyNamespace,
331+
AdditionalTemplateVariables: map[string]string{
332+
e2e.KubernetesVersionVar: e2e.LoadE2EConfig().GetVariableOrEmpty(e2e.AWSKubernetesVersionVar), // override the default k8s version
333+
},
334+
AdditionalFleetGitRepos: []turtlesframework.FleetCreateGitRepoInput{
335+
{
336+
Name: "aws-cluster-classes-eks",
337+
Paths: []string{"examples/clusterclasses/aws/eks"},
338+
ClusterProxy: bootstrapClusterProxy,
339+
TargetNamespace: topologyNamespace,
340+
Branch: "aws-eks-example",
341+
},
342+
},
343+
}
344+
})
345+
})
346+
289347
var _ = Describe("[AWS] [EC2 Kubeadm] Create and delete CAPI cluster functionality should work with namespace auto-import", Label(e2e.FullTestLabel, e2e.KubeadmTestLabel), func() {
290348
var topologyNamespace string
291349

0 commit comments

Comments
 (0)