-
Notifications
You must be signed in to change notification settings - Fork 14
/
setup-halcyon.sh
executable file
·129 lines (100 loc) · 3.26 KB
/
setup-halcyon.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env bash
set -e
# This script simply sets up the basic defaults for a number of development
# senarios, it is written not to be elegant, but to be portable across a wide
# number of platforms with no addtional requirements other than bash.
: ${HALCYON_GROUP_VARS:="./halcyon-kubernetes/kube-deploy/group_vars/all.yml"}
: ${VAGRANT_VARS:="./config.rb"}
: ${BOOTSTRAP_OS:="ubuntu"}
: ${KUBERNETES_CONFIG:="default"}
: ${KUBERNETES_VERSION:="v1.5.4"}
set +e
if [[ "$OSTYPE" == "darwin"* ]]; then
SED=`which gsed`
if [[ -z "$SED" ]]; then
echo "No suitable sed installed, please install gsed"
exit 1
fi
else
SED=`which sed`
fi
set -e
usage(){
cat <<'EOT'
Call this script with...
--k8s-config (-c) [default|kolla]
--guest-os (-g) [ubuntu|centos]
--k8s-version (-v) [kubernetes version]
EOT
exit 0;
}
# exit if there are no arguments
[ $# -eq 0 ] && usage
# $# is the number of arguments
while [ $# -gt 0 ]
do
case "$1" in
-g|--guest-os) BOOTSTRAP_OS="$2"; shift;;
-c|--k8s-config) KUBERNETES_CONFIG="$2"; shift;;
-v|--k8s-version) KUBERNETES_VERSION="$2"; shift;;
-h| --help) usage;;
--) shift;break;;
*) break;;
esac
shift
done
cleanup_before_exit () {
echo -e "Running cleanup code and exiting"
}
trap cleanup_before_exit EXIT
set_yml_value () {
VARIABLE=$1
VALUE=$2
FILE=$3
$SED -i "/^${VARIABLE}/c\\${VARIABLE}: ${VALUE}" ${FILE}
}
set_rb_value () {
VARIABLE=$1
VALUE=$2
FILE=$3
$SED -i "/^\$${VARIABLE}/c\\\$${VARIABLE} = ${VALUE}" ${FILE}
}
set_kolla_options () {
BOOL_VALUE=$1
for VARIABLE in docker_shared_mounts setup_host_kube_dns setup_host_ceph patch_kube_ceph
do
set_yml_value ${VARIABLE} ${BOOL_VALUE} ${HALCYON_GROUP_VARS}
done
}
echo "Setting up halcyon for: ${BOOTSTRAP_OS} with kubernetes ${KUBERNETES_VERSION} ($KUBERNETES_CONFIG)"
if [[ "$BOOTSTRAP_OS" = "centos" ]]; then
set_rb_value kube_version \"centos/7\" ${VAGRANT_VARS}
set_yml_value bootstrap_os centos ${HALCYON_GROUP_VARS}
set_rb_value public_iface \"eth1\" ${VAGRANT_VARS}
set_yml_value public_iface eth0 ${HALCYON_GROUP_VARS}
set_yml_value nat_iface eth0 ${HALCYON_GROUP_VARS}
set_rb_value ssh_user \"centos\" ${VAGRANT_VARS}
set_rb_value os_image \"centos-7.2\" ${VAGRANT_VARS}
elif [[ "$BOOTSTRAP_OS" = "ubuntu" ]]; then
set_rb_value kube_version \"ubuntu/xenial64\" ${VAGRANT_VARS}
set_yml_value bootstrap_os ubuntu ${HALCYON_GROUP_VARS}
set_rb_value public_iface \"enp0s8\" ${VAGRANT_VARS}
set_yml_value public_iface enp0s3 ${HALCYON_GROUP_VARS}
set_yml_value nat_iface enp0s3 ${HALCYON_GROUP_VARS}
set_rb_value ssh_user \"ubuntu\" ${VAGRANT_VARS}
set_rb_value os_image \"ubuntu-trusty-16.04\" ${VAGRANT_VARS}
fi
if [[ "$KUBERNETES_CONFIG" = "default" ]]; then
set_kolla_options "false"
set_rb_value kube_memory 1024 ${VAGRANT_VARS}
set_rb_value kube_vcpus 1 ${VAGRANT_VARS}
set_rb_value kube_count 3 ${VAGRANT_VARS}
set_rb_value kube_workers \"kube[2:3]\" ${VAGRANT_VARS}
elif [[ "$KUBERNETES_CONFIG" = "kolla" ]]; then
set_kolla_options "true"
set_rb_value kube_memory 2048 ${VAGRANT_VARS}
set_rb_value kube_vcpus 2 ${VAGRANT_VARS}
set_rb_value kube_count 4 ${VAGRANT_VARS}
set_rb_value kube_workers \"kube[2:4]\" ${VAGRANT_VARS}
fi
set_yml_value kube_version ${KUBERNETES_VERSION} ${HALCYON_GROUP_VARS}