This change factors reusable functionality out of the vagrant provision
scripts into a utility script (provision-util.sh) to make maintenance
easier.
... | ... |
@@ -155,7 +155,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| |
155 | 155 |
minion_ip = minion_ips[n] |
156 | 156 |
minion.vm.box = kube_box[kube_os]["name"] |
157 | 157 |
minion.vm.box_url = kube_box[kube_os]["box_url"] |
158 |
- minion.vm.provision "shell", inline: "/vagrant/vagrant/provision-minion.sh #{master_ip} #{num_minion} #{minion_ips_str} #{minion_ip} #{minion_index} #{ENV['OPENSHIFT_SDN']}" |
|
158 |
+ minion.vm.provision "shell", inline: "/vagrant/vagrant/provision-minion.sh #{master_ip} #{num_minion} #{minion_ips_str} #{minion_ip} #{minion_index}" |
|
159 | 159 |
minion.vm.network "private_network", ip: "#{minion_ip}" |
160 | 160 |
minion.vm.hostname = "openshift-minion-#{minion_index}" |
161 | 161 |
end |
... | ... |
@@ -1,10 +1,21 @@ |
1 | 1 |
#!/bin/bash |
2 |
-set -e |
|
2 |
+ |
|
3 |
+set -o errexit |
|
4 |
+set -o nounset |
|
5 |
+set -o pipefail |
|
6 |
+ |
|
7 |
+ORIGIN_ROOT=$( |
|
8 |
+ unset CDPATH |
|
9 |
+ origin_root=$(dirname "${BASH_SOURCE}")/.. |
|
10 |
+ cd "${origin_root}" |
|
11 |
+ pwd |
|
12 |
+) |
|
13 |
+source ${ORIGIN_ROOT}/vagrant/provision-util.sh |
|
3 | 14 |
|
4 | 15 |
# Passed as arguments to provisioning from Vagrantfile |
5 |
-MASTER_IP=$1 |
|
6 |
-NUM_MINIONS=$2 |
|
7 |
-MINION_IPS=$3 |
|
16 |
+MASTER_IP=${1:-""} |
|
17 |
+NUM_MINIONS=${2:-""} |
|
18 |
+MINION_IPS=${3:-""} |
|
8 | 19 |
|
9 | 20 |
INSTANCE_PREFIX=openshift |
10 | 21 |
MASTER_NAME="${INSTANCE_PREFIX}-master" |
... | ... |
@@ -3,86 +3,38 @@ |
3 | 3 |
set -ex |
4 | 4 |
source $(dirname $0)/provision-config.sh |
5 | 5 |
|
6 |
-OPENSHIFT_SDN=$4 |
|
7 |
-if [ "${OPENSHIFT_SDN}" == "redhat/openshift-ovs-multitenant" ] || [ "${OPENSHIFT_SDN}" == "redhat/openshift-ovs-subnet" ] || [ "${OPENSHIFT_SDN}" == "" ]; then |
|
8 |
- OPENSHIFT_SDN_PLUGIN=${OPENSHIFT_SDN} |
|
9 |
-fi |
|
10 |
-OPENSHIFT_SDN_PLUGIN=${OPENSHIFT_SDN_PLUGIN:-redhat/openshift-ovs-subnet} |
|
6 |
+NETWORK_PLUGIN=$(os::util::get-network-plugin ${4:-""}) |
|
11 | 7 |
|
12 | 8 |
NETWORK_CONF_PATH=/etc/sysconfig/network-scripts/ |
13 | 9 |
sed -i 's/^NM_CONTROLLED=no/#NM_CONTROLLED=no/' ${NETWORK_CONF_PATH}ifcfg-eth1 |
14 | 10 |
|
15 | 11 |
systemctl restart network |
16 | 12 |
|
17 |
-# Setup hosts file to support ping by hostname to each minion in the cluster from apiserver |
|
18 |
-node_list="" |
|
13 |
+# Setup hosts file to ensure name resolution to each member of the cluster |
|
19 | 14 |
minion_ip_array=(${MINION_IPS//,/ }) |
20 |
-for (( i=0; i<${#MINION_NAMES[@]}; i++)); do |
|
21 |
- minion=${MINION_NAMES[$i]} |
|
22 |
- node_list="${node_list},${minion}" |
|
23 |
- ip=${minion_ip_array[$i]} |
|
24 |
- if [ ! "$(cat /etc/hosts | grep $minion)" ]; then |
|
25 |
- echo "Adding $minion to hosts file" |
|
26 |
- echo "$ip $minion" >> /etc/hosts |
|
27 |
- fi |
|
28 |
-done |
|
29 |
-if ! grep ${MASTER_IP} /etc/hosts; then |
|
30 |
- echo "${MASTER_IP} ${MASTER_NAME}" >> /etc/hosts |
|
31 |
-fi |
|
32 |
-node_list=${node_list:1} |
|
15 |
+os::util::setup-hosts-file "${MASTER_NAME}" "${MASTER_IP}" MINION_NAMES \ |
|
16 |
+ minion_ip_array |
|
33 | 17 |
|
34 | 18 |
# Install the required packages |
35 | 19 |
yum install -y docker-io git golang e2fsprogs hg net-tools bridge-utils which |
36 | 20 |
|
37 | 21 |
# Build openshift |
38 | 22 |
echo "Building openshift" |
39 |
-pushd /vagrant |
|
23 |
+pushd "${ORIGIN_ROOT}" |
|
40 | 24 |
./hack/build-go.sh |
41 |
- cp _output/local/go/bin/openshift /usr/bin |
|
25 |
+ os::util::install-cmds "${ORIGIN_ROOT}" |
|
42 | 26 |
./hack/install-etcd.sh |
43 | 27 |
popd |
44 | 28 |
|
45 |
-# Initialize certificates |
|
46 |
-echo "Generating certs" |
|
47 |
-pushd /vagrant |
|
48 |
- SERVER_CONFIG_DIR="`pwd`/openshift.local.config" |
|
49 |
- VOLUMES_DIR="/var/lib/openshift.local.volumes" |
|
50 |
- MASTER_CONFIG_DIR="${SERVER_CONFIG_DIR}/master" |
|
51 |
- CERT_DIR="${MASTER_CONFIG_DIR}" |
|
52 |
- |
|
53 |
- # Master certs |
|
54 |
- /usr/bin/openshift admin ca create-master-certs \ |
|
55 |
- --overwrite=false \ |
|
56 |
- --cert-dir=${CERT_DIR} \ |
|
57 |
- --master=https://${MASTER_IP}:8443 \ |
|
58 |
- --hostnames=${MASTER_IP},${MASTER_NAME} |
|
59 |
- |
|
60 |
- # Certs for nodes |
|
61 |
- for (( i=0; i<${#MINION_NAMES[@]}; i++)); do |
|
62 |
- minion=${MINION_NAMES[$i]} |
|
63 |
- ip=${minion_ip_array[$i]} |
|
64 |
- |
|
65 |
- /usr/bin/openshift admin create-node-config \ |
|
66 |
- --node-dir="${SERVER_CONFIG_DIR}/node-${minion}" \ |
|
67 |
- --node="${minion}" \ |
|
68 |
- --hostnames="${minion},${ip}" \ |
|
69 |
- --master="https://${MASTER_IP}:8443" \ |
|
70 |
- --network-plugin="${OPENSHIFT_SDN_PLUGIN}" \ |
|
71 |
- --node-client-certificate-authority="${CERT_DIR}/ca.crt" \ |
|
72 |
- --certificate-authority="${CERT_DIR}/ca.crt" \ |
|
73 |
- --signer-cert="${CERT_DIR}/ca.crt" \ |
|
74 |
- --signer-key="${CERT_DIR}/ca.key" \ |
|
75 |
- --signer-serial="${CERT_DIR}/ca.serial.txt" \ |
|
76 |
- --volume-dir="${VOLUMES_DIR}" |
|
77 |
- done |
|
78 |
- |
|
79 |
-popd |
|
29 |
+os::util::init-certs "${ORIGIN_ROOT}" "${NETWORK_PLUGIN}" "${MASTER_NAME}" \ |
|
30 |
+ "${MASTER_IP}" MINION_NAMES minion_ip_array |
|
80 | 31 |
|
81 | 32 |
# Start docker |
82 | 33 |
systemctl enable docker.service |
83 | 34 |
systemctl start docker.service |
84 | 35 |
|
85 | 36 |
# Create systemd service |
37 |
+node_list=$(os::util::join , ${MINION_NAMES[@]}) |
|
86 | 38 |
cat <<EOF > /usr/lib/systemd/system/openshift-master.service |
87 | 39 |
[Unit] |
88 | 40 |
Description=OpenShift Master |
... | ... |
@@ -90,8 +42,8 @@ Requires=docker.service network.service |
90 | 90 |
After=network.service |
91 | 91 |
|
92 | 92 |
[Service] |
93 |
-ExecStart=/usr/bin/openshift start master --master=https://${MASTER_IP}:8443 --nodes=${node_list} --network-plugin=${OPENSHIFT_SDN_PLUGIN} |
|
94 |
-WorkingDirectory=/vagrant/ |
|
93 |
+ExecStart=/usr/bin/openshift start master --master=https://${MASTER_IP}:8443 --nodes=${node_list} --network-plugin=${NETWORK_PLUGIN} |
|
94 |
+WorkingDirectory=${ORIGIN_ROOT}/ |
|
95 | 95 |
|
96 | 96 |
[Install] |
97 | 97 |
WantedBy=multi-user.target |
... | ... |
@@ -102,8 +54,8 @@ systemctl daemon-reload |
102 | 102 |
systemctl start openshift-master.service |
103 | 103 |
|
104 | 104 |
# setup SDN |
105 |
-$(dirname $0)/provision-sdn.sh $@ |
|
105 |
+$(dirname $0)/provision-sdn.sh |
|
106 | 106 |
|
107 | 107 |
# Set up the KUBECONFIG environment variable for use by oc |
108 |
-echo 'export KUBECONFIG=/vagrant/openshift.local.config/master/admin.kubeconfig' >> /root/.bash_profile |
|
109 |
-echo 'export KUBECONFIG=/vagrant/openshift.local.config/master/admin.kubeconfig' >> /home/vagrant/.bash_profile |
|
108 |
+os::util::set-oc-env "${ORIGIN_ROOT}" "/root/.bash_profile" |
|
109 |
+os::util::set-oc-env "${ORIGIN_ROOT}" "/home/vagrant/.bash_profile" |
... | ... |
@@ -3,7 +3,6 @@ set -ex |
3 | 3 |
source $(dirname $0)/provision-config.sh |
4 | 4 |
|
5 | 5 |
MINION_IP=$4 |
6 |
-OPENSHIFT_SDN=$6 |
|
7 | 6 |
MINION_INDEX=$5 |
8 | 7 |
|
9 | 8 |
NETWORK_CONF_PATH=/etc/sysconfig/network-scripts/ |
... | ... |
@@ -14,44 +13,29 @@ systemctl restart network |
14 | 14 |
# get the minion name, index is 1-based |
15 | 15 |
minion_name=${MINION_NAMES[$MINION_INDEX-1]} |
16 | 16 |
|
17 |
-# Setup hosts file to support ping by hostname to master |
|
18 |
-if [ ! "$(cat /etc/hosts | grep $MASTER_NAME)" ]; then |
|
19 |
- echo "Adding $MASTER_NAME to hosts file" |
|
20 |
- echo "$MASTER_IP $MASTER_NAME" >> /etc/hosts |
|
21 |
-fi |
|
22 |
- |
|
23 |
-# Setup hosts file to support ping by hostname to each minion in the cluster |
|
17 |
+# Setup hosts file to ensure name resolution to each member of the cluster |
|
24 | 18 |
minion_ip_array=(${MINION_IPS//,/ }) |
25 |
-for (( i=0; i<${#MINION_NAMES[@]}; i++)); do |
|
26 |
- minion=${MINION_NAMES[$i]} |
|
27 |
- ip=${minion_ip_array[$i]} |
|
28 |
- if [ ! "$(cat /etc/hosts | grep $minion)" ]; then |
|
29 |
- echo "Adding $minion to hosts file" |
|
30 |
- echo "$ip $minion" >> /etc/hosts |
|
31 |
- fi |
|
32 |
-done |
|
33 |
-if ! grep ${MINION_IP} /etc/hosts; then |
|
34 |
- echo "${MINION_IP} ${minion_name}" >> /etc/hosts |
|
35 |
-fi |
|
19 |
+os::util::setup-hosts-file "${MASTER_NAME}" "${MASTER_IP}" MINION_NAMES \ |
|
20 |
+ minion_ip_array |
|
36 | 21 |
|
37 | 22 |
# Install the required packages |
38 | 23 |
yum install -y docker-io git golang e2fsprogs hg openvswitch net-tools bridge-utils which ethtool |
39 | 24 |
|
40 | 25 |
# Build openshift |
41 | 26 |
echo "Building openshift" |
42 |
-pushd /vagrant |
|
27 |
+pushd "${ORIGIN_ROOT}" |
|
43 | 28 |
./hack/build-go.sh |
44 |
- cp _output/local/go/bin/openshift /usr/bin |
|
29 |
+ os::util::install-cmds "${ORIGIN_ROOT}" |
|
45 | 30 |
popd |
46 | 31 |
|
47 | 32 |
# Copy over the certificates directory |
48 |
-cp -r /vagrant/openshift.local.config / |
|
33 |
+cp -r "${ORIGIN_ROOT}/openshift.local.config" / |
|
49 | 34 |
chown -R vagrant.vagrant /openshift.local.config |
50 | 35 |
|
51 | 36 |
mkdir -p /openshift.local.volumes |
52 | 37 |
|
53 | 38 |
# Setup SDN |
54 |
-$(dirname $0)/provision-sdn.sh $@ |
|
39 |
+$(dirname $0)/provision-sdn.sh |
|
55 | 40 |
|
56 | 41 |
# Create systemd service |
57 | 42 |
cat <<EOF > /usr/lib/systemd/system/openshift-node.service |
... | ... |
@@ -75,8 +59,8 @@ systemctl enable openshift-node.service |
75 | 75 |
systemctl start openshift-node.service |
76 | 76 |
|
77 | 77 |
# Set up the KUBECONFIG environment variable for use by the client |
78 |
-echo 'export KUBECONFIG=/openshift.local.config/master/admin.kubeconfig' >> /root/.bash_profile |
|
79 |
-echo 'export KUBECONFIG=/openshift.local.config/master/admin.kubeconfig' >> /home/vagrant/.bash_profile |
|
78 |
+os::util::set-oc-env / "/root/.bash_profile" |
|
79 |
+os::util::set-oc-env / "/home/vagrant/.bash_profile" |
|
80 | 80 |
|
81 | 81 |
# Register with the master |
82 | 82 |
#curl -X POST -H 'Accept: application/json' -d "{\"kind\":\"Minion\", \"id\":"${MINION_IP}", \"apiVersion\":\"v1beta1\", \"hostIP\":"${MINION_IP}" }" http://${MASTER_IP}:8080/api/v1beta1/minions |
... | ... |
@@ -2,24 +2,12 @@ |
2 | 2 |
set -ex |
3 | 3 |
source $(dirname $0)/provision-config.sh |
4 | 4 |
|
5 |
-pushd $HOME |
|
6 |
-# build openshift-sdn |
|
7 |
-if [ -d openshift-sdn ]; then |
|
8 |
- cd openshift-sdn |
|
9 |
- git fetch origin |
|
10 |
- git reset --hard origin/master |
|
11 |
- git checkout -b multitenant |
|
12 |
-else |
|
13 |
- git clone https://github.com/openshift/openshift-sdn -b multitenant |
|
14 |
- cd openshift-sdn |
|
15 |
-fi |
|
16 |
- |
|
17 |
-make clean |
|
18 |
-make |
|
19 |
-make install |
|
20 |
-popd |
|
5 |
+os::util::install-sdn "${ORIGIN_ROOT}" |
|
21 | 6 |
|
22 |
-systemctl enable openvswitch |
|
23 |
-systemctl start openvswitch |
|
7 |
+# Only start openvswitch if it has been installed (only minions). |
|
8 |
+if rpm -qa | grep -q openvswitch; then |
|
9 |
+ systemctl enable openvswitch |
|
10 |
+ systemctl start openvswitch |
|
11 |
+fi |
|
24 | 12 |
|
25 | 13 |
# no need to start openshift-sdn, as it is integrated with openshift binary |
26 | 14 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,145 @@ |
0 |
+#!/bin/bash |
|
1 |
+ |
|
2 |
+os::util::join() { |
|
3 |
+ local IFS="$1" |
|
4 |
+ |
|
5 |
+ shift |
|
6 |
+ echo "$*" |
|
7 |
+} |
|
8 |
+ |
|
9 |
+os::util::install-cmds() { |
|
10 |
+ local deployed_root=$1 |
|
11 |
+ |
|
12 |
+ cp ${deployed_root}/_output/local/go/bin/{openshift,oc} /usr/bin |
|
13 |
+} |
|
14 |
+ |
|
15 |
+os::util::add-to-hosts-file() { |
|
16 |
+ local ip=$1 |
|
17 |
+ local name=$2 |
|
18 |
+ |
|
19 |
+ if ! grep -q "${ip}" /etc/hosts; then |
|
20 |
+ local entry="${ip}\t${name}" |
|
21 |
+ echo -e "Adding '${entry}' to hosts file" |
|
22 |
+ echo -e "${entry}" >> /etc/hosts |
|
23 |
+ fi |
|
24 |
+} |
|
25 |
+ |
|
26 |
+os::util::setup-hosts-file() { |
|
27 |
+ local master_name=$1 |
|
28 |
+ local master_ip=$2 |
|
29 |
+ local -n node_names=$3 |
|
30 |
+ local -n node_ips=$4 |
|
31 |
+ |
|
32 |
+ # Setup hosts file to support ping by hostname to master |
|
33 |
+ os::util::add-to-hosts-file "${master_ip}" "${master_name}" |
|
34 |
+ |
|
35 |
+ # Setup hosts file to support ping by hostname to each node in the cluster |
|
36 |
+ for (( i=0; i < ${#node_names[@]}; i++ )); do |
|
37 |
+ os::util::add-to-hosts-file "${node_ips[$i]}" "${node_names[$i]}" |
|
38 |
+ done |
|
39 |
+} |
|
40 |
+ |
|
41 |
+os::util::init-certs() { |
|
42 |
+ local openshift_root=$1 |
|
43 |
+ local network_plugin=$2 |
|
44 |
+ local master_name=$3 |
|
45 |
+ local master_ip=$4 |
|
46 |
+ local -n node_names=$5 |
|
47 |
+ local -n node_ips=$6 |
|
48 |
+ |
|
49 |
+ local server_config_dir=${openshift_root}/openshift.local.config |
|
50 |
+ local volumes_dir="/var/lib/openshift.local.volumes" |
|
51 |
+ local cert_dir="${server_config_dir}/master" |
|
52 |
+ |
|
53 |
+ echo "Generating certs" |
|
54 |
+ |
|
55 |
+ pushd "${openshift_root}" |
|
56 |
+ |
|
57 |
+ # Master certs |
|
58 |
+ /usr/bin/openshift admin ca create-master-certs \ |
|
59 |
+ --overwrite=false \ |
|
60 |
+ --cert-dir="${cert_dir}" \ |
|
61 |
+ --master="https://${master_ip}:8443" \ |
|
62 |
+ --hostnames="${master_ip},${master_name}" |
|
63 |
+ |
|
64 |
+ # Certs for nodes |
|
65 |
+ for (( i=0; i < ${#node_names[@]}; i++ )); do |
|
66 |
+ local name=${node_names[$i]} |
|
67 |
+ local ip=${node_ips[$i]} |
|
68 |
+ /usr/bin/openshift admin create-node-config \ |
|
69 |
+ --node-dir="${server_config_dir}/node-${name}" \ |
|
70 |
+ --node="${name}" \ |
|
71 |
+ --hostnames="${name},${ip}" \ |
|
72 |
+ --master="https://${master_ip}:8443" \ |
|
73 |
+ --network-plugin="${network_plugin}" \ |
|
74 |
+ --node-client-certificate-authority="${cert_dir}/ca.crt" \ |
|
75 |
+ --certificate-authority="${cert_dir}/ca.crt" \ |
|
76 |
+ --signer-cert="${cert_dir}/ca.crt" \ |
|
77 |
+ --signer-key="${cert_dir}/ca.key" \ |
|
78 |
+ --signer-serial="${cert_dir}/ca.serial.txt" \ |
|
79 |
+ --volume-dir="${volumes_dir}" |
|
80 |
+ done |
|
81 |
+ |
|
82 |
+ popd |
|
83 |
+} |
|
84 |
+ |
|
85 |
+# Set up the KUBECONFIG environment variable for use by oc |
|
86 |
+os::util::set-oc-env() { |
|
87 |
+ local deployed_root=$1 |
|
88 |
+ local target=$2 |
|
89 |
+ |
|
90 |
+ if [ "${deployed_root}" = "/" ]; then |
|
91 |
+ deployed_root="" |
|
92 |
+ fi |
|
93 |
+ |
|
94 |
+ local path="${deployed_root}/openshift.local.config/master/admin.kubeconfig" |
|
95 |
+ echo "export KUBECONFIG=${path}" >> "${target}" |
|
96 |
+} |
|
97 |
+ |
|
98 |
+os::util::get-network-plugin() { |
|
99 |
+ local plugin=$1 |
|
100 |
+ |
|
101 |
+ local subnet_plugin="redhat/openshift-ovs-subnet" |
|
102 |
+ local multitenant_plugin="redhat/openshift-ovs-multitenant" |
|
103 |
+ local default_plugin="${subnet_plugin}" |
|
104 |
+ |
|
105 |
+ if [ "${plugin}" != "${subnet_plugin}" ] && \ |
|
106 |
+ [ "${plugin}" != "${multitenant_plugin}" ]; then |
|
107 |
+ if [ "${plugin}" != "" ]; then |
|
108 |
+ >&2 echo "Invalid network plugin: ${plugin}" |
|
109 |
+ fi |
|
110 |
+ >&2 echo "Using default network plugin: ${default_plugin}" |
|
111 |
+ plugin="${default_plugin}" |
|
112 |
+ fi |
|
113 |
+ echo "${plugin}" |
|
114 |
+} |
|
115 |
+ |
|
116 |
+os::util::install-sdn() { |
|
117 |
+ local deployed_root=$1 |
|
118 |
+ |
|
119 |
+ # Source scripts from an openshift-sdn repo if present to support |
|
120 |
+ # openshift-sdn development. |
|
121 |
+ local sdn_root="${deployed_root}/third-party/openshift-sdn" |
|
122 |
+ if [ -d "${sdn_root}" ]; then |
|
123 |
+ pushd "${sdn_root}" |
|
124 |
+ make |
|
125 |
+ make "install-dev" |
|
126 |
+ popd |
|
127 |
+ else |
|
128 |
+ local osdn_base_path="${deployed_root}/Godeps/_workspace/src/github.com/openshift/openshift-sdn" |
|
129 |
+ local osdn_controller_path="${osdn_base_path}/ovssubnet/controller" |
|
130 |
+ pushd "${osdn_controller_path}" |
|
131 |
+ # The subnet plugin is discovered via the kube network plugin path. |
|
132 |
+ local kube_osdn_path="/usr/libexec/kubernetes/kubelet-plugins/net/exec/redhat~openshift-ovs-subnet" |
|
133 |
+ mkdir -p "${kube_osdn_path}" |
|
134 |
+ cp -f kube/bin/openshift-ovs-subnet "${kube_osdn_path}/" |
|
135 |
+ cp -f kube/bin/openshift-sdn-kube-subnet-setup.sh /usr/bin/ |
|
136 |
+ |
|
137 |
+ # The multitenant plugin only needs to be in PATH because the |
|
138 |
+ # origin multitenant plugin knows how to discover it. |
|
139 |
+ cp -f multitenant/bin/openshift-ovs-multitenant /usr/bin/ |
|
140 |
+ cp -f multitenant/bin/openshift-sdn-multitenant-setup.sh /usr/bin/ |
|
141 |
+ popd |
|
142 |
+ fi |
|
143 |
+ |
|
144 |
+} |