diff --git a/Makefile b/Makefile index 812d65b2a..1690d9527 100644 --- a/Makefile +++ b/Makefile @@ -408,11 +408,11 @@ undeploy-policy-controller: ## Undeploy policy-controller from the K8s cluster s $(KUSTOMIZE) build config/policy-controller | kubectl delete -f - .PHONY: install-metallb -install-metallb: $(KUSTOMIZE) ## Installs the metallb load balancer allowing use of an LoadBalancer type with a gateway +install-metallb: kustomize yq ## Installs the metallb load balancer allowing use of an LoadBalancer type with a gateway $(KUSTOMIZE) build config/metallb | kubectl apply -f - kubectl -n metallb-system wait --for=condition=Available deployments controller --timeout=300s kubectl -n metallb-system wait --for=condition=ready pod --selector=app=metallb --timeout=60s - ./utils/docker-network-ipaddresspool.sh kind | kubectl apply -n metallb-system -f - + ./utils/docker-network-ipaddresspool.sh kind $(YQ) | kubectl apply -n metallb-system -f - .PHONY: uninstall-metallb uninstall-metallb: $(KUSTOMIZE) diff --git a/utils/docker-network-ipaddresspool.sh b/utils/docker-network-ipaddresspool.sh index e7297de57..9c4d47390 100755 --- a/utils/docker-network-ipaddresspool.sh +++ b/utils/docker-network-ipaddresspool.sh @@ -9,20 +9,25 @@ set -euo pipefail networkName=$1 +YQ="${2:-yq}" -subnet=`docker network inspect $networkName -f '{{ (index .IPAM.Config 0).Subnet }}'` -# shellcheck disable=SC2206 -subnetParts=(${subnet//./ }) -cidr="${subnetParts[0]}.${subnetParts[1]}.200.0/24" +## Parse kind network subnet +## Take only IPv4 subnets, exclude IPv6 +SUBNET=$(docker network inspect $networkName --format '{{json .IPAM.Config }}' | \ + ${YQ} '.[] | select( .Subnet | test("^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}/\d+$")) | .Subnet') +if [[ -z "$SUBNET" ]]; then + echo "Error: parsing IPv4 network address for '$networkName' docker network" + exit 1 +fi -cat <