blob: 5aa2b2300d8d6f71542a26ee424155f7f8c99c37 [file] [log] [blame]
Zack Williamsfab10452019-08-15 15:50:29 -07001#!/usr/bin/env bash
2#
3# Copyright 2017-present Open Networking Foundation
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# kubespray-vagrant.sh
18# Bootstraps Vagrant VM's for testing kubernetes-installer scripts
19
20set -eu -o pipefail
21
22# configure git
23if [ ! -e "${HOME}/.gitconfig" ]
24then
25 echo "No ${HOME}/.gitconfig, setting testing defaults..."
26 git config --global user.name 'Test User'
27 git config --global user.email 'test@null.com'
28 git config --global color.ui false
29fi
30
31# install repo if needed
32if [ ! -x "/usr/local/bin/repo" ]
33then
34 echo "Installing repo..."
35
36 REPO_SHA256SUM="394d93ac7261d59db58afa49bb5f88386fea8518792491ee3db8baab49c3ecda"
37 curl -o /tmp/repo 'https://gerrit.opencord.org/gitweb?p=repo.git;a=blob_plain;f=repo;hb=refs/heads/stable'
38 echo "$REPO_SHA256SUM /tmp/repo" | sha256sum -c -
39 sudo cp /tmp/repo /usr/local/bin/repo
40 sudo chmod a+x /usr/local/bin/repo
41fi
42
43# check out cord repo
44if [ ! -d "${HOME}/cord" ]
45then
46 # make sure we can find gerrit.opencord.org as DNS failures will fail the build
47 dig +short gerrit.opencord.org || (echo "ERROR: gerrit.opencord.org can't be looked up in DNS" && exit 1)
48
49 echo "Downloading cord with repo..."
50 pushd "${HOME}"
51 mkdir -p cord
52 cd cord
53 repo init -u https://gerrit.opencord.org/manifest -b master
54 repo sync
55 popd
56fi
57
58# if on cloudlab, format extra space - has to happen before Vagrant install or root will overfill
59"$HOME"/cord/automation-tools/scripts/cloudlab-disksetup.sh
60
61echo "Installing prereqs..."
62sudo apt-get update
63sudo apt-get -y install apt-transport-https build-essential curl git python-dev \
64 python-pip python-virtualenv software-properties-common \
65 sshpass libffi-dev qemu-kvm libvirt-bin libvirt-dev \
66 nfs-kernel-server socat
67
68# Install kubernetes tools (if not installed)
69if [ ! -x "/usr/bin/kubeadm" ]
70then
71
72 cat << EOF | base64 -d > /tmp/k8s-apt-key.gpg
73mQENBFUd6rIBCAD6mhKRHDn3UrCeLDp7U5IE7AhhrOCPpqGF7mfTemZYHf/5JdjxcOxoSFlK
747zwmFr3lVqJ+tJ9L1wd1K6P7RrtaNwCiZyeNPf/Y86AJ5NJwBe0VD0xHTXzPNTqRSByVYtdN
7594NoltXUYFAAPZYQls0x0nUD1hLMlOlC2HdTPrD1PMCnYq/NuL/Vk8sWrcUt4DIS+0RDQ8tK
76Ke5PSV0+PnmaJvdF5CKawhh0qGTklS2MXTyKFoqjXgYDfY2EodI9ogT/LGr9Lm/+u4OFPvmN
779VN6UG+s0DgJjWvpbmuHL/ZIRwMEn/tpuneaLTO7h1dCrXC849PiJ8wSkGzBnuJQUbXnABEB
78AAG0QEdvb2dsZSBDbG91ZCBQYWNrYWdlcyBBdXRvbWF0aWMgU2lnbmluZyBLZXkgPGdjLXRl
79YW1AZ29vZ2xlLmNvbT6JAT4EEwECACgFAlUd6rICGy8FCQWjmoAGCwkIBwMCBhUIAgkKCwQW
80AgMBAh4BAheAAAoJEDdGwginMXsPcLcIAKi2yNhJMbu4zWQ2tM/rJFovazcY28MF2rDWGOnc
819giHXOH0/BoMBcd8rw0lgjmOosBdM2JT0HWZIxC/Gdt7NSRA0WOlJe04u82/o3OHWDgTdm9M
82S42noSP0mvNzNALBbQnlZHU0kvt3sV1YsnrxljoIuvxKWLLwren/GVshFLPwONjw3f9Fan6G
83WxJyn/dkX3OSUGaduzcygw51vksBQiUZLCD2Tlxyr9NvkZYTqiaWW78L6regvATsLc9L/dQU
84iSMQZIK6NglmHE+cuSaoK0H4ruNKeTiQUw/EGFaLecay6Qy/s3Hk7K0QLd+gl0hZ1w1VzIeX
85Lo2BRlqnjOYFX4CwAgADmQENBFrBaNsBCADrF18KCbsZlo4NjAvVecTBCnp6WcBQJ5oSh7+E
8698jX9YznUCrNrgmeCcCMUvTDRDxfTaDJybaHugfba43nqhkbNpJ47YXsIa+YL6eEE9emSmQt
87jrSWIiY+2YJYwsDgsgckF3duqkb02OdBQlh6IbHPoXB6H//b1PgZYsomB+841XW1LSJPYlYb
88IrWfwDfQvtkFQI90r6NknVTQlpqQh5GLNWNYqRNrGQPmsB+NrUYrkl1nUt1LRGu+rCe4bSaS
89mNbwKMQKkROE4kTiB72DPk7zH4Lm0uo0YFFWG4qsMIuqEihJ/9KNX8GYBr+tWgyLooLlsdK3
90l+4dVqd8cjkJM1ExABEBAAG0QEdvb2dsZSBDbG91ZCBQYWNrYWdlcyBBdXRvbWF0aWMgU2ln
91bmluZyBLZXkgPGdjLXRlYW1AZ29vZ2xlLmNvbT6JAT4EEwECACgFAlrBaNsCGy8FCQWjmoAG
92CwkIBwMCBhUIAgkKCwQWAgMBAh4BAheAAAoJEGoDCyG6B/T78e8H/1WH2LN/nVNhm5TS1VYJ
93G8B+IW8zS4BqyozxC9iJAJqZIVHXl8g8a/Hus8RfXR7cnYHcg8sjSaJfQhqO9RbKnffiuQgG
94rqwQxuC2jBa6M/QKzejTeP0Mgi67pyrLJNWrFI71RhritQZmzTZ2PoWxfv6b+Tv5v0rPaG+u
95t1J47pn+kYgtUaKdsJz1umi6HzK6AacDf0C0CksJdKG7MOWsZcB4xeOxJYuy6NuO6KcdEz8/
96XyEUjIuIOlhYTd0hH8E/SEBbXXft7/VBQC5wNq40izPi+6WFK/e1O42DIpzQ749ogYQ1eode
97xPNhLzekKR3XhGrNXJ95r5KO10VrsLFNd8KwAgAD
98EOF
99
100 sudo apt-key add /tmp/k8s-apt-key.gpg
101
102 echo "deb http://apt.kubernetes.io/ kubernetes-$(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
103
104 sudo apt-get update
105
106 sudo apt-get -y install \
107 "kubeadm=1.14.6-*" \
108 "kubelet=1.14.6-*" \
109 "kubectl=1.14.6-*"
110
111 # enable kubectl bash completion
112 echo "source <(kubectl completion bash)" >> ~/.bashrc
113
114fi
115
116# install helm
117if [ ! -x "/usr/local/bin/helm" ]
118then
119 echo "Installing helm..."
120
121 HELM_VERSION="2.14.3"
122 HELM_SHA256SUM="38614a665859c0f01c9c1d84fa9a5027364f936814d1e47839b05327e400bf55"
123 HELM_PLATFORM="linux-amd64"
124 curl -L -o /tmp/helm.tgz "https://storage.googleapis.com/kubernetes-helm/helm-v${HELM_VERSION}-${HELM_PLATFORM}.tar.gz"
125 echo "$HELM_SHA256SUM /tmp/helm.tgz" | sha256sum -c -
126 pushd /tmp
127 tar -xzvf helm.tgz
128 sudo cp ${HELM_PLATFORM}/helm /usr/local/bin/helm
129 sudo chmod a+x /usr/local/bin/helm
130 rm -rf helm.tgz ${HELM_PLATFORM}
131 popd
132
133 helm init --client-only
134 helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/
135
136 echo "source <(helm completion bash)" >> ~/.bashrc
137fi
138
139# install vagrant
140if [ ! -x "/usr/bin/vagrant" ]
141then
142 echo "Installing vagrant and associated tools..."
143
144 VAGRANT_VERSION="2.2.5"
145 VAGRANT_SHA256SUM="415f50b93235e761db284c761f6a8240a6ef6762ee3ec7ff869d2bccb1a1cdf7"
146 curl -o /tmp/vagrant.deb https://releases.hashicorp.com/vagrant/${VAGRANT_VERSION}/vagrant_${VAGRANT_VERSION}_x86_64.deb
147 echo "$VAGRANT_SHA256SUM /tmp/vagrant.deb" | sha256sum -c -
148 sudo dpkg -i /tmp/vagrant.deb
149fi
150
151echo "Installing vagrant plugins if needed..."
152VAGRANT_LIBVIRT_VERSION="0.0.45"
153vagrant plugin list | grep -q vagrant-libvirt || vagrant plugin install vagrant-libvirt --plugin-version ${VAGRANT_LIBVIRT_VERSION}
154vagrant plugin list | grep -q vagrant-mutate || vagrant plugin install vagrant-mutate
155
156echo "Obtaining libvirt image of Ubuntu"
157UBUNTU_VERSION=${UBUNTU_VERSION:-bento/ubuntu-16.04}
158vagrant box list | grep "${UBUNTU_VERSION}" | grep virtualbox || vagrant box add --provider virtualbox "${UBUNTU_VERSION}"
159vagrant box list | grep "${UBUNTU_VERSION}" | grep libvirt || vagrant mutate "${UBUNTU_VERSION}" libvirt --input-provider virtualbox
160
161echo "DONE! 'cd ~/cord/automation-tools/kubespray-installer && vagrant up' to start the VMs"
162