-
Notifications
You must be signed in to change notification settings - Fork 1
/
metallb.sh
56 lines (44 loc) · 1.52 KB
/
metallb.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env bash
# get script source
SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
ROOT_DIR="${SOURCE_DIR}/.."
DEP_DIR="${ROOT_DIR}/deps"
ENV_FILE="${ENV_FILE:-"${ROOT_DIR}/.env"}"
# source project files
if [ -f "${ENV_FILE}" ]; then
source "${ENV_FILE}"
fi
source "${SOURCE_DIR}/utils.sh"
# env variables
env_variables=()
# ================= DO NOT EDIT BEYOND THIS LINE =================
# get private IPv4 addresses from user input
ipv4_addresses=($(get_values "private IPv4 address"))
# get user confirmation
print_title "metallb"
confirm_values "${env_variables[@]}"
confirm="${?}"
if [ "${confirm}" -ne 0 ]; then
exit "${confirm}"
fi
# validate number of IPv4 addresses
if [ "${#ipv4_addresses[@]}" -lt 1 ]; then
echo "ERROR: There must be at least 1 private IPv4 address"
exit 1
fi
# install metallb
# source: https://raw.githubusercontent.com/metallb/metallb/v0.13.9/config/manifests/metallb-native.yaml
kubectl apply -f "${DEP_DIR}/metallb/metallb-native.yaml"
# wait until no pods are pending
wait_for_pods metallb-system
# copy metallb-configuration.yaml to home directory
cp -f "${DEP_DIR}/metallb/metallb-configuration.yaml" ~
# replace {{ IPv4_RANGE }} in metallb-configuration.yaml
if [ "${#ipv4_addresses[@]}" -eq 1 ]; then
ipv4_range="${ipv4_addresses[0]}"
else
ipv4_range="${ipv4_addresses[0]}-${ipv4_addresses[-1]}"
fi
sed -i "s/{{ IPv4_RANGE }}/${ipv4_range}/g" ~/metallb-configuration.yaml
# apply metallb-configuration.yaml
kubectl apply -f ~/metallb-configuration.yaml