Fixed port checking #6
This file contains hidden or 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: End-to-End Test Containerized MetalLB | |
| on: [push, pull_request] | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.21' | |
| - name: Create k8s Kind Cluster | |
| uses: helm/kind-action@v1 | |
| with: | |
| config: kind-config.yaml | |
| - name: Install MetalLB | |
| run: | | |
| kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.7/config/manifests/metallb-native.yaml | |
| kubectl wait --namespace metallb-system \ | |
| --for=condition=ready pod \ | |
| --selector=app=metallb \ | |
| --timeout=90s | |
| DOCKER_SUBNET=$(docker network inspect kind | jq -r '.[0].IPAM.Config[0].Subnet' | cut -d'/' -f1) | |
| echo "Kind network subnet: $DOCKER_SUBNET" | |
| SUBNET_PREFIX=$(echo $DOCKER_SUBNET | cut -d'.' -f1-2) | |
| echo "Subnet prefix: $SUBNET_PREFIX" | |
| cat <<EOF | kubectl apply -f - | |
| apiVersion: metallb.io/v1beta1 | |
| kind: IPAddressPool | |
| metadata: | |
| name: default | |
| namespace: metallb-system | |
| spec: | |
| addresses: | |
| - ${SUBNET_PREFIX}.255.200-${SUBNET_PREFIX}.255.250 | |
| --- | |
| apiVersion: metallb.io/v1beta1 | |
| kind: L2Advertisement | |
| metadata: | |
| name: default | |
| namespace: metallb-system | |
| EOF | |
| - name: Apply manifests | |
| run: | | |
| kubectl apply -f deployment.yaml | |
| kubectl apply -f service.yaml | |
| - name: Wait for LoadBalancer to get external IP | |
| run: | | |
| echo "Waiting for external IP (timeout: 120s)..." | |
| timeout 120s bash -c 'until kubectl get service demo-http-server-service -o jsonpath="{.status.loadBalancer.ingress[0].ip}" | grep -v "null"; do sleep 2; done' || true | |
| EXTERNAL_IP=$(kubectl get service demo-http-server-service -o jsonpath="{.status.loadBalancer.ingress[0].ip}") | |
| if [ -z "$EXTERNAL_IP" ]; then | |
| echo "Failed to get external IP, test will likely fail" | |
| else | |
| echo "Service has external IP: $EXTERNAL_IP" | |
| echo "SERVICE_URL=http://${EXTERNAL_IP}:5000" >> $GITHUB_ENV | |
| echo "Testing connectivity to $EXTERNAL_IP:5000" | |
| timeout 10s curl -v $EXTERNAL_IP:5000 || echo "Direct connection failed, checking network" | |
| # Route to the external IP through Kind network | |
| sudo ip route add ${EXTERNAL_IP}/32 via $(docker network inspect kind -f '{{range .IPAM.Config}}{{.Gateway}}{{end}}') | |
| echo "Added route to $EXTERNAL_IP through Kind network gateway" | |
| echo "Testing connectivity to $EXTERNAL_IP:5000 again after route addition" | |
| curl -v $EXTERNAL_IP:5000 || echo "Connection still failed" | |
| kubectl get svc -A -owide | |
| kubectl describe svc demo-http-server-service | |
| fi | |
| - name: Send GET request and check response | |
| run: | | |
| response=$(curl -s ${{ env.SERVICE_URL }}) | |
| echo "Response: $response" | |
| if [ "$response" == "Hello there!" ]; then | |
| echo "✅ The value received is correct" | |
| else | |
| echo "❌ Received value is incorrect" | |
| exit 1 | |
| fi |