|
| 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): ~ |
0 commit comments