Skip to content

Commit

Permalink
prow: run metallb on kind in multicluster topology (#23363)
Browse files Browse the repository at this point in the history
* prow: run metallb on kind in multicluster topology

* fix lint issues

* last lint issue...

* make cidr_to_ips robust to different envs

* workaround lint

* use variable for cidr param in cidr_to_ips

Co-authored-by: Steven Landow <landow@google.com>
  • Loading branch information
stevenctl and Steven Landow authored Apr 29, 2020
1 parent 5fc58b4 commit a796e54
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions prow/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ EOF
connect_kind_clusters "${CLUSTERI_NAME}" "${CLUSTERI_KUBECONFIG}" "${CLUSTERJ_NAME}" "${CLUSTERJ_KUBECONFIG}"
fi
done
install_metallb "$CLUSTERI_KUBECONFIG"
done
else
# Connect clusters 1 and 2, but leave cluster 3 on a separate network.
Expand All @@ -261,6 +262,49 @@ function connect_kind_clusters() {
docker exec "${C2_NODE}" ip route add "${C1_POD_CIDR}" via "${C1_DOCKER_IP}"
}

function install_metallb() {
KUBECONFIG="${1}"
kubectl apply --kubeconfig="$KUBECONFIG" -f https://raw.githubusercontent.com/metallb/metallb/v0.9.3/manifests/namespace.yaml
kubectl apply --kubeconfig="$KUBECONFIG" -f https://raw.githubusercontent.com/metallb/metallb/v0.9.3/manifests/metallb.yaml

if [ -z "${METALLB_IPS[*]}" ]; then
# Take IPs from the end of the docker bridge network subnet to use for MetalLB IPs
DOCKER_BRIDGE_SUBNET="$(docker inspect bridge | jq .[0].IPAM.Config[0].Subnet -r)"
METALLB_IPS=()
while read -r ip; do
METALLB_IPS+=("$ip")
done < <(cidr_to_ips "$DOCKER_BRIDGE_SUBNET" | tail -n 100)
fi

# Give this cluster of those IPs
RANGE="${METALLB_IPS[0]}-${METALLB_IPS[9]}"
METALLB_IPS=("${METALLB_IPS[@]:10}")

echo 'apiVersion: v1
kind: ConfigMap
metadata:
namespace: metallb-system
name: config
data:
config: |
address-pools:
- name: default
protocol: layer2
addresses:
- '"$RANGE" | kubectl apply --kubeconfig="$KUBECONFIG" -f -
}

function cidr_to_ips() {
CIDR="$1"
if command -v python3; then
python3 - <<EOF
from ipaddress import IPv4Network; [print(str(ip)) for ip in IPv4Network('$CIDR').hosts()]
EOF
elif command -v nmap; then
nmap -sL "$CIDR" | awk '/Nmap scan report/{print $NF}'
fi
}

function cni_run_daemon_kind() {
echo 'Run the CNI daemon set'
ISTIO_CNI_HUB=${ISTIO_CNI_HUB:-gcr.io/istio-testing}
Expand Down

0 comments on commit a796e54

Please sign in to comment.