-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathchainsaw-test.yaml
More file actions
executable file
·102 lines (100 loc) · 3.54 KB
/
chainsaw-test.yaml
File metadata and controls
executable file
·102 lines (100 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
name: force-delete-linodeobjectstoragebucket
# Label to trigger the test on every PR
labels:
all:
quick:
linodeobj:
spec:
bindings:
# A short identifier for the E2E test run
- name: run
value: (join('-', ['e2e', 'force-delete-obj', random('[0-9a-z]{8}')]))
- name: bucket
# Format the bucket name into a valid Kubernetes object name
# TODO: This is over-truncated to account for the Kubernetes access key Secret
value: (trim((truncate(($run), `52`)), '-'))
- name: access_secret
value: (join('-', [($bucket), 'obj-key']))
template: true
steps:
- name: Check if CAPI provider resources exist
try:
- assert:
file: assert-capi-resources.yaml
- name: Create LinodeObjectStorageBucket and Key
try:
- apply:
file: create-bucket-and-key.yaml
# AFAICT this is the only way not have chainsaw immediately bomb out because resources don't exist
# or hang on assertion even after they do
- name: Wait for LinodeObjectStorageBucket and Key to be marked ready
try:
- script:
env:
- name: BUCKET
value: ($bucket)
content: |
set -e
kubectl -n $NAMESPACE wait --for=jsonpath='{.status.ready}'=true lobjkey $BUCKET --timeout=30s
kubectl -n $NAMESPACE wait --for=jsonpath='{.status.ready}'=true lobj $BUCKET --timeout=30s
- name: Check if the bucket was created
try:
- script:
env:
- name: BUCKET
value: ($bucket)
content: |
set -e
curl -s \
-H "Authorization: Bearer $LINODE_TOKEN" \
-H "Content-Type: application/json" \
"https://api.linode.com/v4/object-storage/buckets/us-sea-1/$BUCKET"
check:
($error): ~
(json_parse($stdout)):
label: ($bucket)
- name: Ensure the access key was created
try:
- script:
env:
- name: URI
value: object-storage/keys
- name: OBJ_KEY
value: ($access_secret)
content: |
set -e
export KEY_ID=$(kubectl -n $NAMESPACE get lobjkey $OBJ_KEY -ojson | jq '.status.accessKeyRef')
curl -s \
-H "Authorization: Bearer $LINODE_TOKEN" \
-H "Content-Type: application/json" \
"https://api.linode.com/v4/$URI/$KEY_ID"
check:
($error): ~
- name: Delete LinodeObjectStorageBucket
try:
- delete:
ref:
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
kind: LinodeObjectStorageBucket
name: ($bucket)
- error:
file: check-lobj-deletion.yaml
- name: Check if the bucket was deleted
try:
- script:
env:
- name: BUCKET
value: ($bucket)
content: |
set -e
curl -s \
-H "Authorization: Bearer $LINODE_TOKEN" \
-H "Content-Type: application/json" \
"https://api.linode.com/v4/object-storage/buckets/us-sea-1/$BUCKET"
check:
($stdout): |-
{"errors": [{"reason": "Not found"}]}