|
| 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" |
0 commit comments