From e63905302fd4da45471253876df2c4fb45781fbf Mon Sep 17 00:00:00 2001 From: micw523 Date: Tue, 30 Oct 2018 20:40:26 -0500 Subject: [PATCH] Upgrade Travis CI k8s version --- .travis.yml | 2 +- scripts/kube-init.sh | 89 +++++++++++++++++++++++--------------------- 2 files changed, 48 insertions(+), 43 deletions(-) diff --git a/.travis.yml b/.travis.yml index 39d0814741..8747e6e14b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ # ref: https://docs.travis-ci.com/user/languages/python language: python -dist: trusty +dist: xenial sudo: true services: - docker diff --git a/scripts/kube-init.sh b/scripts/kube-init.sh index bcdcb0e21c..58cae869af 100755 --- a/scripts/kube-init.sh +++ b/scripts/kube-init.sh @@ -30,6 +30,11 @@ trap "clean_exit" EXIT # Switch off SE-Linux setenforce 0 +# Mount root to fix dns issues +# Define $HOME since somehow this is not defined +HOME=/home/travis +sudo mount --make-rshared / + # Install docker if needed path_to_executable=$(which docker) if [ -x "$path_to_executable" ] ; then @@ -40,7 +45,7 @@ fi docker --version # Get the latest stable version of kubernetes -export K8S_VERSION=$(curl -sS https://storage.googleapis.com/kubernetes-release/release/stable.txt) +K8S_VERSION=$(curl -sS https://storage.googleapis.com/kubernetes-release/release/stable.txt) echo "K8S_VERSION : ${K8S_VERSION}" echo "Starting docker service" @@ -54,48 +59,48 @@ wget -O kubectl "http://storage.googleapis.com/kubernetes-release/release/${K8S_ sudo chmod +x kubectl sudo mv kubectl /usr/local/bin/ -echo "Download localkube from minikube project" -wget -O localkube "https://storage.googleapis.com/minikube/k8sReleases/v1.7.0/localkube-linux-amd64" -sudo chmod +x localkube -sudo mv localkube /usr/local/bin/ - -echo "Starting localkube" -sudo nohup localkube --logtostderr=true --enable-dns=false > localkube.log 2>&1 & - -echo "Waiting for localkube to start..." -if ! timeout 120 sh -c "while ! curl -ks http://127.0.0.1:8080/ >/dev/null; do sleep 1; done"; then - sudo cat localkube.log - die $LINENO "localkube did not start" +echo "Download minikube from minikube project" +wget -O minikube "https://storage.googleapis.com/minikube/releases/v0.30.0/minikube-linux-amd64" +sudo chmod +x minikube +sudo mv minikube /usr/local/bin/ + +# L68-100: Set up minikube within Travis CI +# See https://github.com/kubernetes/minikube/blob/master/README.md#linux-continuous-integration-without-vm-support +echo "Set up minikube" +export MINIKUBE_WANTUPDATENOTIFICATION=false +export MINIKUBE_WANTREPORTERRORPROMPT=false +export CHANGE_MINIKUBE_NONE_USER=true +sudo mkdir -p $HOME/.kube +sudo mkdir -p $HOME/.minikube +sudo touch $HOME/.kube/config +export KUBECONFIG=$HOME/.kube/config +export MINIKUBE_HOME=$HOME +export MINIKUBE_DRIVER=${MINIKUBE_DRIVER:-none} + +# Used bootstrapper to be kubeadm for the most recent k8s version +# since localkube is depreciated and only supported up to version 1.10.0 +echo "Starting minikube" +sudo minikube start --vm-driver=$MINIKUBE_DRIVER --bootstrapper=kubeadm --kubernetes-version=$K8S_VERSION --logtostderr + +MINIKUBE_OK="false" + +echo "Waiting for minikube to start..." +# this for loop waits until kubectl can access the api server that Minikube has created +for i in {1..90}; do # timeout for 3 minutes + kubectl get po &> /dev/null + if [ $? -ne 1 ]; then + MINIKUBE_OK="true" + break + fi + sleep 2 +done + +# Shut down CI if minikube did not start and show logs +if [ $MINIKUBE_OK == "false" ]; then + sudo minikube logs + die $LINENO "minikube did not start" fi -echo "Check certificate permissions" -sudo chmod 644 /var/lib/localkube/certs/* -sudo ls -altr /var/lib/localkube/certs/ - -echo "Set up .kube/config" -mkdir ~/.kube -cat < ~/.kube/config -apiVersion: v1 -clusters: -- cluster: - insecure-skip-tls-verify: true - server: https://localhost:8443 - name: local -contexts: -- context: - cluster: local - user: myself - name: local -current-context: local -kind: Config -preferences: {} -users: -- name: myself - user: - client-certificate: /var/lib/localkube/certs/apiserver.crt - client-key: /var/lib/localkube/certs/apiserver.key -EOF - echo "Dump Kubernetes Objects..." kubectl get componentstatuses kubectl get configmaps @@ -124,4 +129,4 @@ kubectl get services echo "Running tests..." set -x -e # Yield execution to venv command -$* \ No newline at end of file +$*