Skip to content

Commit

Permalink
add e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulait committed Mar 3, 2025
1 parent 257ee06 commit 7d4b6b3
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ create-capl-cluster:
.PHONY: patch-linode-ccm
patch-linode-ccm:
KUBECONFIG=$(KUBECONFIG_PATH) kubectl patch -n kube-system daemonset ccm-linode --type='json' -p="[{'op': 'replace', 'path': '/spec/template/spec/containers/0/image', 'value': '${IMG}'}]"
KUBECONFIG=$(KUBECONFIG_PATH) kubectl patch -n kube-system daemonset ccm-linode --type='json' -p='[{"op": "add", "path": "/spec/template/spec/containers/0/env/-", "value": {"name": "LINODE_API_VERSION", "value": "v4beta"}}]'
KUBECONFIG=$(KUBECONFIG_PATH) kubectl rollout status -n kube-system daemonset/ccm-linode --timeout=600s
KUBECONFIG=$(KUBECONFIG_PATH) kubectl -n kube-system get daemonset/ccm-linode -o yaml

Expand Down
75 changes: 75 additions & 0 deletions e2e/test/lb-with-vpc-backends/chainsaw-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# 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: lb-with-vpc-backends
labels:
all:
spec:
namespace: "lb-with-vpc-backends"
steps:
- name: Create pods and services
try:
- apply:
file: create-pods-services.yaml
catch:
- describe:
apiVersion: v1
kind: Pod
- describe:
apiVersion: v1
kind: Service
- name: Check endpoints exist
try:
- assert:
resource:
apiVersion: v1
kind: Endpoints
metadata:
name: svc-test
(subsets[0].addresses != null): true
(subsets[0].ports != null): true
- name: Check that loadbalancer ip is assigned
try:
- assert:
resource:
apiVersion: v1
kind: Service
metadata:
name: svc-test
status:
(loadBalancer.ingress[0].ip != null): true
- name: Check NodeBalancerConfig for backend ips
try:
- script:
content: |
set -e
nbid=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh)
nbconfig=$(curl -s \
-H "Authorization: Bearer $LINODE_TOKEN" \
-H "Content-Type: application/json" \
"https://api.linode.com/v4/nodebalancers/$nbid/configs")
config_id=$(echo $nbconfig | jq -r '.data[] | select(.port == 80) | .id')
# Get nodes from the config
nodes=$(curl -s \
-H "Authorization: Bearer $LINODE_TOKEN" \
-H "Content-Type: application/json" \
"https://api.linode.com/v4/nodebalancers/$nbid/configs/$config_id/nodes")
# Extract all addresses and remove ports
addresses=$(echo "$json_data" | jq -r '.data[].address' | sed 's/:[0-9]*$//')
for ip in $addresses; do
if [[ $ip =~ ^10\.0\.0\.[0-9]+$ ]]; then
echo "$ip is in the 10.0.0.0/8 subnet"
else
echo "$ip is NOT in the 10.0.0.0/8 subnet"
fi
done
check:
($error): ~
(contains($stdout, 'is NOT in the 10.0.0.0/8 subnet')): false
49 changes: 49 additions & 0 deletions e2e/test/lb-with-vpc-backends/create-pods-services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: vpc-backends
name: test
spec:
replicas: 1
selector:
matchLabels:
app: vpc-backends
template:
metadata:
labels:
app: vpc-backends
spec:
containers:
- image: appscode/test-server:2.3
name: test
ports:
- name: http-1
containerPort: 80
protocol: TCP
env:
- name: POD_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
---
apiVersion: v1
kind: Service
metadata:
name: svc-test
annotations:
service.beta.kubernetes.io/linode-loadbalancer-backend-ipv4-range: "10.100.0.0/30"
labels:
app: vpc-backends
spec:
type: LoadBalancer
selector:
app: vpc-backends
ports:
- name: http-1
protocol: TCP
port: 80
targetPort: 80
sessionAffinity: None

0 comments on commit 7d4b6b3

Please sign in to comment.