Skip to content

Commit 7a24a67

Browse files
committed
e2e: linodemachine: cluster object store
1 parent 2d4a737 commit 7a24a67

8 files changed

+297
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
3+
kind: LinodeObjectStorageKey
4+
metadata:
5+
name: ($key)
6+
spec:
7+
keyGeneration: 0
8+
status:
9+
ready: true
10+
lastKeyGeneration: 0
11+
---
12+
apiVersion: v1
13+
kind: Secret
14+
metadata:
15+
name: ($key_secret)
16+
data:
17+
(bucket_name != null): true
18+
(s3_endpoint != null): true
19+
(access_key != null): true
20+
(secret_key != null): true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
3+
kind: LinodeMachine
4+
metadata:
5+
labels:
6+
cluster.x-k8s.io/cluster-name: ($cluster)
7+
spec:
8+
region: us-sea
9+
type: g6-nanode-1
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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+
name: cluster-object-store
6+
# Label to trigger the test on every PR
7+
labels:
8+
all:
9+
linodemachine:
10+
spec:
11+
bindings:
12+
# A short identifier for the E2E test run
13+
- name: run
14+
value: (join('-', ['e2e', 'cluster-obj-store', env('GIT_REF')]))
15+
- name: cluster
16+
# Format the cluster name
17+
value: (trim((truncate(($run), `29`)), '-'))
18+
- name: key
19+
# Format the key name into a valid Kubernetes object name
20+
# TODO: This is over-truncated to account for the Kubernetes access key Secret
21+
value: (trim((truncate((join('-', [($cluster), 'object-store'])), `52`)), '-'))
22+
- name: key_secret
23+
value: (concat(($key), '-obj-key'))
24+
template: true
25+
steps:
26+
- name: Check if CAPI provider resources exist
27+
try:
28+
- assert:
29+
file: assert-capi-resources.yaml
30+
- name: Create bucket
31+
try:
32+
- script:
33+
env:
34+
- name: URI
35+
value: object-storage/buckets
36+
- name: BUCKET_LABEL
37+
value: ($key)
38+
content: |
39+
set -e
40+
41+
curl -s \
42+
-X POST \
43+
-H "Authorization: Bearer $LINODE_TOKEN" \
44+
-H "Content-Type: application/json" \
45+
-d "{\"label\":\"$BUCKET_LABEL\",\"region\":\"us-sea\"}" \
46+
"https://api.linode.com/v4/$URI"
47+
check:
48+
($error): ~
49+
- name: Create LinodeObjectStorageKey
50+
try:
51+
- apply:
52+
file: create-linodeobjectstoragekey.yaml
53+
- assert:
54+
file: assert-key-and-secret.yaml
55+
catch:
56+
- describe:
57+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
58+
kind: LinodeObjectStorageKey
59+
- describe:
60+
apiVersion: v1
61+
kind: Secret
62+
- name: Create Cluster resource
63+
try:
64+
- apply:
65+
file: create-cluster.yaml
66+
catch:
67+
- describe:
68+
apiVersion: cluster.x-k8s.io/v1beta1
69+
kind: Cluster
70+
- name: Generate dummy cloud-config data
71+
try:
72+
- script:
73+
env:
74+
- name: NAMESPACE
75+
value: ($namespace)
76+
content: |
77+
set -e
78+
79+
# Some very incompressible data
80+
tr -dc A-Za-z0-9 < /dev/urandom | head -c 100kB > chonk.txt
81+
kubectl -n $NAMESPACE create secret generic chonk-secret --from-file=chonk.txt
82+
check:
83+
($error): ~
84+
- name: Create LinodeMachine resource
85+
try:
86+
- apply:
87+
file: create-linodemachine.yaml
88+
- assert:
89+
file: assert-linodemachine.yaml
90+
catch:
91+
- describe:
92+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
93+
kind: LinodeMachineTemplate
94+
- describe:
95+
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
96+
kind: KubeadmControlPlane
97+
- name: Delete Cluster resource
98+
try:
99+
- delete:
100+
ref:
101+
apiVersion: cluster.x-k8s.io/v1beta1
102+
kind: Cluster
103+
name: ($cluster)
104+
- error:
105+
file: check-linodemachine-deletion.yaml
106+
- name: Delete LinodeObjectStorageKey
107+
try:
108+
- script:
109+
env:
110+
- name: URI
111+
value: object-storage/keys
112+
- name: OBJ_KEY
113+
value: ($key)
114+
content: |
115+
set -e
116+
117+
export KEY_ID=$(kubectl -n $NAMESPACE get lobjkey $OBJ_KEY -ojson | jq '.status.accessKeyRef')
118+
119+
curl -s \
120+
-X DELETE \
121+
-H "Authorization: Bearer $LINODE_TOKEN" \
122+
"https://api.linode.com/v4/$URI/$KEY_ID"
123+
check:
124+
($error): ~
125+
- name: Delete bucket
126+
try:
127+
- script:
128+
env:
129+
- name: URI
130+
value: object-storage/buckets/us-sea
131+
- name: BUCKET_LABEL
132+
value: ($key)
133+
content: |
134+
set -e
135+
136+
curl -s \
137+
-X DELETE \
138+
-H "Authorization: Bearer $LINODE_TOKEN" \
139+
"https://api.linode.com/v4/$URI/$BUCKET_LABEL"
140+
check:
141+
($error): ~
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
2+
kind: LinodeMachine
3+
metadata:
4+
labels:
5+
cluster.x-k8s.io/cluster-name: ($cluster)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
apiVersion: cluster.x-k8s.io/v1beta1
3+
kind: Cluster
4+
metadata:
5+
name: ($cluster)
6+
spec:
7+
controlPlaneRef:
8+
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
9+
kind: KubeadmControlPlane
10+
name: ($cluster)
11+
infrastructureRef:
12+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
13+
kind: LinodeCluster
14+
name: ($cluster)
15+
---
16+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
17+
kind: LinodeCluster
18+
metadata:
19+
name: ($cluster)
20+
spec:
21+
region: us-sea
22+
objectStore:
23+
credentialsRef:
24+
name: ($key_secret)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
3+
kind: KubeadmControlPlane
4+
metadata:
5+
name: ($cluster)
6+
spec:
7+
kubeadmConfigSpec:
8+
files:
9+
- path: /chonk.txt
10+
contentFrom:
11+
secret:
12+
key: chonk.txt
13+
name: chonk-secret
14+
clusterConfiguration:
15+
apiServer:
16+
extraArgs:
17+
cloud-provider: external
18+
controllerManager:
19+
extraArgs:
20+
cloud-provider: external
21+
machineTemplate:
22+
infrastructureRef:
23+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
24+
kind: LinodeMachineTemplate
25+
name: ($cluster)
26+
replicas: 1
27+
version: 1.29.1
28+
---
29+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
30+
kind: LinodeMachineTemplate
31+
metadata:
32+
name: ($cluster)
33+
spec:
34+
template:
35+
spec:
36+
region: us-sea
37+
type: g6-nanode-1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
2+
kind: LinodeObjectStorageKey
3+
metadata:
4+
name: ($key)
5+
spec:
6+
bucketAccess:
7+
- bucketName: ($key)
8+
permissions: read_write
9+
region: us-sea
10+
generatedSecret:
11+
name: ($key_secret)
12+
format:
13+
bucket_name: '{{ .BucketName }}'
14+
s3_endpoint: '{{ .S3Endpoint }}'
15+
access_key: '{{ .AccessKey }}'
16+
secret_key: '{{ .SecretKey }}'

0 commit comments

Comments
 (0)