Add kubeconfig option (#81)

This commit is contained in:
Iñaki Domínguez Ochoa 2018-08-20 21:28:22 +02:00 committed by Chris O'Haver
parent 5b8ae1cda0
commit 82742c778a

View file

@ -4,7 +4,7 @@
show_help () { show_help () {
cat << USAGE cat << USAGE
usage: $0 [ -r REVERSE-CIDR ] [ -i DNS-IP ] [ -d CLUSTER-DOMAIN ] [ -t YAML-TEMPLATE ] usage: $0 [ -r REVERSE-CIDR ] [ -i DNS-IP ] [ -d CLUSTER-DOMAIN ] [ -t YAML-TEMPLATE ] [ -k KUBECONFIG ]
-r : Define a reverse zone for the given CIDR. You may specifcy this option more -r : Define a reverse zone for the given CIDR. You may specifcy this option more
than once to add multiple reverse zones. If no reverse CIDRs are defined, than once to add multiple reverse zones. If no reverse CIDRs are defined,
@ -21,7 +21,7 @@ YAML_TEMPLATE=`pwd`/coredns.yaml.sed
# Get Opts # Get Opts
while getopts "hr:i:d:t:" opt; do while getopts "hr:i:d:t:k:" opt; do
case "$opt" in case "$opt" in
h) show_help h) show_help
;; ;;
@ -33,16 +33,26 @@ while getopts "hr:i:d:t:" opt; do
;; ;;
t) YAML_TEMPLATE=$OPTARG t) YAML_TEMPLATE=$OPTARG
;; ;;
k) KUBECONFIG=$OPTARG
;;
esac esac
done done
# Set kubeconfig flag if config specified
if [[ ! -z $KUBECONFIG ]]; then
if [[ -f $KUBECONFIG ]]; then
KUBECONFIG="--kubeconfig $KUBECONFIG"
else
KUBECONFIG=""
fi
fi
# Conditional Defaults # Conditional Defaults
if [[ -z $REVERSE_CIDRS ]]; then if [[ -z $REVERSE_CIDRS ]]; then
REVERSE_CIDRS="in-addr.arpa ip6.arpa" REVERSE_CIDRS="in-addr.arpa ip6.arpa"
fi fi
if [[ -z $CLUSTER_DNS_IP ]]; then if [[ -z $CLUSTER_DNS_IP ]]; then
# Default IP to kube-dns IP # Default IP to kube-dns IP
CLUSTER_DNS_IP=$(kubectl get service --namespace kube-system kube-dns -o jsonpath="{.spec.clusterIP}") CLUSTER_DNS_IP=$(kubectl get service --namespace kube-system kube-dns -o jsonpath="{.spec.clusterIP}" $KUBECONFIG)
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
>&2 echo "Error! The IP address for DNS service couldn't be determined automatically. Please specify the DNS-IP with the '-i' option." >&2 echo "Error! The IP address for DNS service couldn't be determined automatically. Please specify the DNS-IP with the '-i' option."
exit 2 exit 2