Skip to content

Commit c4ccf22

Browse files
author
Rahul Sharma
committed
add e2e test for premium nodebalancers
1 parent 0970dd9 commit c4ccf22

File tree

3 files changed

+163
-1
lines changed

3 files changed

+163
-1
lines changed

docs/configuration/annotations.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ For implementation details, see:
3232
| `tags` | string | | A comma separated list of tags to be applied to the NodeBalancer instance |
3333
| `firewall-id` | string | | An existing Cloud Firewall ID to be attached to the NodeBalancer instance. See [Firewall Setup](firewall.md) |
3434
| `firewall-acl` | string | | The Firewall rules to be applied to the NodeBalancer. See [Firewall Configuration](#firewall-configuration) |
35-
| `nodebalancer-type` | string | | The type of NodeBalancer to create (options: common, premium) |
35+
| `nodebalancer-type` | string | | The type of NodeBalancer to create (options: common, premium). See [NodeBalancer Types](#nodebalancer-type) |
3636

3737
### Port Specific Configuration
3838

@@ -105,6 +105,14 @@ metadata:
105105
}
106106
```
107107
108+
### NodeBalancer Type
109+
Linode supports nodebalancers of different types: common and premium. By default, nodebalancers of type common are provisioned. If an account is allowed to provision premium nodebalancers and one wants to use them, it can be achieved by specifying the annotation:
110+
```yaml
111+
metadata:
112+
annotations:
113+
service.beta.kubernetes.io/linode-loadbalancer-nodebalancer-type: premium
114+
```
115+
108116
For more examples and detailed configuration options, see:
109117
- [LoadBalancer Configuration](loadbalancer.md)
110118
- [Firewall Configuration](firewall.md)
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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-premium-nb
6+
labels:
7+
all:
8+
spec:
9+
namespace: "lb-premium-nb"
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 that loadbalancer ip is assigned
23+
try:
24+
- assert:
25+
resource:
26+
apiVersion: v1
27+
kind: Service
28+
metadata:
29+
name: svc-test
30+
status:
31+
(loadBalancer.ingress[0].ip != null): true
32+
- name: Fetch loadbalancer ip and check both pods reachable
33+
try:
34+
- script:
35+
content: |
36+
set -e
37+
IP=$(kubectl get svc svc-test -n $NAMESPACE -o json | jq -r .status.loadBalancer.ingress[0].ip)
38+
39+
podnames=()
40+
41+
for i in {1..10}; do
42+
if [[ ${#podnames[@]} -lt 2 ]]; then
43+
output=$(curl -s $IP:80 | jq -e .podName || true)
44+
45+
if [[ "$output" == *"test-"* ]]; then
46+
unique=true
47+
for i in "${array[@]}"; do
48+
if [[ "$i" == "$output" ]]; then
49+
unique=false
50+
break
51+
fi
52+
done
53+
if [[ "$unique" == true ]]; then
54+
podnames+=($output)
55+
fi
56+
fi
57+
else
58+
break
59+
fi
60+
sleep 10
61+
done
62+
63+
if [[ ${#podnames[@]} -lt 2 ]]; then
64+
echo "all pods failed to respond"
65+
else
66+
echo "all pods responded"
67+
fi
68+
check:
69+
($error == null): true
70+
(contains($stdout, 'all pods responded')): true
71+
- name: Check nodebalancer type
72+
try:
73+
- script:
74+
content: |
75+
set -e
76+
77+
nbid=$(KUBECONFIG=$KUBECONFIG NAMESPACE=$NAMESPACE LINODE_TOKEN=$LINODE_TOKEN ../scripts/get-nb-id.sh)
78+
for i in {1..10}; do
79+
type=$(curl -s --request GET \
80+
-H "Authorization: Bearer $LINODE_TOKEN" \
81+
-H "Content-Type: application/json" \
82+
-H "accept: application/json" \
83+
"https://api.linode.com/v4/nodebalancers/${nbid}" | jq -r '.type')
84+
85+
if [[ $type == "premium" ]]; then
86+
echo "nodebalancer type is premium"
87+
break
88+
fi
89+
sleep 5
90+
done
91+
check:
92+
($error == null): true
93+
(contains($stdout, 'nodebalancer type is premium')): true
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
apiVersion: apps/v1
3+
kind: Deployment
4+
metadata:
5+
labels:
6+
app: lb-premium-nb
7+
name: test
8+
spec:
9+
replicas: 2
10+
selector:
11+
matchLabels:
12+
app: lb-premium-nb
13+
template:
14+
metadata:
15+
labels:
16+
app: lb-premium-nb
17+
spec:
18+
affinity:
19+
podAntiAffinity:
20+
preferredDuringSchedulingIgnoredDuringExecution:
21+
- podAffinityTerm:
22+
labelSelector:
23+
matchExpressions:
24+
- key: app
25+
operator: In
26+
values:
27+
- simple-lb
28+
topologyKey: kubernetes.io/hostname
29+
weight: 100
30+
containers:
31+
- image: appscode/test-server:2.3
32+
name: test
33+
ports:
34+
- name: http-1
35+
containerPort: 8080
36+
protocol: TCP
37+
env:
38+
- name: POD_NAME
39+
valueFrom:
40+
fieldRef:
41+
apiVersion: v1
42+
fieldPath: metadata.name
43+
---
44+
apiVersion: v1
45+
kind: Service
46+
metadata:
47+
name: svc-test
48+
annotations:
49+
service.beta.kubernetes.io/linode-loadbalancer-nodebalancer-type: premium
50+
labels:
51+
app: lb-premium-nb
52+
spec:
53+
type: LoadBalancer
54+
selector:
55+
app: lb-premium-nb
56+
ports:
57+
- name: http-1
58+
protocol: TCP
59+
port: 80
60+
targetPort: 8080
61+
sessionAffinity: None

0 commit comments

Comments
 (0)