Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[testing] E2E test case for VPC route controller #280

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading