|
| 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: route-controller-test |
| 6 | +spec: |
| 7 | + bindings: |
| 8 | + - name: fwname |
| 9 | + value: (join('-', ['ccm-fwtest', env('CLUSTER_NAME')])) |
| 10 | + namespace: "route-controller-test" |
| 11 | + steps: |
| 12 | + - name: Check if CCM is deployed |
| 13 | + try: |
| 14 | + - assert: |
| 15 | + file: ../assert-ccm-resources.yaml |
| 16 | + - name: Check if the route controller updated the config for the linode |
| 17 | + try: |
| 18 | + - script: |
| 19 | + content: | |
| 20 | + set -e |
| 21 | +
|
| 22 | + if [ -z "$KUBECONFIG" ] || [ -z "$LINODE_TOKEN" ]; then |
| 23 | + echo "Error: KUBECONFIG and LINODE_TOKEN environment variables must be set" |
| 24 | + exit 1 |
| 25 | + fi |
| 26 | +
|
| 27 | + # Get all node names |
| 28 | + nodes=$(kubectl get nodes -o jsonpath='{.items[*].metadata.name}') |
| 29 | + if [ -z "$nodes" ]; then |
| 30 | + echo "Error: No nodes found in cluster" |
| 31 | + exit 1 |
| 32 | + fi |
| 33 | +
|
| 34 | + # Process each node |
| 35 | + for node in $nodes; do |
| 36 | + echo "Checking node: $node" |
| 37 | + |
| 38 | + # Get pod CIDR and instance ID |
| 39 | + pod_cidr=$(kubectl get node "$node" -o jsonpath='{.spec.podCIDR}') |
| 40 | + instance_id=$(kubectl get node "$node" -o jsonpath='{.spec.providerID}' | sed 's/linode:\/\///') |
| 41 | + |
| 42 | + echo " Pod CIDR: $pod_cidr" |
| 43 | + echo " Instance ID: $instance_id" |
| 44 | + |
| 45 | + # Get interface details for this config |
| 46 | + interfaces=$(curl -s \ |
| 47 | + -H "Authorization: Bearer $LINODE_TOKEN" \ |
| 48 | + "https://api.linode.com/v4/linode/instances/$instance_id/configs" \ |
| 49 | + | jq -r '.data[0].interfaces') |
| 50 | + |
| 51 | + # Check if pod CIDR is in the VPC interface IP ranges |
| 52 | + if echo "$interfaces" | jq -e --arg cidr "$pod_cidr" '.[] | select(.purpose == "vpc") | .ip_ranges[] | select(. == $cidr)' > /dev/null; then |
| 53 | + echo "Pod CIDR found in VPC interface configuration" |
| 54 | + else |
| 55 | + echo "Pod CIDR not found in VPC interface configuration" |
| 56 | + echo "Current VPC interface configuration:" |
| 57 | + echo "$interfaces" | jq '.[] | select(.purpose == "vpc")' |
| 58 | + fi |
| 59 | + |
| 60 | + echo "---" |
| 61 | + done |
| 62 | +
|
| 63 | + check: |
| 64 | + ($error == null): true |
| 65 | + (contains($stdout, 'Pod CIDR not found in VPC interface configuration')): false |
0 commit comments