Skip to content

Commit 4f1609a

Browse files
committed
WIP: test for MachinePool
1 parent 3eea450 commit 4f1609a

File tree

6 files changed

+214
-8
lines changed

6 files changed

+214
-8
lines changed

config/manager/manager.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ spec:
2121
containers:
2222
- args:
2323
- --leader-elect
24-
- --feature-gates=GKE=${EXP_CAPG_GKE:=false}
24+
- --feature-gates=GKE=${EXP_CAPG_GKE:=false},MachinePool=${EXP_MACHINE_POOL:=false}
2525
- "--diagnostics-address=${CAPG_DIAGNOSTICS_ADDRESS:=:8443}"
2626
- "--insecure-diagnostics=${CAPG_INSECURE_DIAGNOSTICS:=false}"
2727
- "--v=${CAPG_LOGLEVEL:=0}"

feature/feature.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ const (
3030
// owner: @richardchen331 & @richardcase
3131
// alpha: v0.1
3232
GKE featuregate.Feature = "GKE"
33-
34-
// MachinePool is used to enable MIG support
35-
// owner: @justinsb
36-
// alpha: v0.1
37-
MachinePool featuregate.Feature = "MachinePool"
3833
)
3934

4035
func init() {

main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) error {
207207
return fmt.Errorf("setting up GCPCluster controller: %w", err)
208208
}
209209

210-
if feature.Gates.Enabled(feature.MachinePool) {
210+
if feature.Gates.Enabled(capifeature.MachinePool) {
211211
setupLog.Info("Enabling MachinePool reconcilers")
212212
gcpMachinePoolConcurrency := gcpMachineConcurrency // FUTURE: Use our own flag while feature-gated?
213213

@@ -275,7 +275,7 @@ func setupWebhooks(mgr ctrl.Manager) error {
275275
return fmt.Errorf("setting up GCPMachineTemplate webhook: %w", err)
276276
}
277277

278-
if feature.Gates.Enabled(feature.MachinePool) {
278+
if feature.Gates.Enabled(capifeature.MachinePool) {
279279
setupLog.Info("Enabling GCPMachinePool webhooks")
280280

281281
if err := (&infrav1exp.GCPMachinePool{}).SetupWebhookWithManager(mgr); err != nil {

test/e2e/config/gcp-ci.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ providers:
7575
- sourcePath: "${PWD}/test/e2e/data/infrastructure-gcp/cluster-template-ci-gke-autopilot.yaml"
7676
- sourcePath: "${PWD}/test/e2e/data/infrastructure-gcp/cluster-template-ci-gke-custom-subnet.yaml"
7777
- sourcePath: "${PWD}/test/e2e/data/infrastructure-gcp/cluster-template-ci-with-internal-lb.yaml"
78+
- sourcePath: "${PWD}/test/e2e/data/infrastructure-gcp/cluster-template-ci-with-machinepool.yaml"
7879
- sourcePath: "${PWD}/test/e2e/data/infrastructure-gcp/withclusterclass/cluster-template-ci-gke-autopilot-topology.yaml"
7980

8081
variables:
@@ -120,6 +121,7 @@ intervals:
120121
default/wait-gpu-nodes: ["30m", "10s"]
121122
default/wait-delete-cluster: ["30m", "10s"]
122123
default/wait-machine-upgrade: ["60m", "10s"]
124+
default/wait-machine-pool-nodes: ["40m", "10s"]
123125
default/wait-machine-pool-upgrade: ["60m", "10s"]
124126
default/wait-machine-remediation: ["30m", "10s"]
125127
default/wait-deployment: ["15m", "10s"]
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
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+
controllerManager:
53+
extraArgs:
54+
cloud-provider: external
55+
allocate-node-cidrs: "false"
56+
kubernetesVersion: "${KUBERNETES_VERSION}"
57+
files:
58+
- content: |
59+
[Global]
60+
61+
project-id = "${GCP_PROJECT}"
62+
network-name = "${GCP_NETWORK_NAME}"
63+
multizone = true
64+
owner: root:root
65+
path: /etc/kubernetes/cloud.config
66+
permissions: "0744"
67+
joinConfiguration:
68+
nodeRegistration:
69+
name: '{{ ds.meta_data.local_hostname.split(".")[0] }}'
70+
kubeletExtraArgs:
71+
cloud-provider: external
72+
version: "${KUBERNETES_VERSION}"
73+
---
74+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
75+
kind: GCPMachineTemplate
76+
metadata:
77+
name: "${CLUSTER_NAME}-control-plane"
78+
spec:
79+
template:
80+
spec:
81+
instanceType: "${GCP_CONTROL_PLANE_MACHINE_TYPE}"
82+
image: "${IMAGE_ID}"
83+
---
84+
apiVersion: cluster.x-k8s.io/v1beta1
85+
kind: MachinePool
86+
metadata:
87+
name: "${CLUSTER_NAME}-md-0"
88+
spec:
89+
clusterName: "${CLUSTER_NAME}"
90+
replicas: ${WORKER_MACHINE_COUNT}
91+
template:
92+
spec:
93+
clusterName: "${CLUSTER_NAME}"
94+
version: "${KUBERNETES_VERSION}"
95+
bootstrap:
96+
configRef:
97+
name: "${CLUSTER_NAME}-md-0"
98+
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
99+
kind: KubeadmConfigTemplate
100+
infrastructureRef:
101+
name: "${CLUSTER_NAME}-md-0"
102+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
103+
kind: GCPMachineTemplate
104+
---
105+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
106+
kind: GCPMachinePool
107+
metadata:
108+
name: "${CLUSTER_NAME}-md-0"
109+
spec:
110+
instanceType: "${GCP_NODE_MACHINE_TYPE}"
111+
image: "${IMAGE_ID}"
112+
---
113+
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
114+
kind: KubeadmConfigTemplate
115+
metadata:
116+
name: "${CLUSTER_NAME}-md-0"
117+
spec:
118+
template:
119+
spec:
120+
joinConfiguration:
121+
nodeRegistration:
122+
name: '{{ ds.meta_data.local_hostname.split(".")[0] }}'
123+
kubeletExtraArgs:
124+
cloud-provider: external
125+
---
126+
apiVersion: v1
127+
kind: ConfigMap
128+
metadata:
129+
name: "${CLUSTER_NAME}-crs-cni"
130+
data: ${CNI_RESOURCES}
131+
---
132+
apiVersion: addons.cluster.x-k8s.io/v1beta1
133+
kind: ClusterResourceSet
134+
metadata:
135+
name: "${CLUSTER_NAME}-crs-cni"
136+
spec:
137+
strategy: ApplyOnce
138+
clusterSelector:
139+
matchLabels:
140+
cni: "${CLUSTER_NAME}-crs-cni"
141+
resources:
142+
- name: "${CLUSTER_NAME}-crs-cni"
143+
kind: ConfigMap
144+
---
145+
apiVersion: v1
146+
kind: ConfigMap
147+
metadata:
148+
name: "${CLUSTER_NAME}-crs-ccm"
149+
data: ${CCM_RESOURCES}
150+
---
151+
apiVersion: addons.cluster.x-k8s.io/v1beta1
152+
kind: ClusterResourceSet
153+
metadata:
154+
name: "${CLUSTER_NAME}-crs-ccm"
155+
spec:
156+
strategy: ApplyOnce
157+
clusterSelector:
158+
matchLabels:
159+
ccm: "${CLUSTER_NAME}-crs-ccm"
160+
resources:
161+
- name: "${CLUSTER_NAME}-crs-ccm"
162+
kind: ConfigMap

test/e2e/e2e_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,53 @@ 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-machinepool",
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+
WaitForMachinePools: e2eConfig.GetIntervals(specName, "wait-machine-pool-nodes"),
150+
}, result)
151+
152+
By("Scaling worker node to 3")
153+
clusterctl.ApplyClusterTemplateAndWait(ctx, clusterctl.ApplyClusterTemplateAndWaitInput{
154+
ClusterProxy: bootstrapClusterProxy,
155+
ConfigCluster: clusterctl.ConfigClusterInput{
156+
LogFolder: clusterctlLogFolder,
157+
ClusterctlConfigPath: clusterctlConfigPath,
158+
KubeconfigPath: bootstrapClusterProxy.GetKubeconfigPath(),
159+
InfrastructureProvider: clusterctl.DefaultInfrastructureProvider,
160+
Flavor: "ci-with-machinepool",
161+
Namespace: namespace.Name,
162+
ClusterName: clusterName,
163+
KubernetesVersion: e2eConfig.MustGetVariable(KubernetesVersion),
164+
ControlPlaneMachineCount: ptr.To[int64](1),
165+
WorkerMachineCount: ptr.To[int64](3),
166+
},
167+
WaitForClusterIntervals: e2eConfig.GetIntervals(specName, "wait-cluster"),
168+
WaitForControlPlaneIntervals: e2eConfig.GetIntervals(specName, "wait-control-plane"),
169+
WaitForMachineDeployments: e2eConfig.GetIntervals(specName, "wait-worker-nodes"),
170+
WaitForMachinePools: e2eConfig.GetIntervals(specName, "wait-machine-pool-nodes"),
171+
}, result)
172+
})
173+
})
174+
128175
Context("Creating a highly available control-plane cluster", func() {
129176
It("Should create a cluster with 3 control-plane and 2 worker nodes", func() {
130177
clusterName := fmt.Sprintf("%s-ha", clusterNamePrefix)

0 commit comments

Comments
 (0)