Skip to content

Fixed port checking

Fixed port checking #5

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
# Apply MetalLB config for automatic IP assignment
cat <<EOF | kubectl apply -f -
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: default
namespace: metallb-system
spec:
addresses:
- 192.168.1.240-192.168.1.250
---
apiVersion: metallb.io/v1beta1
kind: BGPAdvertisement
metadata:
name: example
namespace: metallb-system
spec:
communities:
- no-export
ipAddressPools:
- default
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
kubectl get svc -A -owide
kubectl describe svc demo-http-server-service
sleep 10
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