3 ################################################################################
4 # Copyright (c) 2019 AT&T Intellectual Property. #
5 # Copyright (c) 2019 Nokia. #
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 #
11 # http://www.apache.org/licenses/LICENSE-2.0 #
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 ################################################################################
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.
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;
34 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
36 RCS="$(find $DIR/../etc -type f -maxdepth 1)"
38 echo "reading in values in $RC"
44 if [ -z "$WORKSPACE" ]; then
45 export WORKSPACE=`git rev-parse --show-toplevel`
47 HEAT_DIR="$WORKSPACE/ric-infra/00-Kubernetes/heat"
48 BIN_DIR="$WORKSPACE/ric-infra/00-Kubernetes/bin"
49 ETC_DIR="$WORKSPACE/ric-infra/00-Kubernetes/etc"
50 ENV_DIR="$WORKSPACE/ric-infra/00-Kubernetes/heat/env"
53 TMPL="${HEAT_DIR}/scripts/k8s_vm_install.sh"
59 if [ -z "$__RUNRICENV_GERRIT_HOST__" ]; then
60 export __RUNRICENV_GERRIT_HOST__=$gerrithost
62 if [ -z "$__RUNRICENV_GERRIT_IP__" ]; then
63 export __RUNRICENV_GERRIT_IP__=$gerritip
65 if [ -z "$__RUNRICENV_DOCKER_HOST__" ]; then
66 export __RUNRICENV_DOCKER_HOST__=$dockerregistry
68 if [ -z "$__RUNRICENV_DOCKER_IP__" ]; then
69 export __RUNRICENV_DOCKER_IP__=$dockerip
71 if [ -z "$__RUNRICENV_DOCKER_PORT__" ]; then
72 export __RUNRICENV_DOCKER_PORT__=$dockerport
74 if [ -z "$__RUNRICENV_DOCKER_USER__" ]; then
75 export __RUNRICENV_DOCKER_USER__=$dockeruser
77 if [ -z "$__RUNRICENV_DOCKER_PASS__" ]; then
78 export __RUNRICENV_DOCKER_PASS__=$dockerpassword
80 if [ -z "$__RUNRICENV_DOCKER_CERT__" ]; then
81 export __RUNRICENV_DOCKER_CERT__=$dockercert
83 if [ -z "$__RUNRICENV_DOCKER_CERT_LEN__" ]; then
84 export __RUNRICENV_DOCKER_CERT_LEN__=$(echo $dockercert | wc -c)
86 if [ -z "$__RUNRICENV_HELMREPO_HOST__" ]; then
87 export __RUNRICENV_HELMREPO_HOST__=$helmrepo
89 if [ -z "$__RUNRICENV_HELMREPO_PORT__" ]; then
90 export __RUNRICENV_HELMREPO_PORT__=$helmport
92 if [ -z "$__RUNRICENV_HELMREPO_IP__" ]; then
93 export __RUNRICENV_HELMREPO_IP__=$helmip
95 if [ -z "$__RUNRICENV_HELMREPO_USER__" ]; then
96 export __RUNRICENV_HELMREPO_USER__=$helmuser
98 if [ -z "$__RUNRICENV_HELMREPO_PASS__" ]; then
99 export __RUNRICENV_HELMREPO_PASS__=$helmpassword
101 if [ -z "$__RUNRICENV_HELMREPO_CERT__" ]; then
102 export __RUNRICENV_HELMREPO_CERT__=$helmcert
104 if [ -z "$__RUNRICENV_HELMREPO_CERT_LEN__" ]; then
105 export __RUNRICENV_HELMREPO_CERT_LEN__=$(echo $helmcert | wc -c)
109 filename=$(basename -- "$TMPL")
110 extension="${filename##*.}"
111 filename="${filename%.*}"
113 envsubst '${__RUNRICENV_GERRIT_HOST__}
114 ${__RUNRICENV_GERRIT_IP__}
115 ${__RUNRICENV_DOCKER_HOST__}
116 ${__RUNRICENV_DOCKER_IP__}
117 ${__RUNRICENV_DOCKER_PORT__}
118 ${__RUNRICENV_DOCKER_USER__}
119 ${__RUNRICENV_DOCKER_PASS__}
120 ${__RUNRICENV_DOCKER_CERT__}
121 ${__RUNRICENV_DOCKER_CERT__}
122 ${__RUNRICENV_DOCKER_CERT_LEN__}
123 ${__RUNRICENV_HELMREPO_HOST__}
124 ${__RUNRICENV_HELMREPO_PORT__}
125 ${__RUNRICENV_HELMREPO_IP__}
126 ${__RUNRICENV_HELMREPO_CERT__}
127 ${__RUNRICENV_HELMREPO_CERT_LEN__}
128 ${__RUNRICENV_HELMREPO_USER__}
129 ${__RUNRICENV_HELMREPO_PASS__}' < "$TMPL" > "$filename"
131 # fill values that are supplied by Heat stack deployment process as much as we can
132 sed -i "" -e "s/__docker_version__/${INFRA_DOCKER_VERSION}/g" "$filename"
133 sed -i "" -e "s/__k8s_version__/${INFRA_K8S_VERSION}/g" "$filename"
134 sed -i "" -e "s/__k8s_cni_version__/${INFRA_CNI_VERSION}/g" "$filename"
135 sed -i "" -e "s/__helm_version__/${INFRA_HELM_VERSION}/g" "$filename"
136 sed -i "" -e "s/__k8s_mst_private_ip_addr__/\$(hostname -I)/g" "$filename"
137 sed -i "" -e "s/__host_private_ip_addr__/\$(hostname -I)/g" "$filename"
138 #sed -i "" -e "s/__k8s_mst_floating_ip_addr__/\$(ec2metadata --public-ipv4)/g" "$filename"
139 sed -i "" -e "s/__k8s_mst_floating_ip_addr__/\$(curl ifconfig.co)/g" "$filename"
140 sed -i "" -e "s/__stack_name__/\$(hostname)/g" "$filename"
141 #echo "__mtu__" > /opt/config/mtu.txt
142 #echo "__cinder_volume_id__" > /opt/config/cinder_volume_id.txt
144 # because cloud init user data has a 16kB limit, remove all comment lines to save space.
145 sed -i "" -e '/^[ \t]*#/d' "$filename"
149 mv "$filename" ./k8s-1node-cloud-init.sh