Skip to content

Commit

Permalink
Fixed setting of DNS_CLUSTER_IP in bootstrap.sh (#226)
Browse files Browse the repository at this point in the history
* Replaced API calls for deciding DNS_CLUSTER_IP with arg
* Bypass the metadata calls to avoid 404 errors
* Fall back to MAC logic if --dns-cluster-ip is absent
* Updated comment for --dns-cluster-ip
  • Loading branch information
drewhemm authored and Claes Mogren committed Jan 7, 2020
1 parent 388317a commit 4353bbf
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions files/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function print_help {
echo "--enable-docker-bridge Restores the docker default bridge network. (default: false)"
echo "--aws-api-retry-attempts Number of retry attempts for AWS API call (DescribeCluster) (default: 3)"
echo "--docker-config-json The contents of the /etc/docker/daemon.json file. Useful if you want a custom config differing from the default one in the AMI"
echo "--dns-cluster-ip Overrides the IP address to use for DNS queries within the cluster. Defaults to 10.100.0.10 or 172.20.0.10 based on the IP address of the primary interface"
}

POSITIONAL=()
Expand Down Expand Up @@ -79,6 +80,11 @@ while [[ $# -gt 0 ]]; do
shift
shift
;;
--dns-cluster-ip)
DNS_CLUSTER_IP=$2
shift
shift
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
Expand Down Expand Up @@ -262,11 +268,15 @@ sed -i s,CLUSTER_NAME,$CLUSTER_NAME,g /var/lib/kubelet/kubeconfig
sed -i s,MASTER_ENDPOINT,$APISERVER_ENDPOINT,g /var/lib/kubelet/kubeconfig
### kubelet.service configuration

MAC=$(curl -s http://169.254.169.254/latest/meta-data/network/interfaces/macs/ -s | head -n 1 | sed 's/\/$//')
TEN_RANGE=$(curl -s http://169.254.169.254/latest/meta-data/network/interfaces/macs/$MAC/vpc-ipv4-cidr-blocks | grep -c '^10\..*' || true )
DNS_CLUSTER_IP=10.100.0.10
if [[ "$TEN_RANGE" != "0" ]] ; then
DNS_CLUSTER_IP=172.20.0.10;
if [ -z ${DNS_CLUSTER_IP+x} ]; then
MAC=$(curl -s http://169.254.169.254/latest/meta-data/network/interfaces/macs/ -s | head -n 1 | sed 's/\/$//')
TEN_RANGE=$(curl -s http://169.254.169.254/latest/meta-data/network/interfaces/macs/$MAC/vpc-ipv4-cidr-blocks | grep -c '^10\..*' || true )
DNS_CLUSTER_IP=10.100.0.10
if [[ "$TEN_RANGE" != "0" ]]; then
DNS_CLUSTER_IP=172.20.0.10
fi
else
DNS_CLUSTER_IP="${DNS_CLUSTER_IP}"
fi

KUBELET_CONFIG=/etc/kubernetes/kubelet/kubelet-config.json
Expand Down

0 comments on commit 4353bbf

Please sign in to comment.