Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance docker network ipaddresspool #418

Merged
merged 4 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 12 additions & 7 deletions utils/docker-network-ipaddresspool.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF
cat <<EOF | ADDRESS=$SUBNET ${YQ} '(select(.kind == "IPAddressPool") | .spec.addresses[0]) = env(ADDRESS)'
---
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: kuadrant-local
spec:
addresses:
- $cidr
addresses: [] # set by make target
---
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
Expand Down
Loading