Skip to content

Commit

Permalink
[testing] E2E test case for VPC route controller (#280)
Browse files Browse the repository at this point in the history
* Add the chainsaw test

* Address comment
  • Loading branch information
komer3 authored Dec 19, 2024
1 parent e3e4997 commit 51eaadd
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions e2e/test/route-controller-test/chainsaw-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# 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: route-controller-test
spec:
bindings:
- name: fwname
value: (join('-', ['ccm-fwtest', env('CLUSTER_NAME')]))
namespace: "route-controller-test"
steps:
- name: Check if CCM is deployed
try:
- assert:
file: ../assert-ccm-resources.yaml
- name: Check if the route controller updated the config for the linode
try:
- script:
content: |
set -e
if [ -z "$KUBECONFIG" ] || [ -z "$LINODE_TOKEN" ]; then
echo "Error: KUBECONFIG and LINODE_TOKEN environment variables must be set"
exit 1
fi
# Get all node names
nodes=$(kubectl get nodes -o jsonpath='{.items[*].metadata.name}')
if [ -z "$nodes" ]; then
echo "Error: No nodes found in cluster"
exit 1
fi
# Process each node
for node in $nodes; do
echo "Checking node: $node"
# Get pod CIDR and instance ID
pod_cidr=$(kubectl get node "$node" -o jsonpath='{.spec.podCIDR}')
instance_id=$(kubectl get node "$node" -o jsonpath='{.spec.providerID}' | sed 's/linode:\/\///')
echo " Pod CIDR: $pod_cidr"
echo " Instance ID: $instance_id"
# Get interface details for this config
interfaces=$(curl -s \
-H "Authorization: Bearer $LINODE_TOKEN" \
"https://api.linode.com/v4/linode/instances/$instance_id/configs" \
| jq -r '.data[0].interfaces')
# Check if pod CIDR is in the VPC interface IP ranges
if echo "$interfaces" | jq -e --arg cidr "$pod_cidr" '.[] | select(.purpose == "vpc") | .ip_ranges[] | select(. == $cidr)' > /dev/null; then
echo "Pod CIDR found in VPC interface configuration"
else
echo "Pod CIDR not found in VPC interface configuration"
echo "Current VPC interface configuration:"
echo "$interfaces" | jq '.[] | select(.purpose == "vpc")'
fi
echo "---"
done
check:
($error == null): true
(contains($stdout, 'Pod CIDR not found in VPC interface configuration')): false

0 comments on commit 51eaadd

Please sign in to comment.