feat: adding haproxy support #13
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 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-ingress haproxy-ingress/haproxy-ingress \ | |
--set controller.service.type=NodePort \ | |
--set controller.watchIngressWithoutClass=true | |
- name: Wait for HAProxy Ingress | |
run: | | |
echo "Waiting for HAProxy Ingress pods..." | |
kubectl wait --namespace default \ | |
--for=condition=ready pod \ | |
--selector=app.kubernetes.io/instance=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" | |
if [ -n "$headers" ]; then | |
RESP_CODE=$(curl -s -o /dev/null -w "%{http_code}" $headers "$url") | |
else | |
RESP_CODE=$(curl -s -o /dev/null -w "%{http_code}" "$url") | |
fi | |
echo "Response code: $RESP_CODE" | |
if [ "$RESP_CODE" -eq "$expected_code" ]; then | |
return 0 | |
fi | |
if [ "$i" -lt "$MAX_RETRIES" ]; then | |
echo "Waiting ${RETRY_DELAY}s before next attempt..." | |
sleep "$RETRY_DELAY" | |
fi | |
done | |
return 1 | |
} | |
echo "Testing frontend endpoint..." | |
test_endpoint "http://$INGRESS_IP/" 200 || exit 1 | |
echo "Testing backend endpoint..." | |
test_endpoint "http://$INGRESS_IP/v2/docs/" 200 || exit 1 | |
echo "Testing websocket endpoint..." | |
test_endpoint "http://$INGRESS_IP/websocket/" 101 "-H 'Upgrade: websocket' -H 'Connection: Upgrade'" || \ | |
test_endpoint "http://$INGRESS_IP/websocket/" 400 "-H 'Upgrade: websocket' -H 'Connection: Upgrade'" || 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 |