Skip to content

Commit 7d4b6b3

Browse files
author
Rahul Sharma
committed
add e2e test
1 parent 257ee06 commit 7d4b6b3

File tree

3 files changed

+125
-0
lines changed

3 files changed

+125
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ create-capl-cluster:
162162
.PHONY: patch-linode-ccm
163163
patch-linode-ccm:
164164
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}'}]"
165+
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"}}]'
165166
KUBECONFIG=$(KUBECONFIG_PATH) kubectl rollout status -n kube-system daemonset/ccm-linode --timeout=600s
166167
KUBECONFIG=$(KUBECONFIG_PATH) kubectl -n kube-system get daemonset/ccm-linode -o yaml
167168

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
apiVersion: apps/v1
3+
kind: Deployment
4+
metadata:
5+
labels:
6+
app: vpc-backends
7+
name: test
8+
spec:
9+
replicas: 1
10+
selector:
11+
matchLabels:
12+
app: vpc-backends
13+
template:
14+
metadata:
15+
labels:
16+
app: vpc-backends
17+
spec:
18+
containers:
19+
- image: appscode/test-server:2.3
20+
name: test
21+
ports:
22+
- name: http-1
23+
containerPort: 80
24+
protocol: TCP
25+
env:
26+
- name: POD_NAME
27+
valueFrom:
28+
fieldRef:
29+
apiVersion: v1
30+
fieldPath: metadata.name
31+
---
32+
apiVersion: v1
33+
kind: Service
34+
metadata:
35+
name: svc-test
36+
annotations:
37+
service.beta.kubernetes.io/linode-loadbalancer-backend-ipv4-range: "10.100.0.0/30"
38+
labels:
39+
app: vpc-backends
40+
spec:
41+
type: LoadBalancer
42+
selector:
43+
app: vpc-backends
44+
ports:
45+
- name: http-1
46+
protocol: TCP
47+
port: 80
48+
targetPort: 80
49+
sessionAffinity: None

0 commit comments

Comments
 (0)