blob: 61603ba8415831dff3eefa173bb08b82842ddf58 [file] [log] [blame]
wriderea83d032019-06-04 22:31:18 -04001#!/bin/bash
2#
3################################################################################
4# Copyright (c) 2019 AT&T Intellectual Property. #
5# Copyright (c) 2019 Nokia. #
6# #
7# Licensed under the Apache License, Version 2.0 (the "License"); #
8# you may not use this file except in compliance with the License. #
9# You may obtain a copy of the License at #
10# #
11# http://www.apache.org/licenses/LICENSE-2.0 #
12# #
13# Unless required by applicable law or agreed to in writing, software #
14# distributed under the License is distributed on an "AS IS" BASIS, #
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
16# See the License for the specific language governing permissions and #
17# limitations under the License. #
18################################################################################
19
20
21# the following script replaces templates in a script with env variables defined in etc folder
22# when running without specifying a script, the default is to use the heat/scripts/k8s-vm-install.sh,
23# the result which is a script that can be used as cloud-init script and the initial installation
24# script that turns a newly launched VM into a single node k8s cluster with Helm.
25
26usage() {
27 echo "Usage: $0 <template file>" 1>&2;
28 echo " If the template file is supplied, the template file is processed;" 1>&2;
29 echo " Otherwise the k8s_vm_install.sh file under heat/script is used as template." 1>&2;
30 exit 1;
31}
32
33
34DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
35set -a
36RCS="$(find $DIR/../etc -type f -maxdepth 1)"
37for RC in $RCS; do
38 echo "reading in values in $RC"
39 source $RC
40done
41set +a
42
43
44if [ -z "$WORKSPACE" ]; then
45 export WORKSPACE=`git rev-parse --show-toplevel`
46fi
47HEAT_DIR="$WORKSPACE/ric-infra/00-Kubernetes/heat"
48BIN_DIR="$WORKSPACE/ric-infra/00-Kubernetes/bin"
49ETC_DIR="$WORKSPACE/ric-infra/00-Kubernetes/etc"
50ENV_DIR="$WORKSPACE/ric-infra/00-Kubernetes/heat/env"
51
52if [ -z "$1" ]; then
53 TMPL="${HEAT_DIR}/scripts/k8s_vm_install.sh"
54else
55 TMPL="$1"
56fi
57
58
59if [ -z "$__RUNRICENV_GERRIT_HOST__" ]; then
60 export __RUNRICENV_GERRIT_HOST__=$gerrithost
61fi
62if [ -z "$__RUNRICENV_GERRIT_IP__" ]; then
63 export __RUNRICENV_GERRIT_IP__=$gerritip
64fi
65if [ -z "$__RUNRICENV_DOCKER_HOST__" ]; then
66 export __RUNRICENV_DOCKER_HOST__=$dockerregistry
67fi
68if [ -z "$__RUNRICENV_DOCKER_IP__" ]; then
69 export __RUNRICENV_DOCKER_IP__=$dockerip
70fi
71if [ -z "$__RUNRICENV_DOCKER_PORT__" ]; then
72 export __RUNRICENV_DOCKER_PORT__=$dockerport
73fi
74if [ -z "$__RUNRICENV_DOCKER_USER__" ]; then
75 export __RUNRICENV_DOCKER_USER__=$dockeruser
76fi
77if [ -z "$__RUNRICENV_DOCKER_PASS__" ]; then
78 export __RUNRICENV_DOCKER_PASS__=$dockerpassword
79fi
80if [ -z "$__RUNRICENV_DOCKER_CERT__" ]; then
81 export __RUNRICENV_DOCKER_CERT__=$dockercert
82fi
83if [ -z "$__RUNRICENV_HELMREPO_HOST__" ]; then
84 export __RUNRICENV_HELMREPO_HOST__=$helmrepo
85fi
86if [ -z "$__RUNRICENV_HELMREPO_PORT__" ]; then
87 export __RUNRICENV_HELMREPO_PORT__=$helmport
88fi
89if [ -z "$__RUNRICENV_HELMREPO_IP__" ]; then
90 export __RUNRICENV_HELMREPO_IP__=$helmip
91fi
92if [ -z "$__RUNRICENV_HELMREPO_USER__" ]; then
93 export __RUNRICENV_HELMREPO_USER__=$helmuser
94fi
95if [ -z "$__RUNRICENV_HELMREPO_PASS__" ]; then
96 export __RUNRICENV_HELMREPO_PASS__=$helmpassword
97fi
98if [ -z "$__RUNRICENV_HELMREPO_CERT__" ]; then
99 export __RUNRICENV_HELMREPO_CERT__=$helmcert
100fi
101
102
103filename=$(basename -- "$TMPL")
104extension="${filename##*.}"
105filename="${filename%.*}"
106
107envsubst '${__RUNRICENV_GERRIT_HOST__}
108 ${__RUNRICENV_GERRIT_IP__}
109 ${__RUNRICENV_DOCKER_HOST__}
110 ${__RUNRICENV_DOCKER_IP__}
111 ${__RUNRICENV_DOCKER_PORT__}
112 ${__RUNRICENV_DOCKER_USER__}
113 ${__RUNRICENV_DOCKER_PASS__}
114 ${__RUNRICENV_DOCKER_CERT__}
115 ${__RUNRICENV_HELMREPO_HOST__}
116 ${__RUNRICENV_HELMREPO_PORT__}
117 ${__RUNRICENV_HELMREPO_IP__}
118 ${__RUNRICENV_HELMREPO_CERT__}
119 ${__RUNRICENV_HELMREPO_USER__}
120 ${__RUNRICENV_HELMREPO_PASS__}' < "$TMPL" > "$filename"
121
122# fill values that are supplied by Heat stack deployment process as much as we can
123sed -e "s/__docker_version__/${INFRA_DOCKER_VERSION}/g" "$filename" > tmp && mv tmp "$filename"
124sed -e "s/__k8s_version__/${INFRA_K8S_VERSION}/g" "$filename" > tmp && mv tmp "$filename"
125sed -e "s/__k8s_cni_version__/${INFRA_CNI_VERSION}/g" "$filename" > tmp && mv tmp "$filename"
126sed -e "s/__helm_version__/${INFRA_HELM_VERSION}/g" "$filename" > tmp && mv tmp "$filename"
127sed -e "s/__k8s_mst_private_ip_addr__/\$(hostname -I)/g" "$filename" > tmp && mv tmp "$filename"
128sed -e "s/__host_private_ip_addr__/\$(hostname -I)/g" "$filename" > tmp && mv tmp "$filename"
wrider5dbb5f82019-06-12 09:27:43 -0400129#sed -e "s/__k8s_mst_floating_ip_addr__/\$(ec2metadata --public-ipv4)/g" "$filename" > tmp && mv tmp "$filename"
130sed -e "s/__k8s_mst_floating_ip_addr__/\$(curl ifconfig.co)/g" "$filename" > tmp && mv tmp "$filename"
wriderea83d032019-06-04 22:31:18 -0400131sed -e "s/__stack_name__/\$(hostname)/g" "$filename" > tmp && mv tmp "$filename"
132#echo "__mtu__" > /opt/config/mtu.txt
133#echo "__cinder_volume_id__" > /opt/config/cinder_volume_id.txt
134
135
136chmod +x "$filename"
137if [ -z "$1" ]; then
138 mv "$filename" k8s-1node-cloud-init.sh
139 # reboot VM to load the new kernel.
140 echo 'if [ "$(uname -r)" != "4.15.0-45-lowlatency" ]; then reboot; fi' >> k8s-1node-cloud-init.sh
141fi