|
| 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: lb-with-vpc-backends |
| 6 | + labels: |
| 7 | + all: |
| 8 | +spec: |
| 9 | + namespace: "lb-with-vpc-backends" |
| 10 | + steps: |
| 11 | + - name: Create pods and services |
| 12 | + try: |
| 13 | + - apply: |
| 14 | + file: create-pods-services.yaml |
| 15 | + catch: |
| 16 | + - describe: |
| 17 | + apiVersion: v1 |
| 18 | + kind: Pod |
| 19 | + - describe: |
| 20 | + apiVersion: v1 |
| 21 | + kind: Service |
| 22 | + - name: Check endpoints exist |
| 23 | + try: |
| 24 | + - assert: |
| 25 | + resource: |
| 26 | + apiVersion: v1 |
| 27 | + kind: Endpoints |
| 28 | + metadata: |
| 29 | + name: svc-test |
| 30 | + (subsets[0].addresses != null): true |
| 31 | + (subsets[0].ports != null): true |
| 32 | + - name: Check that loadbalancer ip is assigned |
| 33 | + try: |
| 34 | + - assert: |
| 35 | + resource: |
| 36 | + apiVersion: v1 |
| 37 | + kind: Service |
| 38 | + metadata: |
| 39 | + name: svc-test |
| 40 | + status: |
| 41 | + (loadBalancer.ingress[0].ip != null): true |
| 42 | + - name: Check NodeBalancerConfig for backend ips |
| 43 | + try: |
| 44 | + - script: |
| 45 | + content: | |
| 46 | + set -e |
| 47 | +
|
| 48 | + nbid=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh) |
| 49 | +
|
| 50 | + nbconfig=$(curl -s \ |
| 51 | + -H "Authorization: Bearer $LINODE_TOKEN" \ |
| 52 | + -H "Content-Type: application/json" \ |
| 53 | + "https://api.linode.com/v4/nodebalancers/$nbid/configs") |
| 54 | +
|
| 55 | + config_id=$(echo $nbconfig | jq -r '.data[] | select(.port == 80) | .id') |
| 56 | +
|
| 57 | + # Get nodes from the config |
| 58 | + nodes=$(curl -s \ |
| 59 | + -H "Authorization: Bearer $LINODE_TOKEN" \ |
| 60 | + -H "Content-Type: application/json" \ |
| 61 | + "https://api.linode.com/v4/nodebalancers/$nbid/configs/$config_id/nodes") |
| 62 | +
|
| 63 | + # Extract all addresses and remove ports |
| 64 | + addresses=$(echo "$json_data" | jq -r '.data[].address' | sed 's/:[0-9]*$//') |
| 65 | +
|
| 66 | + for ip in $addresses; do |
| 67 | + if [[ $ip =~ ^10\.0\.0\.[0-9]+$ ]]; then |
| 68 | + echo "$ip is in the 10.0.0.0/8 subnet" |
| 69 | + else |
| 70 | + echo "$ip is NOT in the 10.0.0.0/8 subnet" |
| 71 | + fi |
| 72 | + done |
| 73 | + check: |
| 74 | + ($error): ~ |
| 75 | + (contains($stdout, 'is NOT in the 10.0.0.0/8 subnet')): false |
0 commit comments