-
Notifications
You must be signed in to change notification settings - Fork 8
/
common.sh
63 lines (49 loc) · 1.45 KB
/
common.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
57
58
59
60
61
62
63
#!/usr/bin/env bash
# Copyright (c) 2017 Kazuki Suda <[email protected]>
#
# This software is released under the MIT License.
# http://opensource.org/licenses/mit-license.php
MINIKUBE_INGRESS_DNS_DOMAIN=${MINIKUBE_INGRESS_DNS_DOMAIN:-minikube.local}
minikube_ingress_dns() {
if [[ -z "$dnsmasq_config_file" ]]; then
echoerr "dnsmasq_config_file variable is not defined."
exit 1
fi
if ! declare -f write_to_dnsmasq_config_file >/dev/null 2>&1; then
echoerr "write_to_dnsmasq_config_file function is not defined."
exit 1
fi
if ! declare -f restart_dnsmasq >/dev/null 2>&1; then
echoerr "restart_dnsmasq function is not defined."
exit 1
fi
local ip="$(minikube ip)"
[[ -z "$ip" ]] && return
echoinfo "The IP address of running a cluster: ${ip}"
local dnsmasq_config="$(cat <<EOL
bind-interfaces
listen-address=127.0.0.1
port=5354
address=/${MINIKUBE_INGRESS_DNS_DOMAIN}/${ip}
EOL
)"
if [[ "$dnsmasq_config" != "$(cat $dnsmasq_config_file 2>/dev/null)" ]]; then
echoinfo "Configure dnsmasq for ${MINIKUBE_INGRESS_DNS_DOMAIN}..."
echo "$dnsmasq_config" | write_to_dnsmasq_config_file
echoinfo "Restart dnsmasq..."
exe restart_dnsmasq
fi
exe dig +noall +answer "${MINIKUBE_INGRESS_DNS_DOMAIN}" @127.0.0.1 -p 5354
}
exe() {
(set -x; $@)
}
echoinfo() {
echo -n "[minikube-ingress-dns] INFO: "
echo $@
}
echoerr() {
echo -n "[minikube-ingress-dns] ERROR: " >&2
echo $@ >&2
}
# vim: ft=sh ts=2 sts=2 sw=2