-
Notifications
You must be signed in to change notification settings - Fork 2
/
bootstrap.sh
executable file
·73 lines (57 loc) · 2.93 KB
/
bootstrap.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env bash
set -euo pipefail
CLUSTER_CTL_VERSION="v1.8.1"
CAPO_PROVIDER_VERSION="v0.10.4"
CAPO_ADDON_VERSION="0.5.9"
# Check a clouds.yaml file exists in the same directory as the script
if [ ! -f clouds.yaml ]; then
echo "A clouds.yaml file is required in the same directory as this script"
exit 1
fi
echo "Updating system to apply latest security patches..."
export DEBIAN_FRONTEND=noninteractive
sudo apt-get update -qq
# Shut apt up, since it just blows up the logs
sudo apt-get upgrade -y -qq > /dev/null
echo "Installing required tools..."
sudo apt-get install -y snapd python3-openstackclient
export PATH=$PATH:/snap/bin
sudo snap install kubectl --classic
sudo snap install helm --classic
sudo snap install yq
curl --no-progress-meter -L "https://github.com/kubernetes-sigs/cluster-api/releases/download/${CLUSTER_CTL_VERSION}/clusterctl-linux-amd64" -o clusterctl
chmod +x clusterctl
sudo mv clusterctl /usr/local/bin/clusterctl
# Check that application_credential_id existing in clouds.yaml
# This has to be done after yq is installed
if [ "$(yq -r '.clouds.openstack.auth.application_credential_id' clouds.yaml)" == "null" ]; then
# Enforce the use of app creds
echo "Error: An app cred clouds.yaml file is required in the clouds.yaml file, normal creds (i.e. those with passwords) are not supported"
exit 1
fi
if [ "$(yq -r '.clouds.openstack.auth.project_id' clouds.yaml)" == "null" ]; then
echo "Looking up project_id for clouds.yaml..."
APP_CRED_ID=$(yq -r '.clouds.openstack.auth.application_credential_id' clouds.yaml)
PROJECT_ID=$(openstack --os-cloud openstack application credential show ${APP_CRED_ID} -c project_id -f value)
echo "Injecting project ID: '${PROJECT_ID}' into clouds.yaml..."
injected_id=$PROJECT_ID yq e '.clouds.openstack.auth.project_id = env(injected_id)' -i clouds.yaml
fi
echo "Installing and starting microk8s..."
sudo snap install microk8s --classic
sudo microk8s status --wait-ready
echo "Exporting the kubeconfig file..."
mkdir -p ~/.kube/
sudo microk8s.config > ~/.kube/config
sudo chown $USER ~/.kube/config
sudo chmod 600 ~/.kube/config
sudo microk8s enable dns
echo "Initialising cluster-api OpenStack provider..."
echo "If this fails you may need a GITHUB_TOKEN, see https://stfc.atlassian.net/wiki/spaces/CLOUDKB/pages/211878034/Cluster+API+Setup for details"
clusterctl init --infrastructure=openstack:${CAPO_PROVIDER_VERSION}
echo "Importing required helm repos and packages"
helm repo add capi https://azimuth-cloud.github.io/capi-helm-charts
helm repo add capi-addons https://azimuth-cloud.github.io/cluster-api-addon-provider
helm repo update
helm upgrade cluster-api-addon-provider capi-addons/cluster-api-addon-provider --create-namespace --install --wait -n clusters --version "${CAPO_ADDON_VERSION}"
echo "You are now ready to create a cluster following the remaining instructions..."
echo "https://stfc.atlassian.net/wiki/spaces/CLOUDKB/pages/211878034/Cluster+API+Setup"