#!/usr/bin/env bash source /vagrant/.envrc # Check if MetalLB is already installed by looking for the controller deployment if ! kubectl get deployment -n metallb-system controller &>/dev/null; then echo "Installing MetalLB..." kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/main/config/manifests/metallb-native.yaml if [ $? -ne 0 ]; then echo "Fatal: Failed to apply MetalLB manifest." >&2 exit 1 fi # Wait for MetalLB components to be ready echo "Waiting for MetalLB components to be ready..." kubectl wait --namespace metallb-system \ --for=condition=ready pod \ --selector=app=metallb \ --timeout=90s else echo "MetalLB is already installed." fi # Wait for the webhook service to be ready echo "Waiting for MetalLB webhook service to be ready..." kubectl wait --namespace metallb-system \ --for=condition=ready pod \ --selector=component=webhook \ --timeout=90s # Check if the IPAddressPool already exists if ! kubectl get ipaddresspool -n metallb-system default &>/dev/null; then echo "Creating MetalLB IPAddressPool..." cat </dev/null; then echo "Creating MetalLB L2Advertisement..." cat <