Skip to content

Commit 3c5e5b0

Browse files
committed
Adding e2e tests for shared vpc installs
1 parent c9c98eb commit 3c5e5b0

File tree

4 files changed

+168
-16
lines changed

4 files changed

+168
-16
lines changed

scripts/ci-e2e.sh

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ EOF
102102

103103
# initialize a router and cloud NAT
104104
init_networks() {
105+
# gcloud compute shared-vpc enable "$GCP_PROJECT"
106+
# gcloud compute shared-vpc associated-projects add "$GCP_SERVICE_PROJECT" --host-project
107+
105108
if [[ ${GCP_NETWORK_NAME} != "default" ]]; then
106109
gcloud compute networks create --project "$GCP_PROJECT" "${GCP_NETWORK_NAME}" --subnet-mode auto --quiet
107110
gcloud compute firewall-rules create "${GCP_NETWORK_NAME}"-allow-http --project "$GCP_PROJECT" \
@@ -125,7 +128,6 @@ init_networks() {
125128
--nat-all-subnet-ip-ranges --auto-allocate-nat-external-ips
126129
}
127130

128-
129131
cleanup() {
130132
# Force a cleanup of cluster api created resources using gcloud commands
131133
(gcloud compute forwarding-rules list --project "$GCP_PROJECT" | grep capg-e2e \
@@ -143,25 +145,29 @@ cleanup() {
143145
(gcloud compute instances list --project "$GCP_PROJECT" | grep capg-e2e \
144146
| awk '{print "gcloud compute instances delete --project '"$GCP_PROJECT"' --quiet " $1 " --zone " $2 "\n"}' \
145147
| bash) || true
146-
(gcloud compute instance-groups list --project "$GCP_PROJECT" | grep capg-e2e \
147-
| awk '{print "gcloud compute instance-groups unmanaged delete --project '"$GCP_PROJECT"' --quiet " $1 " --zone " $2 "\n"}' \
148-
| bash) || true
149148
(gcloud compute firewall-rules list --project "$GCP_PROJECT" | grep capg-e2e \
150149
| awk '{print "gcloud compute firewall-rules delete --project '"$GCP_PROJECT"' --quiet " $1 "\n"}' \
151150
| bash) || true
151+
(gcloud compute instance-groups list --project "$GCP_PROJECT" | grep capg-e2e \
152+
| awk '{print "gcloud compute instance-groups unmanaged delete --project '"$GCP_PROJECT"' --quiet " $1 " --zone " $2 "\n"}' \
153+
| bash) || true
152154

153-
# cleanup the networks
154-
gcloud compute routers nats delete "${TEST_NAME}-mynat" --project="${GCP_PROJECT}" \
155-
--router-region="${GCP_REGION}" --router="${TEST_NAME}-myrouter" --quiet || true
156-
gcloud compute routers delete "${TEST_NAME}-myrouter" --project="${GCP_PROJECT}" \
157-
--region="${GCP_REGION}" --quiet || true
158-
159-
if [[ ${GCP_NETWORK_NAME} != "default" ]]; then
160-
(gcloud compute firewall-rules list --project "$GCP_PROJECT" | grep "$GCP_NETWORK_NAME" \
161-
| awk '{print "gcloud compute firewall-rules delete --project '"$GCP_PROJECT"' --quiet " $1 "\n"}' \
162-
| bash) || true
163-
gcloud compute networks delete --project="${GCP_PROJECT}" \
164-
--quiet "${GCP_NETWORK_NAME}" || true
155+
if [[ -n "${SKIP_INIT_NETWORK:-}" ]]; then
156+
echo "Skipping GCP network deletion..."
157+
else
158+
# cleanup the networks
159+
gcloud compute routers nats delete "${TEST_NAME}-mynat" --project="${GCP_PROJECT}" \
160+
--router-region="${GCP_REGION}" --router="${TEST_NAME}-myrouter" --quiet || true
161+
gcloud compute routers delete "${TEST_NAME}-myrouter" --project="${GCP_PROJECT}" \
162+
--region="${GCP_REGION}" --quiet || true
163+
164+
if [[ ${GCP_NETWORK_NAME} != "default" ]]; then
165+
(gcloud compute firewall-rules list --project "$GCP_PROJECT" | grep "$GCP_NETWORK_NAME" \
166+
| awk '{print "gcloud compute firewall-rules delete --project '"$GCP_PROJECT"' --quiet " $1 "\n"}' \
167+
| bash) || true
168+
gcloud compute networks delete --project="${GCP_PROJECT}" \
169+
--quiet "${GCP_NETWORK_NAME}" || true
170+
fi
165171
fi
166172

167173
if [[ -n "${SKIP_INIT_IMAGE:-}" ]]; then

test/e2e/config/gcp-ci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ providers:
7373
- sourcePath: "${PWD}/test/e2e/data/infrastructure-gcp/cluster-template-ci-gke-autopilot.yaml"
7474
- sourcePath: "${PWD}/test/e2e/data/infrastructure-gcp/cluster-template-ci-gke-custom-subnet.yaml"
7575
- sourcePath: "${PWD}/test/e2e/data/infrastructure-gcp/cluster-template-ci-with-internal-lb.yaml"
76+
- sourcePath: "${PWD}/test/e2e/data/infrastructure-gcp/cluster-template-ci-with-shared-vpc.yaml"
7677

7778
variables:
7879
KUBERNETES_VERSION: "${KUBERNETES_VERSION:-v1.29.0}"
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
---
2+
apiVersion: cluster.x-k8s.io/v1beta1
3+
kind: Cluster
4+
metadata:
5+
name: "${CLUSTER_NAME}"
6+
labels:
7+
cni: "${CLUSTER_NAME}-shared-vpc"
8+
spec:
9+
clusterNetwork:
10+
pods:
11+
cidrBlocks: ["192.168.0.0/16"]
12+
infrastructureRef:
13+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
14+
kind: GCPCluster
15+
name: "${CLUSTER_NAME}"
16+
controlPlaneRef:
17+
kind: KubeadmControlPlane
18+
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
19+
name: "${CLUSTER_NAME}-control-plane"
20+
---
21+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
22+
kind: GCPCluster
23+
metadata:
24+
name: "${CLUSTER_NAME}"
25+
spec:
26+
project: "${GCP_SERVICE_PROJECT}"
27+
region: "${GCP_REGION}"
28+
network:
29+
name: "${GCP_NETWORK_NAME}"
30+
hostProject: "${GCP_PROJECT}"
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+
useExperimentalRetryJoin: true
45+
initConfiguration:
46+
nodeRegistration:
47+
name: '{{ ds.meta_data.local_hostname.split(".")[0] }}'
48+
kubeletExtraArgs:
49+
cloud-provider: gce
50+
clusterConfiguration:
51+
apiServer:
52+
timeoutForControlPlane: 20m
53+
extraArgs:
54+
cloud-provider: gce
55+
controllerManager:
56+
extraArgs:
57+
cloud-provider: gce
58+
allocate-node-cidrs: "false"
59+
kubernetesVersion: "${KUBERNETES_VERSION}"
60+
joinConfiguration:
61+
nodeRegistration:
62+
name: '{{ ds.meta_data.local_hostname.split(".")[0] }}'
63+
kubeletExtraArgs:
64+
cloud-provider: gce
65+
version: "${KUBERNETES_VERSION}"
66+
---
67+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
68+
kind: GCPMachineTemplate
69+
metadata:
70+
name: "${CLUSTER_NAME}-control-plane"
71+
spec:
72+
template:
73+
spec:
74+
instanceType: "${GCP_CONTROL_PLANE_MACHINE_TYPE}"
75+
image: "${IMAGE_ID}"
76+
---
77+
apiVersion: cluster.x-k8s.io/v1beta1
78+
kind: MachineDeployment
79+
metadata:
80+
name: "${CLUSTER_NAME}-md-0"
81+
spec:
82+
clusterName: "${CLUSTER_NAME}"
83+
replicas: ${WORKER_MACHINE_COUNT}
84+
selector:
85+
matchLabels:
86+
template:
87+
spec:
88+
clusterName: "${CLUSTER_NAME}"
89+
version: "${KUBERNETES_VERSION}"
90+
bootstrap:
91+
configRef:
92+
name: "${CLUSTER_NAME}-md-0"
93+
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
94+
kind: KubeadmConfigTemplate
95+
infrastructureRef:
96+
name: "${CLUSTER_NAME}-md-0"
97+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
98+
kind: GCPMachineTemplate
99+
---
100+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
101+
kind: GCPMachineTemplate
102+
metadata:
103+
name: "${CLUSTER_NAME}-md-0"
104+
spec:
105+
template:
106+
spec:
107+
instanceType: "${GCP_NODE_MACHINE_TYPE}"
108+
image: "${IMAGE_ID}"
109+
---
110+
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
111+
kind: KubeadmConfigTemplate
112+
metadata:
113+
name: "${CLUSTER_NAME}-md-0"
114+
spec:
115+
template:
116+
spec:
117+
joinConfiguration:
118+
nodeRegistration:
119+
name: '{{ ds.meta_data.local_hostname.split(".")[0] }}'
120+
kubeletExtraArgs:
121+
cloud-provider: gce

test/e2e/e2e_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,28 @@ var _ = Describe("Workload cluster creation", func() {
206206
}, result)
207207
})
208208
})
209+
210+
Context("Creating a control-plane cluster with a shared vpc", func() {
211+
It("Should create a cluster with 1 control-plane and 1 worker node where the network exists in a host project", func() {
212+
By("Creating a cluster where the host project shares network resources with the service project")
213+
clusterctl.ApplyClusterTemplateAndWait(ctx, clusterctl.ApplyClusterTemplateAndWaitInput{
214+
ClusterProxy: bootstrapClusterProxy,
215+
ConfigCluster: clusterctl.ConfigClusterInput{
216+
LogFolder: clusterctlLogFolder,
217+
ClusterctlConfigPath: clusterctlConfigPath,
218+
KubeconfigPath: bootstrapClusterProxy.GetKubeconfigPath(),
219+
InfrastructureProvider: clusterctl.DefaultInfrastructureProvider,
220+
Flavor: "ci-with-shared-vpc",
221+
Namespace: namespace.Name,
222+
ClusterName: clusterName,
223+
KubernetesVersion: e2eConfig.GetVariable(KubernetesVersion),
224+
ControlPlaneMachineCount: ptr.To[int64](1),
225+
WorkerMachineCount: ptr.To[int64](1),
226+
},
227+
WaitForClusterIntervals: e2eConfig.GetIntervals(specName, "wait-cluster"),
228+
WaitForControlPlaneIntervals: e2eConfig.GetIntervals(specName, "wait-control-plane"),
229+
WaitForMachineDeployments: e2eConfig.GetIntervals(specName, "wait-worker-nodes"),
230+
}, result)
231+
})
232+
})
209233
})

0 commit comments

Comments
 (0)