Skip to content

Commit

Permalink
Merge branch 'main' into fix/database-setup
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas Lamirault <[email protected]>
  • Loading branch information
nlamirault authored Dec 12, 2024
2 parents 0c4b683 + f9c3afb commit 65224c8
Show file tree
Hide file tree
Showing 7 changed files with 500 additions and 4 deletions.
224 changes: 224 additions & 0 deletions .github/workflows/test-traefik-ingress.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
name: Test Traefik 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-traefik-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: 30080
hostPort: 30080
protocol: TCP
- containerPort: 443
hostPort: 443
protocol: TCP
EOF
- name: Debug kind config
if: ${{ inputs.debug_enabled }}
run: cat kind-config.yaml

- name: Create kind cluster
uses: helm/[email protected]
with:
wait: 600s
config: kind-config.yaml

- name: Install Traefik
run: |
helm repo add traefik https://traefik.github.io/charts
helm repo update
helm install traefik traefik/traefik \
--set installCRDs=true \
--set ports.web.port=8000 \
--set ports.web.exposedPort=80 \
--set ports.web.nodePort=30080 \
--set service.type=NodePort \
--set ingressClass.enabled=true \
--set ingressClass.isDefaultClass=true
- name: Wait for Traefik
run: |
echo "Waiting for Traefik pods..."
kubectl wait --namespace default \
--for=condition=ready pod \
--selector=app.kubernetes.io/name=traefik \
--timeout=90s
- name: Create test values for traefik
run: |
mkdir -p debug
cat <<EOF > debug/traefik-values.yaml
global:
ingress:
enabled: true
className: traefik
classType: traefik
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/traefik-values.yaml

- name: Install Keep chart
run: |
helm install keep ./charts/keep -f debug/traefik-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: Debug - Show resources
if: ${{ inputs.debug_enabled }}
run: |
echo "🔍 Checking all resources..."
kubectl get pods -A
kubectl get svc -A
kubectl get ingress -A
kubectl describe ingress -A
- name: Test 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:30080/" 307 || exit 1
echo "🔌 Testing backend endpoint..."
test_endpoint "http://$INGRESS_IP:30080/v2/docs" 200 || exit 1
echo "🔄 Testing websocket endpoint..."
test_endpoint "http://$INGRESS_IP:30080/websocket/" 200 || exit 1
- name: Debug - Show logs on failure
if: ${{ failure() && inputs.debug_enabled }}
run: |
echo "📜 Traefik Controller logs:"
kubectl logs -l app.kubernetes.io/name=traefik --tail=100
echo "Application pods logs:"
for pod in $(kubectl get pods -n default -l app.kubernetes.io/instance=keep -o name); do
echo "Logs for $pod:"
kubectl logs $pod --tail=100
done
4 changes: 2 additions & 2 deletions charts/keep/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
apiVersion: v2
name: keep
version: 0.1.45
version: 0.1.47
description: Keep Helm Chart
type: application
icon: https://platform.keephq.dev/_next/image?url=%2Fkeep.png&w=48&q=75
appVersion: 0.30.7
appVersion: 0.31.7
deprecated: false
annotations:
app: keep
Expand Down
14 changes: 14 additions & 0 deletions charts/keep/templates/ingress-traefik-middleware.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{- if and .Values.global.ingress.enabled (or (eq .Values.global.ingress.className "traefik") (eq .Values.global.ingress.classType "traefik")) }}
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: strip-prefix
namespace: {{ .Release.Namespace }}
labels:
{{- include "keep.labels" . | nindent 4 }}
spec:
stripPrefix:
prefixes:
- {{ .Values.global.ingress.backendPrefix }}
- {{ .Values.global.ingress.websocketPrefix }}
{{- end }}
96 changes: 96 additions & 0 deletions charts/keep/templates/ingress-traefik.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{{- if and .Values.global.ingress.enabled (or (eq .Values.global.ingress.className "traefik") (eq .Values.global.ingress.classType "traefik")) }}
{{- $fullName := include "keep.fullname" . }}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ $fullName }}-ingress
labels:
{{- include "keep.labels" . | nindent 4 }}
annotations:
traefik.ingress.kubernetes.io/router.middlewares: {{ .Release.Namespace }}-strip-prefix@kubernetescrd
traefik.ingress.kubernetes.io/router.entrypoints: web
traefik.ingress.kubernetes.io/timeouts.idle: "3600s"
traefik.ingress.kubernetes.io/timeouts.connect: "3600s"
traefik.ingress.kubernetes.io/timeouts.read: "3600s"
traefik.ingress.kubernetes.io/timeouts.write: "3600s"

# WebSocket configuration
traefik.ingress.kubernetes.io/websockets.enabled: "true"
{{- with .Values.global.ingress.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}

spec:
ingressClassName: traefik
{{- if .Values.global.ingress.tls }}
tls:
{{- range .Values.global.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- if .Values.global.ingress.hosts }}
{{- range .Values.global.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- if $.Values.websocket.enabled }}
- path: {{ $.Values.global.ingress.websocketPrefix }}
pathType: Prefix
backend:
service:
name: {{ $fullName }}-websocket
port:
number: {{ $.Values.websocket.service.port }}
{{- end }}
{{- if $.Values.backend.enabled }}
- path: {{ $.Values.global.ingress.backendPrefix }}
pathType: Prefix
backend:
service:
name: {{ $fullName }}-backend
port:
number: {{ $.Values.backend.service.port }}
{{- end }}
- path: "/"
pathType: Prefix
backend:
service:
name: {{ $fullName }}-frontend
port:
number: {{ $.Values.frontend.service.port }}
{{- end }}
{{- else }}
- http:
paths:
{{- if $.Values.websocket.enabled }}
- path: {{ $.Values.global.ingress.websocketPrefix }}
pathType: Prefix
backend:
service:
name: {{ $fullName }}-websocket
port:
number: {{ $.Values.websocket.service.port }}
{{- end }}
{{- if $.Values.backend.enabled }}
- path: {{ $.Values.global.ingress.backendPrefix }}
pathType: Prefix
backend:
service:
name: {{ $fullName }}-backend
port:
number: {{ $.Values.backend.service.port }}
{{- end }}
- path: "/"
pathType: Prefix
backend:
service:
name: {{ $fullName }}-frontend
port:
number: {{ $.Values.frontend.service.port }}
{{- end }}
{{- end }}
2 changes: 1 addition & 1 deletion local_test_haproxy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ global:
annotations:
ingress.class: haproxy
websocketPrefix: /websocket
backendPrefix: /v2/docs
backendPrefix: /v2
frontendPrefix: /
frontend:
enabled: true
Expand Down
2 changes: 1 addition & 1 deletion local_test_nginx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ global:
className: nginx
classType: nginx
websocketPrefix: /websocket
backendPrefix: /v2/docs
backendPrefix: /v2
frontendPrefix: /
frontend:
enabled: true
Expand Down
Loading

0 comments on commit 65224c8

Please sign in to comment.