-
Notifications
You must be signed in to change notification settings - Fork 10
237 lines (199 loc) · 7.84 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
name: Test HAProxy Ingress
on:
pull_request:
branches:
- main
workflow_dispatch:
inputs:
debug_enabled:
description: 'Run workflow with debug logging'
required: false
default: true
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 config
run: |
cat <<-EOF > kind-config.yaml
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
EOF
- name: Create kind cluster
uses: helm/[email protected]
with:
wait: 600s
config: kind-config.yaml
- name: Install HAProxy Ingress Controller
run: |
helm repo add haproxy-ingress https://haproxy-ingress.github.io/charts
helm repo update
helm install haproxy haproxy-ingress/haproxy-ingress \
--set controller.service.type=NodePort \
--set controller.kind=DaemonSet \
--set controller.daemonset.useHostPort=true \
--set controller.service.ports.http=80 \
--set controller.service.ports.https=443 \
--set controller.service.ports.stat=30024
- name: Wait for HAProxy Ingress
run: |
echo "Waiting for HAProxy Ingress pods..."
kubectl wait --namespace default \
--for=condition=ready pod \
--selector=app.kubernetes.io/name=haproxy-ingress \
--timeout=120s
- name: Set up chart-testing
uses: helm/[email protected]
- name: Create test values for haproxy
run: |
mkdir -p debug
cat <<EOF > debug/haproxy-values.yaml
global:
ingress:
enabled: true
className: haproxy
classType: haproxy
websocketPrefix: /websocket
backendPrefix: /v2
frontendPrefix: /
frontend:
enabled: true
backend:
enabled: true
websocket:
enabled: true
EOF
- name: Debug - Show test values
if: ${{ inputs.debug_enabled }}
run: cat debug/haproxy-values.yaml
- name: Install Keep chart
run: |
helm install keep ./charts/keep -f debug/haproxy-values.yaml
- name: Wait for all pods
run: |
echo "Waiting for all pods to be ready..."
kubectl wait --for=condition=ready pod --all -n default --timeout=180s
echo "Checking pod status..."
kubectl get pods -n default
echo "Checking ingress status..."
kubectl get ingress -n default
echo "Waiting additional 30s for services to stabilize..."
sleep 30
- name: Verify services and endpoints
run: |
echo "Service Status:"
kubectl get svc -n default
echo "Endpoint Status:"
kubectl get endpoints -n default
echo "Ingress Details:"
kubectl describe ingress -n default
- name: Test HAProxy Ingress endpoints
run: |
INGRESS_IP="127.0.0.1"
APP_NAME=$(helm list -n default -o json | jq -r '.[0].name')
MAX_RETRIES=5
RETRY_DELAY=10
test_endpoint() {
local url=$1
local expected_code=$2
local headers=${3:-""}
for ((i=1; i<=MAX_RETRIES; i++)); do
echo "Attempt $i of $MAX_RETRIES for $url"
echo "Headers being sent: $headers"
if [ -n "$headers" ]; then
echo "Full curl command: curl -v $headers \"$url\""
RESP=$(curl -v $headers "$url" 2>&1)
else
echo "Full curl command: curl -v \"$url\""
RESP=$(curl -v "$url" 2>&1)
fi
# Extract response code, handling connection failures
RESP_CODE=$(echo "$RESP" | grep "< HTTP" | awk '{print $3}')
if [ -z "$RESP_CODE" ]; then
echo "⚠️ No response code received - connection may have failed"
echo -e "\n🔍 Response Details:"
echo "------------------------"
echo "Response code: Connection failed"
echo -e "\n📋 Response Headers:"
echo "$RESP" | grep -E "^< " || echo "No headers found"
echo -e "\n📝 Response Body:"
echo "$RESP" | sed -n '/^* Connected/,/^* Connection/!p' | grep -v "^[*<>]" || echo "No body found"
echo "------------------------"
if [ "$i" -lt "$MAX_RETRIES" ]; then
echo "⏳ Waiting ${RETRY_DELAY}s before next attempt..."
sleep "$RETRY_DELAY"
continue
fi
echo "❌ Failed to establish connection after $MAX_RETRIES attempts"
return 1
fi
echo -e "\n🔍 Response Details:"
echo "------------------------"
echo "Response code: $RESP_CODE"
echo -e "\n📋 Response Headers:"
echo "$RESP" | grep -E "^< " || echo "No headers found"
echo -e "\n📝 Response Body:"
echo "$RESP" | sed -n '/^* Connected/,/^* Connection/!p' | grep -v "^[*<>]" || echo "No body found"
echo "------------------------"
if [ "$RESP_CODE" -eq "$expected_code" ]; then
echo "✅ Expected response code $expected_code received"
return 0
fi
if [ "$i" -lt "$MAX_RETRIES" ]; then
echo "⏳ Waiting ${RETRY_DELAY}s before next attempt..."
sleep "$RETRY_DELAY"
fi
done
echo "❌ Failed to get expected response code $expected_code after $MAX_RETRIES attempts"
return 1
}
echo "🌐 Testing frontend endpoint..."
test_endpoint "http://$INGRESS_IP/" 307 || exit 1
echo "🔌 Testing backend endpoint..."
test_endpoint "http://$INGRESS_IP/v2/docs" 200 || exit 1
echo "🔄 Testing websocket endpoint..."
# should return "OK"
test_endpoint "http://$INGRESS_IP/websocket/" 200 || exit 1
- name: Debug - Show logs on failure
if: ${{ failure() }}
run: |
echo "HAProxy Ingress Controller logs:"
kubectl logs -l app.kubernetes.io/instance=haproxy-ingress -n default --tail=100
echo "All pods status:"
kubectl get pods -n default -o wide
echo "Application pods logs:"
for pod in $(kubectl get pods -n default -o name); do
echo "Logs for $pod:"
kubectl logs $pod -n default --tail=100 || true
done
echo "Ingress configuration:"
kubectl get ingress -n default -o yaml
echo "Endpoints:"
kubectl get endpoints -n default
echo "Services:"
kubectl get svc -n default