From 09ca2789e639c95743ba42fb6e298ca350b6a0f4 Mon Sep 17 00:00:00 2001 From: Jim Fitzpatrick Date: Fri, 19 Apr 2024 14:53:31 +0100 Subject: [PATCH 1/2] Make selection of subnet using docker more flexible. --- utils/docker-network-ipaddresspool.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/docker-network-ipaddresspool.sh b/utils/docker-network-ipaddresspool.sh index 4d77da7e6..68a84ddc5 100755 --- a/utils/docker-network-ipaddresspool.sh +++ b/utils/docker-network-ipaddresspool.sh @@ -29,7 +29,7 @@ set -e # Fallback to docker version of cmd if [[ -z "$SUBNET" ]]; then - SUBNET=$(docker network inspect $networkName -f '{{ (index .IPAM.Config 0).Subnet }}') + SUBNET=$(docker network inspect $networkName | ${YQ} e '.[] | select(.IPAM.Config[] | has("Gateway")) | .IPAM.Config[] | select(has("Gateway")) | .Subnet' -) fi # Neither worked, error out if [[ -z "$SUBNET" ]]; then From e6d104a6ea88439df357c2cd8399a2c424cde1c7 Mon Sep 17 00:00:00 2001 From: Jim Fitzpatrick Date: Mon, 22 Apr 2024 12:35:50 +0100 Subject: [PATCH 2/2] Use Regex to find the IP address --- utils/docker-network-ipaddresspool.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/docker-network-ipaddresspool.sh b/utils/docker-network-ipaddresspool.sh index 68a84ddc5..364072c80 100755 --- a/utils/docker-network-ipaddresspool.sh +++ b/utils/docker-network-ipaddresspool.sh @@ -29,7 +29,7 @@ set -e # Fallback to docker version of cmd if [[ -z "$SUBNET" ]]; then - SUBNET=$(docker network inspect $networkName | ${YQ} e '.[] | select(.IPAM.Config[] | has("Gateway")) | .IPAM.Config[] | select(has("Gateway")) | .Subnet' -) + 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') fi # Neither worked, error out if [[ -z "$SUBNET" ]]; then