wrider | ea83d03 | 2019-06-04 22:31:18 -0400 | [diff] [blame] | 1 | #!/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 | |
| 26 | usage() { |
| 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 | |
| 34 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" |
| 35 | set -a |
| 36 | RCS="$(find $DIR/../etc -type f -maxdepth 1)" |
| 37 | for RC in $RCS; do |
| 38 | echo "reading in values in $RC" |
| 39 | source $RC |
| 40 | done |
| 41 | set +a |
| 42 | |
| 43 | |
| 44 | if [ -z "$WORKSPACE" ]; then |
| 45 | export WORKSPACE=`git rev-parse --show-toplevel` |
| 46 | fi |
| 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" |
| 51 | |
| 52 | if [ -z "$1" ]; then |
| 53 | TMPL="${HEAT_DIR}/scripts/k8s_vm_install.sh" |
| 54 | else |
| 55 | TMPL="$1" |
| 56 | fi |
| 57 | |
| 58 | |
| 59 | if [ -z "$__RUNRICENV_GERRIT_HOST__" ]; then |
| 60 | export __RUNRICENV_GERRIT_HOST__=$gerrithost |
| 61 | fi |
| 62 | if [ -z "$__RUNRICENV_GERRIT_IP__" ]; then |
| 63 | export __RUNRICENV_GERRIT_IP__=$gerritip |
| 64 | fi |
| 65 | if [ -z "$__RUNRICENV_DOCKER_HOST__" ]; then |
| 66 | export __RUNRICENV_DOCKER_HOST__=$dockerregistry |
| 67 | fi |
| 68 | if [ -z "$__RUNRICENV_DOCKER_IP__" ]; then |
| 69 | export __RUNRICENV_DOCKER_IP__=$dockerip |
| 70 | fi |
| 71 | if [ -z "$__RUNRICENV_DOCKER_PORT__" ]; then |
| 72 | export __RUNRICENV_DOCKER_PORT__=$dockerport |
| 73 | fi |
| 74 | if [ -z "$__RUNRICENV_DOCKER_USER__" ]; then |
| 75 | export __RUNRICENV_DOCKER_USER__=$dockeruser |
| 76 | fi |
| 77 | if [ -z "$__RUNRICENV_DOCKER_PASS__" ]; then |
| 78 | export __RUNRICENV_DOCKER_PASS__=$dockerpassword |
| 79 | fi |
| 80 | if [ -z "$__RUNRICENV_DOCKER_CERT__" ]; then |
| 81 | export __RUNRICENV_DOCKER_CERT__=$dockercert |
| 82 | fi |
| 83 | if [ -z "$__RUNRICENV_HELMREPO_HOST__" ]; then |
| 84 | export __RUNRICENV_HELMREPO_HOST__=$helmrepo |
| 85 | fi |
| 86 | if [ -z "$__RUNRICENV_HELMREPO_PORT__" ]; then |
| 87 | export __RUNRICENV_HELMREPO_PORT__=$helmport |
| 88 | fi |
| 89 | if [ -z "$__RUNRICENV_HELMREPO_IP__" ]; then |
| 90 | export __RUNRICENV_HELMREPO_IP__=$helmip |
| 91 | fi |
| 92 | if [ -z "$__RUNRICENV_HELMREPO_USER__" ]; then |
| 93 | export __RUNRICENV_HELMREPO_USER__=$helmuser |
| 94 | fi |
| 95 | if [ -z "$__RUNRICENV_HELMREPO_PASS__" ]; then |
| 96 | export __RUNRICENV_HELMREPO_PASS__=$helmpassword |
| 97 | fi |
| 98 | if [ -z "$__RUNRICENV_HELMREPO_CERT__" ]; then |
| 99 | export __RUNRICENV_HELMREPO_CERT__=$helmcert |
| 100 | fi |
| 101 | |
| 102 | |
| 103 | filename=$(basename -- "$TMPL") |
| 104 | extension="${filename##*.}" |
| 105 | filename="${filename%.*}" |
| 106 | |
| 107 | envsubst '${__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 |
| 123 | sed -e "s/__docker_version__/${INFRA_DOCKER_VERSION}/g" "$filename" > tmp && mv tmp "$filename" |
| 124 | sed -e "s/__k8s_version__/${INFRA_K8S_VERSION}/g" "$filename" > tmp && mv tmp "$filename" |
| 125 | sed -e "s/__k8s_cni_version__/${INFRA_CNI_VERSION}/g" "$filename" > tmp && mv tmp "$filename" |
| 126 | sed -e "s/__helm_version__/${INFRA_HELM_VERSION}/g" "$filename" > tmp && mv tmp "$filename" |
| 127 | sed -e "s/__k8s_mst_private_ip_addr__/\$(hostname -I)/g" "$filename" > tmp && mv tmp "$filename" |
| 128 | sed -e "s/__host_private_ip_addr__/\$(hostname -I)/g" "$filename" > tmp && mv tmp "$filename" |
wrider | 5dbb5f8 | 2019-06-12 09:27:43 -0400 | [diff] [blame] | 129 | #sed -e "s/__k8s_mst_floating_ip_addr__/\$(ec2metadata --public-ipv4)/g" "$filename" > tmp && mv tmp "$filename" |
| 130 | sed -e "s/__k8s_mst_floating_ip_addr__/\$(curl ifconfig.co)/g" "$filename" > tmp && mv tmp "$filename" |
wrider | ea83d03 | 2019-06-04 22:31:18 -0400 | [diff] [blame] | 131 | sed -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 | |
| 136 | chmod +x "$filename" |
| 137 | if [ -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 |
| 141 | fi |