Skip to content

Commit ed3b28d

Browse files
committed
WIP: test for MachinePool
1 parent bf24435 commit ed3b28d

File tree

2 files changed

+209
-0
lines changed

2 files changed

+209
-0
lines changed
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
---
2+
apiVersion: cluster.x-k8s.io/v1beta1
3+
kind: Cluster
4+
metadata:
5+
name: "${CLUSTER_NAME}"
6+
labels:
7+
cni: "${CLUSTER_NAME}-crs-cni"
8+
ccm: "${CLUSTER_NAME}-crs-ccm"
9+
spec:
10+
clusterNetwork:
11+
pods:
12+
cidrBlocks: ["192.168.0.0/16"]
13+
infrastructureRef:
14+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
15+
kind: GCPCluster
16+
name: "${CLUSTER_NAME}"
17+
controlPlaneRef:
18+
kind: KubeadmControlPlane
19+
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
20+
name: "${CLUSTER_NAME}-control-plane"
21+
---
22+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
23+
kind: GCPCluster
24+
metadata:
25+
name: "${CLUSTER_NAME}"
26+
spec:
27+
project: "${GCP_PROJECT}"
28+
region: "${GCP_REGION}"
29+
network:
30+
name: "${GCP_NETWORK_NAME}"
31+
---
32+
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
33+
kind: KubeadmControlPlane
34+
metadata:
35+
name: "${CLUSTER_NAME}-control-plane"
36+
spec:
37+
replicas: ${CONTROL_PLANE_MACHINE_COUNT}
38+
machineTemplate:
39+
infrastructureRef:
40+
kind: GCPMachineTemplate
41+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
42+
name: "${CLUSTER_NAME}-control-plane"
43+
kubeadmConfigSpec:
44+
initConfiguration:
45+
nodeRegistration:
46+
name: '{{ ds.meta_data.local_hostname.split(".")[0] }}'
47+
kubeletExtraArgs:
48+
cloud-provider: external
49+
clusterConfiguration:
50+
apiServer:
51+
timeoutForControlPlane: 20m
52+
extraArgs:
53+
cloud-provider: external
54+
controllerManager:
55+
extraArgs:
56+
cloud-provider: external
57+
allocate-node-cidrs: "false"
58+
kubernetesVersion: "${KUBERNETES_VERSION}"
59+
files:
60+
- content: |
61+
[Global]
62+
63+
project-id = "${GCP_PROJECT}"
64+
network-name = "${GCP_NETWORK_NAME}"
65+
multizone = true
66+
owner: root:root
67+
path: /etc/kubernetes/cloud.config
68+
permissions: "0744"
69+
joinConfiguration:
70+
nodeRegistration:
71+
name: '{{ ds.meta_data.local_hostname.split(".")[0] }}'
72+
kubeletExtraArgs:
73+
cloud-provider: external
74+
version: "${KUBERNETES_VERSION}"
75+
---
76+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
77+
kind: GCPMachineTemplate
78+
metadata:
79+
name: "${CLUSTER_NAME}-control-plane"
80+
spec:
81+
template:
82+
spec:
83+
instanceType: "${GCP_CONTROL_PLANE_MACHINE_TYPE}"
84+
image: "${IMAGE_ID}"
85+
---
86+
apiVersion: cluster.x-k8s.io/v1beta1
87+
kind: MachinePool
88+
metadata:
89+
name: "${CLUSTER_NAME}-md-0"
90+
spec:
91+
clusterName: "${CLUSTER_NAME}"
92+
replicas: ${WORKER_MACHINE_COUNT}
93+
template:
94+
spec:
95+
clusterName: "${CLUSTER_NAME}"
96+
version: "${KUBERNETES_VERSION}"
97+
bootstrap:
98+
configRef:
99+
name: "${CLUSTER_NAME}-md-0"
100+
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
101+
kind: KubeadmConfigTemplate
102+
infrastructureRef:
103+
name: "${CLUSTER_NAME}-md-0"
104+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
105+
kind: GCPMachineTemplate
106+
---
107+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
108+
kind: GCPMachinePool
109+
metadata:
110+
name: "${CLUSTER_NAME}-md-0"
111+
spec:
112+
instanceType: "${GCP_NODE_MACHINE_TYPE}"
113+
image: "${IMAGE_ID}"
114+
---
115+
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
116+
kind: KubeadmConfigTemplate
117+
metadata:
118+
name: "${CLUSTER_NAME}-md-0"
119+
spec:
120+
template:
121+
spec:
122+
joinConfiguration:
123+
nodeRegistration:
124+
name: '{{ ds.meta_data.local_hostname.split(".")[0] }}'
125+
kubeletExtraArgs:
126+
cloud-provider: external
127+
---
128+
apiVersion: v1
129+
kind: ConfigMap
130+
metadata:
131+
name: "${CLUSTER_NAME}-crs-cni"
132+
data: ${CNI_RESOURCES}
133+
---
134+
apiVersion: addons.cluster.x-k8s.io/v1beta1
135+
kind: ClusterResourceSet
136+
metadata:
137+
name: "${CLUSTER_NAME}-crs-cni"
138+
spec:
139+
strategy: ApplyOnce
140+
clusterSelector:
141+
matchLabels:
142+
cni: "${CLUSTER_NAME}-crs-cni"
143+
resources:
144+
- name: "${CLUSTER_NAME}-crs-cni"
145+
kind: ConfigMap
146+
---
147+
apiVersion: v1
148+
kind: ConfigMap
149+
metadata:
150+
name: "${CLUSTER_NAME}-crs-ccm"
151+
data: ${CCM_RESOURCES}
152+
---
153+
apiVersion: addons.cluster.x-k8s.io/v1beta1
154+
kind: ClusterResourceSet
155+
metadata:
156+
name: "${CLUSTER_NAME}-crs-ccm"
157+
spec:
158+
strategy: ApplyOnce
159+
clusterSelector:
160+
matchLabels:
161+
ccm: "${CLUSTER_NAME}-crs-ccm"
162+
resources:
163+
- name: "${CLUSTER_NAME}-crs-ccm"
164+
kind: ConfigMap

test/e2e/e2e_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,51 @@ var _ = Describe("Workload cluster creation", func() {
125125
})
126126
})
127127

128+
Context("Creating a single control-plane cluster with MachinePool", func() {
129+
It("Should create a cluster with 1 worker node and can be scaled", func() {
130+
clusterName := fmt.Sprintf("%s-single", clusterNamePrefix)
131+
By("Initializes with 1 worker node")
132+
clusterctl.ApplyClusterTemplateAndWait(ctx, clusterctl.ApplyClusterTemplateAndWaitInput{
133+
ClusterProxy: bootstrapClusterProxy,
134+
ConfigCluster: clusterctl.ConfigClusterInput{
135+
LogFolder: clusterctlLogFolder,
136+
ClusterctlConfigPath: clusterctlConfigPath,
137+
KubeconfigPath: bootstrapClusterProxy.GetKubeconfigPath(),
138+
InfrastructureProvider: clusterctl.DefaultInfrastructureProvider,
139+
Flavor: "ci-with-machine-pool",
140+
Namespace: namespace.Name,
141+
ClusterName: clusterName,
142+
KubernetesVersion: e2eConfig.MustGetVariable(KubernetesVersion),
143+
ControlPlaneMachineCount: ptr.To[int64](1),
144+
WorkerMachineCount: ptr.To[int64](1),
145+
},
146+
WaitForClusterIntervals: e2eConfig.GetIntervals(specName, "wait-cluster"),
147+
WaitForControlPlaneIntervals: e2eConfig.GetIntervals(specName, "wait-control-plane"),
148+
WaitForMachineDeployments: e2eConfig.GetIntervals(specName, "wait-worker-nodes"),
149+
}, result)
150+
151+
By("Scaling worker node to 3")
152+
clusterctl.ApplyClusterTemplateAndWait(ctx, clusterctl.ApplyClusterTemplateAndWaitInput{
153+
ClusterProxy: bootstrapClusterProxy,
154+
ConfigCluster: clusterctl.ConfigClusterInput{
155+
LogFolder: clusterctlLogFolder,
156+
ClusterctlConfigPath: clusterctlConfigPath,
157+
KubeconfigPath: bootstrapClusterProxy.GetKubeconfigPath(),
158+
InfrastructureProvider: clusterctl.DefaultInfrastructureProvider,
159+
Flavor: "ci-with-machine-pool",
160+
Namespace: namespace.Name,
161+
ClusterName: clusterName,
162+
KubernetesVersion: e2eConfig.MustGetVariable(KubernetesVersion),
163+
ControlPlaneMachineCount: ptr.To[int64](1),
164+
WorkerMachineCount: ptr.To[int64](3),
165+
},
166+
WaitForClusterIntervals: e2eConfig.GetIntervals(specName, "wait-cluster"),
167+
WaitForControlPlaneIntervals: e2eConfig.GetIntervals(specName, "wait-control-plane"),
168+
WaitForMachineDeployments: e2eConfig.GetIntervals(specName, "wait-worker-nodes"),
169+
}, result)
170+
})
171+
})
172+
128173
Context("Creating a highly available control-plane cluster", func() {
129174
It("Should create a cluster with 3 control-plane and 2 worker nodes", func() {
130175
clusterName := fmt.Sprintf("%s-ha", clusterNamePrefix)

0 commit comments

Comments
 (0)