Skip to content

Commit 0a32a1f

Browse files
tormath1eljohnson92
authored andcommitted
e2e: add Flatcar test
This test will upload a Flatcar image and deploy a 2 nodes cluster Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>
1 parent 4067998 commit 0a32a1f

File tree

7 files changed

+399
-0
lines changed

7 files changed

+399
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: capi-controller-manager
5+
namespace: capi-system
6+
status:
7+
availableReplicas: 1
8+
---
9+
apiVersion: apps/v1
10+
kind: Deployment
11+
metadata:
12+
name: capl-controller-manager
13+
namespace: capl-system
14+
status:
15+
availableReplicas: 1
16+
---
17+
apiVersion: apps/v1
18+
kind: Deployment
19+
metadata:
20+
name: capi-kubeadm-bootstrap-controller-manager
21+
namespace: kubeadm-bootstrap-system
22+
status:
23+
availableReplicas: 1
24+
---
25+
apiVersion: apps/v1
26+
kind: Deployment
27+
metadata:
28+
name: capi-kubeadm-control-plane-controller-manager
29+
namespace: kubeadm-control-plane-system
30+
status:
31+
availableReplicas: 1
32+
---
33+
apiVersion: apps/v1
34+
kind: Deployment
35+
metadata:
36+
name: caaph-controller-manager
37+
namespace: caaph-system
38+
status:
39+
availableReplicas: 1
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
apiVersion: apps/v1
2+
kind: DaemonSet
3+
metadata:
4+
name: ccm-linode
5+
namespace: kube-system
6+
status:
7+
currentNumberScheduled: 1
8+
desiredNumberScheduled: 1
9+
numberAvailable: 1
10+
numberMisscheduled: 0
11+
numberReady: 1
12+
---
13+
apiVersion: apps/v1
14+
kind: DaemonSet
15+
metadata:
16+
name: cilium
17+
namespace: kube-system
18+
status:
19+
currentNumberScheduled: 2
20+
desiredNumberScheduled: 2
21+
numberAvailable: 2
22+
numberMisscheduled: 0
23+
numberReady: 2
24+
---
25+
apiVersion: apps/v1
26+
kind: DaemonSet
27+
metadata:
28+
name: csi-linode-node
29+
namespace: kube-system
30+
status:
31+
currentNumberScheduled: 2
32+
desiredNumberScheduled: 2
33+
numberAvailable: 2
34+
numberMisscheduled: 0
35+
numberReady: 2
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: cilium-operator
5+
namespace: kube-system
6+
status:
7+
availableReplicas: 2
8+
readyReplicas: 2
9+
---
10+
apiVersion: apps/v1
11+
kind: Deployment
12+
metadata:
13+
labels:
14+
app.kubernetes.io/part-of: cilium
15+
namespace: kube-system
16+
status:
17+
readyReplicas: 1
18+
---
19+
apiVersion: apps/v1
20+
kind: Deployment
21+
metadata:
22+
name: coredns
23+
namespace: kube-system
24+
status:
25+
availableReplicas: 2
26+
readyReplicas: 2
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
3+
kind: LinodeMachine
4+
metadata:
5+
labels:
6+
cluster.x-k8s.io/cluster-name: ($cluster)
7+
spec:
8+
region: (env('LINODE_REGION'))
9+
type: g6-standard-2
10+
status:
11+
ready: true
12+
instanceState: running
13+
---
14+
apiVersion: cluster.x-k8s.io/v1beta1
15+
kind: Machine
16+
metadata:
17+
labels:
18+
cluster.x-k8s.io/cluster-name: ($cluster)
19+
spec:
20+
clusterName: ($cluster)
21+
status:
22+
bootstrapReady: true
23+
infrastructureReady: true
24+
---
25+
apiVersion: cluster.x-k8s.io/v1beta1
26+
kind: MachineDeployment
27+
metadata:
28+
labels:
29+
cluster.x-k8s.io/cluster-name: ($cluster)
30+
spec:
31+
clusterName: ($cluster)
32+
replicas: 1
33+
status:
34+
readyReplicas: 1
35+
unavailableReplicas: 0
36+
availableReplicas: 1
37+
---
38+
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
39+
kind: KubeadmControlPlane
40+
metadata:
41+
labels:
42+
cluster.x-k8s.io/cluster-name: ($cluster)
43+
status:
44+
readyReplicas: 1
45+
unavailableReplicas: 0
46+
ready: true
47+
---
48+
apiVersion: addons.cluster.x-k8s.io/v1alpha1
49+
kind: HelmReleaseProxy
50+
metadata:
51+
labels:
52+
cluster.x-k8s.io/cluster-name: ($cluster)
53+
status:
54+
conditions:
55+
- type: Ready
56+
status: "True"
57+
- type: ClusterAvailable
58+
status: "True"
59+
- type: HelmReleaseReady
60+
status: "True"
61+
status: deployed
Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
2+
apiVersion: chainsaw.kyverno.io/v1alpha1
3+
kind: Test
4+
metadata:
5+
creationTimestamp: null
6+
name: flatcar-capl-cluster
7+
# Labels to allow the test to be triggered based on selector flag
8+
labels:
9+
all:
10+
kubeadm:
11+
flavors:
12+
flatcar:
13+
spec:
14+
bindings:
15+
# A short identifier for the E2E test run
16+
- name: run
17+
value: (join('-', ['e2e', 'flatcar-cluster', env('GIT_REF')]))
18+
- name: cluster
19+
# Format the cluster name
20+
value: (trim((truncate(($run), `32`)), '-'))
21+
template: true
22+
steps:
23+
- name: Check if CAPI provider resources exist
24+
try:
25+
- assert:
26+
file: assert-capi-resources.yaml
27+
- name: Upload Flatcar image
28+
try:
29+
- script:
30+
env:
31+
- name: TARGET_API
32+
value: api.linode.com
33+
- name: TARGET_API_VERSION
34+
value: v4
35+
- name: URI
36+
value: images/upload
37+
- name: LINODE_REGION
38+
value: (env('LINODE_REGION'))
39+
content: |
40+
set -e
41+
# Get the latest version on Alpha channel.
42+
# NOTE: This can be changed to Beta or Stable when Akamai support will come on these channels.
43+
curl -fsSL --remote-name \
44+
https://alpha.release.flatcar-linux.net/amd64-usr/current/flatcar_production_akamai_image.bin.gz
45+
46+
res=$(curl -s --request POST \
47+
--url "https://${TARGET_API}/${TARGET_API_VERSION}/${URI}" \
48+
--data '{"region":"'${LINODE_REGION}'","cloud_init":true,"label":"flatcar-alpha"}' \
49+
--header "Authorization: Bearer ${LINODE_TOKEN}" \
50+
--header "accept: application/json" \
51+
--header "content-type: application/json")
52+
53+
UPLOAD_URL=$(echo "${res}" | jq -r .upload_to)
54+
IMAGE_ID=$(echo "${res}" | jq -r .image.id)
55+
echo "${IMAGE_ID}" > image-id
56+
57+
curl -s --request PUT \
58+
"${UPLOAD_URL}" \
59+
--header "Content-Type: application/octet-stream" \
60+
--upload-file flatcar_production_akamai_image.bin.gz \
61+
--progress-bar \
62+
--output /dev/null
63+
check:
64+
($error): ~
65+
- name: Generate cluster using clusterctl
66+
try:
67+
- script:
68+
env:
69+
- name: CLUSTER
70+
value: ($cluster)
71+
- name: NAMESPACE
72+
value: ($namespace)
73+
- name: CLUSTERCTL_CONFIG
74+
value: (env('CLUSTERCTL_CONFIG'))
75+
content: |
76+
set -e
77+
export FLATCAR_IMAGE_NAME=$(cat image-id)
78+
clusterctl generate cluster $CLUSTER -n $NAMESPACE \
79+
--kubernetes-version v1.29.5 \
80+
--infrastructure local-linode:v0.0.0 \
81+
--control-plane-machine-count 1 --worker-machine-count 1 \
82+
--flavor kubeadm-flatcar \
83+
--config ${CLUSTERCTL_CONFIG:=${HOME}/.cluster-api/clusterctl.yaml} > flatcar-cluster.yaml
84+
check:
85+
($error == null): true
86+
- name: Apply generated cluster yaml
87+
try:
88+
- apply:
89+
file: flatcar-cluster.yaml
90+
- assert:
91+
file: assert-child-cluster-resources.yaml
92+
catch:
93+
- describe:
94+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
95+
kind: LinodeMachine
96+
- describe:
97+
apiVersion: cluster.x-k8s.io/v1beta1
98+
kind: Machine
99+
- describe:
100+
apiVersion: cluster.x-k8s.io/v1beta1
101+
kind: MachineDeployment
102+
- describe:
103+
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
104+
kind: KubeadmControlPlane
105+
- describe:
106+
apiVersion: addons.cluster.x-k8s.io/v1alpha1
107+
kind: HelmReleaseProxy
108+
- name: Check if the linodes are created
109+
try:
110+
- script:
111+
env:
112+
- name: TARGET_API
113+
value: api.linode.com
114+
- name: TARGET_API_VERSION
115+
value: v4beta
116+
- name: URI
117+
value: linode/instances
118+
- name: FILTER
119+
value: (to_string({"tags":($cluster)}))
120+
content: |
121+
set -e
122+
curl -s \
123+
-H "Authorization: Bearer $LINODE_TOKEN" \
124+
-H "X-Filter: $FILTER" \
125+
-H "Content-Type: application/json" \
126+
"https://$TARGET_API/$TARGET_API_VERSION/$URI"
127+
check:
128+
($error): ~
129+
(json_parse($stdout)):
130+
results: 2
131+
- name: Get child cluster kubeconfig
132+
try:
133+
- script:
134+
env:
135+
- name: CLUSTER
136+
value: ($cluster)
137+
- name: NAMESPACE
138+
value: ($namespace)
139+
- name: CLUSTERCTL_CONFIG
140+
value: (env('CLUSTERCTL_CONFIG'))
141+
content: |
142+
set -e
143+
clusterctl get kubeconfig $CLUSTER -n $NAMESPACE > flatcar-cluster-kubeconfig.yaml
144+
check:
145+
($error == null): true
146+
- clusters:
147+
flatcar-cluster:
148+
kubeconfig: ./flatcar-cluster-kubeconfig.yaml
149+
name: Check child cluster resources
150+
try:
151+
- assert:
152+
cluster: flatcar-cluster
153+
file: assert-child-cluster-deployments.yaml
154+
- assert:
155+
cluster: flatcar-cluster
156+
file: assert-child-cluster-daemonsets.yaml
157+
catch:
158+
- describe:
159+
cluster: flatcar-cluster
160+
apiVersion: apps/v1
161+
kind: Deployment
162+
namespace: kube-system
163+
- describe:
164+
cluster: flatcar-cluster
165+
apiVersion: apps/v1
166+
kind: DaemonSet
167+
namespace: kube-system
168+
- name: Delete child cluster
169+
try:
170+
- delete:
171+
ref:
172+
apiVersion: cluster.x-k8s.io/v1beta1
173+
kind: Cluster
174+
name: ($cluster)
175+
- error:
176+
file: check-child-cluster-deleted.yaml
177+
- name: Check if the linodes are deleted
178+
try:
179+
- script:
180+
env:
181+
- name: TARGET_API
182+
value: api.linode.com
183+
- name: TARGET_API_VERSION
184+
value: v4beta
185+
- name: URI
186+
value: linode/instances
187+
- name: FILTER
188+
value: (to_string({"tags":($cluster)}))
189+
content: |
190+
set -e
191+
curl -s \
192+
-H "Authorization: Bearer $LINODE_TOKEN" \
193+
-H "X-Filter: $FILTER" \
194+
-H "Content-Type: application/json" \
195+
"https://$TARGET_API/$TARGET_API_VERSION/$URI"
196+
check:
197+
($error): ~
198+
(json_parse($stdout)):
199+
results: 0
200+
- name: Delete generated child cluster manifest yaml
201+
try:
202+
- script:
203+
content: |
204+
rm -f flatcar-cluster.yaml
205+
rm -f flatcar-cluster-kubeconfig.yaml
206+
check:
207+
($error == null): true
208+
- name: Delete Flatcar image
209+
try:
210+
- script:
211+
env:
212+
- name: TARGET_API
213+
value: api.linode.com
214+
- name: TARGET_API_VERSION
215+
value: v4
216+
- name: URI
217+
value: images
218+
- name: LINODE_REGION
219+
value: (env('LINODE_REGION'))
220+
content: |
221+
set -e
222+
# Get the latest version on Alpha channel.
223+
# NOTE: This can be changed to Beta or Stable when Akamai support will come on these channels.
224+
IMAGE_ID=$(cat image-id)
225+
curl -s --request DELETE \
226+
--url "https://${TARGET_API}/${TARGET_API_VERSION}/${URI}/${IMAGE_ID}" \
227+
--header "Authorization: Bearer ${LINODE_TOKEN}" \
228+
--header "accept: application/json"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
2+
kind: LinodeMachine
3+
metadata:
4+
labels:
5+
cluster.x-k8s.io/cluster-name: ($cluster)

0 commit comments

Comments
 (0)