From fd7add74ac93fdde6eeb9aa47b28b1798cdb54cd Mon Sep 17 00:00:00 2001 From: Drew Walters Date: Mon, 21 Jan 2019 17:30:31 -0600 Subject: [PATCH] Add proxy support to Minikube gate script This commit introduces proxy support to the Minikube gate script by leveraging existing `HTTP_PROXY`, `HTTPS_PROXY`, and `NO_PROXY` environment variables. Additionally, this adds the ability to interpret DNS nameservers when running behind a proxy server and use those in `/etc/resolv.conf` over the Google DNS servers. Change-Id: I508dd00fb7df33945e8ee96af250a8eff9db389a --- tools/deployment/common/005-deploy-k8s.sh | 111 ++++++++++++++-------- 1 file changed, 74 insertions(+), 37 deletions(-) diff --git a/tools/deployment/common/005-deploy-k8s.sh b/tools/deployment/common/005-deploy-k8s.sh index 10948f06a..50509f5c9 100755 --- a/tools/deployment/common/005-deploy-k8s.sh +++ b/tools/deployment/common/005-deploy-k8s.sh @@ -1,6 +1,7 @@ #!/bin/bash # Copyright 2017 The Openstack-Helm Authors. +# Copyright 2019, AT&T Intellectual Property # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain @@ -15,20 +16,50 @@ # under the License. set -xe + : ${HELM_VERSION:="v2.12.3"} : ${KUBE_VERSION:="v1.12.2"} : ${MINIKUBE_VERSION:="v0.30.0"} : ${CALICO_VERSION:="v3.3"} -export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true + +: "${HTTP_PROXY:=""}" + +export DEBCONF_NONINTERACTIVE_SEEN=true +export DEBIAN_FRONTEND=noninteractive + +function configure_resolvconf { + # Setup resolv.conf to use the k8s api server, which is required for the + # kubelet to resolve cluster services. + sudo mv /etc/resolv.conf /etc/resolv.conf.backup + + sudo bash -c "echo 'search svc.cluster.local cluster.local' > /etc/resolv.conf" + sudo bash -c "echo 'nameserver 10.96.0.10' >> /etc/resolv.conf" + + # NOTE(drewwalters96): Use the Google DNS servers to prevent local addresses in + # the resolv.conf file unless using a proxy, then use the existing DNS servers, + # as custom DNS nameservers are commonly required when using a proxy server. + if [ -z "${HTTP_PROXY}" ]; then + sudo bash -c "echo 'nameserver 8.8.8.8' >> /etc/resolv.conf" + sudo bash -c "echo 'nameserver 8.8.4.4' >> /etc/resolv.conf" + else + sed -ne "s/nameserver //p" /etc/resolv.conf.backup | while read -r ns; do + sudo bash -c "echo 'nameserver ${ns}' >> /etc/resolv.conf" + done + fi + + sudo bash -c "echo 'options ndots:5 timeout:1 attempts:1' >> /etc/resolv.conf" + sudo rm /etc/resolv.conf.backup +} # NOTE: Clean Up hosts file -sudo sed -i '/^127.0.0.1/c\127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4' /etc/hosts +sudo sed -i '/^127.0.0.1/c\127.0.0.1 localhost localhost.localdomain localhost4localhost4.localdomain4' /etc/hosts sudo sed -i '/^::1/c\::1 localhost6 localhost6.localdomain6' /etc/hosts -# NOTE: Install required packages on host +# Install required packages for K8s on host sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 460F3994 RELEASE_NAME=$(grep 'CODENAME' /etc/lsb-release | awk -F= '{print $2}') -sudo add-apt-repository "deb https://download.ceph.com/debian-mimic/ ${RELEASE_NAME} main" +sudo add-apt-repository "deb https://download.ceph.com/debian-mimic/ +${RELEASE_NAME} main" sudo -E apt-get update sudo -E apt-get install -y \ docker.io \ @@ -40,34 +71,54 @@ sudo -E apt-get install -y \ nfs-common \ bridge-utils \ libxtables11 -sudo -E tee /etc/modprobe.d/rbd.conf <