From 669b9b7460f417969b3defe5e61d15ea9015f6a3 Mon Sep 17 00:00:00 2001 From: Eguzki Astiz Lezaun Date: Thu, 8 Feb 2024 20:49:34 +0100 Subject: [PATCH 1/4] docker-network-ipaddresspool.sh: parse IPv4 discard IPv6 --- Makefile | 4 ++-- utils/docker-network-ipaddresspool.sh | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 812d65b2a..3f33f0538 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..1f7dc6976 100755 --- a/utils/docker-network-ipaddresspool.sh +++ b/utils/docker-network-ipaddresspool.sh @@ -9,23 +9,25 @@ set -euo pipefail networkName=$1 +yq=$2 -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') -cat < Date: Thu, 8 Feb 2024 20:52:05 +0100 Subject: [PATCH 2/4] docker-network-ipaddresspool.sh: little refactor --- utils/docker-network-ipaddresspool.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/docker-network-ipaddresspool.sh b/utils/docker-network-ipaddresspool.sh index 1f7dc6976..60e5ba44a 100755 --- a/utils/docker-network-ipaddresspool.sh +++ b/utils/docker-network-ipaddresspool.sh @@ -16,7 +16,8 @@ yq=$2 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') -echo "--- +cat < Date: Fri, 9 Feb 2024 11:54:19 +0100 Subject: [PATCH 3/4] docker-network-ipaddresspool.sh: little fix --- utils/docker-network-ipaddresspool.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/utils/docker-network-ipaddresspool.sh b/utils/docker-network-ipaddresspool.sh index 60e5ba44a..c59dade12 100755 --- a/utils/docker-network-ipaddresspool.sh +++ b/utils/docker-network-ipaddresspool.sh @@ -29,5 +29,4 @@ apiVersion: metallb.io/v1beta1 kind: L2Advertisement metadata: name: empty - namespace: metallb-system EOF From 8d973b92501047d0916c640e6f2e41ed224df6fc Mon Sep 17 00:00:00 2001 From: Eguzki Astiz Lezaun Date: Tue, 13 Feb 2024 15:05:48 +0100 Subject: [PATCH 4/4] docker-network-ipaddresspool.sh: little enhancements --- Makefile | 2 +- utils/docker-network-ipaddresspool.sh | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 3f33f0538..1690d9527 100644 --- a/Makefile +++ b/Makefile @@ -408,7 +408,7 @@ 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) $(YQ) ## 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 diff --git a/utils/docker-network-ipaddresspool.sh b/utils/docker-network-ipaddresspool.sh index c59dade12..9c4d47390 100755 --- a/utils/docker-network-ipaddresspool.sh +++ b/utils/docker-network-ipaddresspool.sh @@ -9,14 +9,18 @@ set -euo pipefail networkName=$1 -yq=$2 +YQ="${2:-yq}" ## 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') + ${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 <