-
Notifications
You must be signed in to change notification settings - Fork 10
145 lines (125 loc) · 4.52 KB
/
test-haproxy-ingress.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
name: Test HAProxy Ingress
on:
pull_request:
branches:
- main
workflow_dispatch:
inputs:
debug_enabled:
description: 'Run workflow with debug logging'
required: false
default: false
type: boolean
jobs:
test-haproxy-ingress:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Helm
uses: azure/setup-helm@v3
with:
version: v3.10.3
- uses: actions/setup-python@v4
with:
python-version: 3.11
- name: Install test dependencies
run: |
npm install -g wscat
sudo apt-get update && sudo apt-get install -y curl
- name: Create kind cluster
uses: helm/[email protected]
with:
wait: 600s
config: |
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 80
hostPort: 80
protocol: TCP
- containerPort: 443
hostPort: 443
protocol: TCP
- name: Install HAProxy Ingress Controller
run: |
helm repo add haproxy-ingress https://haproxy-ingress.github.io/charts
helm repo update
helm install haproxy-ingress haproxy-ingress/haproxy-ingress \
--set controller.service.type=NodePort \
--set controller.watchIngressWithoutClass=true
- name: Wait for HAProxy Ingress
run: |
kubectl wait --namespace default \
--for=condition=ready pod \
--selector=app.kubernetes.io/instance=haproxy-ingress \
--timeout=90s
- name: Set up chart-testing
uses: helm/[email protected]
- name: Create test values for haproxy
run: |
cat <<EOF > haproxy-values.yaml
global:
ingress:
enabled: true
className: haproxy
classType: haproxy
websocketPrefix: /websocket
backendPrefix: /v2/docs
frontendPrefix: /
frontend:
enabled: true
backend:
enabled: true
websocket:
enabled: true
EOF
- name: Debug - Show test values
if: ${{ inputs.debug_enabled }}
run: cat haproxy-values.yaml
- name: Run chart-testing install
run: |
ct install --debug --config ct.yaml --namespace default --values haproxy-values.yaml
- name: Wait for the backend pod
run: |
kubectl wait --namespace default \
--for=condition=ready pod \
--selector=app.kubernetes.io/instance=keep,keep-component=backend \
--timeout=90s
- name: Debug - Show pods and services
if: ${{ inputs.debug_enabled }}
run: |
kubectl get pods -A
kubectl get svc -A
kubectl get ingress -A
kubectl describe ingress -A
- name: Test HAProxy Ingress endpoints
run: |
INGRESS_IP="127.0.0.1"
APP_NAME=$(helm list -n default -o json | jq -r '.[0].name')
echo "Testing frontend endpoint..."
RESP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://$INGRESS_IP/)
echo "Frontend response code: $RESP_CODE"
[ "$RESP_CODE" -eq 200 ] || exit 1
echo "Testing backend endpoint..."
RESP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://$INGRESS_IP/v2/docs/)
echo "Backend response code: $RESP_CODE"
[ "$RESP_CODE" -eq 200 ] || exit 1
echo "Testing websocket endpoint..."
RESP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -H "Upgrade: websocket" -H "Connection: Upgrade" http://$INGRESS_IP/websocket/)
echo "WebSocket response code: $RESP_CODE"
[ "$RESP_CODE" -eq 101 ] || [ "$RESP_CODE" -eq 400 ] || exit 1
- name: Debug - Show logs on failure
if: ${{ failure() && inputs.debug_enabled }}
run: |
echo "HAProxy Ingress Controller logs:"
kubectl logs -l app.kubernetes.io/instance=haproxy-ingress -n default --tail=100
echo "Application pods logs:"
for pod in $(kubectl get pods -n default -l app.kubernetes.io/instance=$APP_NAME -o name); do
echo "Logs for $pod:"
kubectl logs $pod -n default --tail=100
done