Skip to content

Commit

Permalink
Increase metallb useable ips (#584)
Browse files Browse the repository at this point in the history
The number of IPs available to metallb is currently really small (4)
which means you can only create a small number of gateways (3, istio
takes one) before it stops dishing out new IPs.

These changes increase the number of ips to 16 and assumes the network
will always give us a range allowing the use of all 256 ips,
0.0.0.[0-255] (This appears to be the case for kind networks created
with podman(10.89.0.0/24) and docker(172.18.0.0/16)).

Also adds an option to specify an offest (default is 0) when creating a
kuadrant cluster with local-setup allowing multiple instances to be
created using a different range of IPs.

```
make local-setup KIND_CLUSTER_NAME=kuadrant-local-1 SUBNET_OFFSET=0
make local-setup KIND_CLUSTER_NAME=kuadrant-local-2 SUBNET_OFFSET=1
```
  • Loading branch information
mikenairn authored Apr 29, 2024
1 parent c080b1c commit bb66568
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -424,11 +424,12 @@ deploy-dependencies: kustomize dependencies-manifests ## Deploy dependencies to
kubectl -n "$(KUADRANT_NAMESPACE)" wait --timeout=300s --for=condition=Available deployments --all

.PHONY: install-metallb
install-metallb: SUBNET_OFFSET=0
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 $(YQ) | kubectl apply -n metallb-system -f -
./utils/docker-network-ipaddresspool.sh kind $(YQ) ${SUBNET_OFFSET} | kubectl apply -n metallb-system -f -

.PHONY: uninstall-metallb
uninstall-metallb: $(KUSTOMIZE)
Expand Down
15 changes: 12 additions & 3 deletions utils/docker-network-ipaddresspool.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ set -euo pipefail

networkName=$1
YQ="${2:-yq}"
offset=${3:-0}
cidr=28
numIPs=16

## Parse kind network subnet
## Take only IPv4 subnets, exclude IPv6
Expand Down Expand Up @@ -37,11 +40,17 @@ if [[ -z "$SUBNET" ]]; then
exit 1
fi

network=$(echo $SUBNET | cut -d/ -f1)
# shellcheck disable=SC2206
subnetParts=(${SUBNET//./ })
cidr="${subnetParts[0]}.${subnetParts[1]}.0.252/30"
octets=(${network//./ })

cat <<EOF | ADDRESS=$cidr ${YQ} '(select(.kind == "IPAddressPool") | .spec.addresses[0]) = env(ADDRESS)'
# Default values of numIPs:16 and cidr:28 allows up to 16 clusters (offset 0-15) each with 16 possible IPs
# Note: Assumes the network will always give us a range allowing the use of all 256 ips, 0.0.0.[0-255]
address="${octets[0]}.${octets[1]}.${octets[2]}.$((numIPs * offset))/${cidr}"

echo "IPAddressPool address calculated to be '$address' for docker network subnet: '$SUBNET', numIps: '$numIPs' and offset: '$offset'" >&2

cat <<EOF | ADDRESS=$address ${YQ} '(select(.kind == "IPAddressPool") | .spec.addresses[0]) = env(ADDRESS)'
---
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
Expand Down

0 comments on commit bb66568

Please sign in to comment.