Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Borislav Glozman | 5197e2e | 2017-07-24 10:45:28 +0300 | [diff] [blame] | 3 | . $(dirname "$0")/setenv.bash |
| 4 | |
kerenj | 74d723a | 2017-08-22 15:27:04 +0000 | [diff] [blame] | 5 | |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 6 | usage() { |
| 7 | cat <<EOF |
| 8 | Usage: $0 [PARAMs] |
| 9 | -u : Display usage |
| 10 | -n [NAMESPACE] : Kubernetes namespace (required) |
| 11 | -s false : Exclude services (default: true) |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame] | 12 | -i [INSTANCE] : ONAP deployment instance # (default: 1) |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 13 | -a [APP] : Specify a specific ONAP component (default: all) |
| 14 | from the following choices: |
| 15 | sdc, aai ,mso, message-router, robot, |
| 16 | vid, sdnc, portal, policy, appc |
| 17 | EOF |
| 18 | } |
| 19 | |
| 20 | create_namespace() { |
| 21 | kubectl create namespace $1-$2 |
| 22 | } |
| 23 | |
Borislav Glozman | 5197e2e | 2017-07-24 10:45:28 +0300 | [diff] [blame] | 24 | create_registry_key() { |
| 25 | kubectl --namespace $1-$2 create secret docker-registry $3 --docker-server=$4 --docker-username=$5 --docker-password=$6 --docker-email=$7 |
| 26 | } |
| 27 | |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 28 | create_service() { |
Munir Ahmad | 0803ca6 | 2017-08-23 16:55:59 -0400 | [diff] [blame] | 29 | sed -i-- 's/nodePort: [0-9]\{2\}[02468]\{1\}/nodePort: '"$3"'/g' ../$2/all-services.yaml |
| 30 | sed -i-- 's/nodePort: [0-9]\{2\}[13579]\{1\}/nodePort: '"$4"'/g' ../$2/all-services.yaml |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 31 | kubectl --namespace $1-$2 create -f ../$2/all-services.yaml |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame] | 32 | mv ../$2/all-services.yaml-- ../$2/all-services.yaml |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 33 | } |
| 34 | |
kerenj | 74d723a | 2017-08-22 15:27:04 +0000 | [diff] [blame] | 35 | |
| 36 | create_onap_helm() { |
| 37 | helm install ../$2/ --name $2 |
| 38 | } |
| 39 | |
Mike Elliott | d17accd | 2017-08-14 16:21:40 -0400 | [diff] [blame] | 40 | configure_app() { |
| 41 | # if previous configuration exists put back original template file |
kerenj | 74d723a | 2017-08-22 15:27:04 +0000 | [diff] [blame] | 42 | for file in $3/*.yaml; do |
Mike Elliott | d17accd | 2017-08-14 16:21:40 -0400 | [diff] [blame] | 43 | if [ -e "$file-template" ]; then |
| 44 | mv "$file-template" "${file%}" |
| 45 | fi |
| 46 | done |
kerenj | 74d723a | 2017-08-22 15:27:04 +0000 | [diff] [blame] | 47 | |
| 48 | if [ -e "$2/Chart.yaml" ]; then |
Munir Ahmad | 0803ca6 | 2017-08-23 16:55:59 -0400 | [diff] [blame] | 49 | sed -i-- 's/nodePort: [0-9]\{2\}[02468]\{1\}/nodePort: '"$4"'/g' $3/all-services.yaml |
| 50 | sed -i-- 's/nodePort: [0-9]\{2\}[13579]\{1\}/nodePort: '"$5"'/g' $3/all-services.yaml |
kerenj | 74d723a | 2017-08-22 15:27:04 +0000 | [diff] [blame] | 51 | sed -i "s/onap-/$1-/g" ../$2/values.yaml |
| 52 | fi |
| 53 | |
Mike Elliott | d17accd | 2017-08-14 16:21:40 -0400 | [diff] [blame] | 54 | |
| 55 | # replace the default 'onap' namespace qualification of K8s hostnames within |
| 56 | # the config files |
| 57 | # note: this will create a '-template' file within the component's directory |
| 58 | # this is not ideal and should be addressed (along with the replacement |
| 59 | # of sed commands for configuration) by the future configuration |
| 60 | # user stories (ie. OOM-51 to OOM-53) |
kerenj | 74d723a | 2017-08-22 15:27:04 +0000 | [diff] [blame] | 61 | find $3 -type f -exec sed -i -- "s/onap-/$1-/g" {} \; |
Mike Elliott | d17accd | 2017-08-14 16:21:40 -0400 | [diff] [blame] | 62 | |
Munir Ahmad | 76610be | 2017-08-17 11:56:15 -0400 | [diff] [blame] | 63 | # replace the default '/dockerdata-nfs/onapdemo' volume mount paths |
kerenj | 74d723a | 2017-08-22 15:27:04 +0000 | [diff] [blame] | 64 | find $3 -iname "*.yaml" -type f -exec sed -i -e 's/dockerdata-nfs\/[a-zA-Z0-9\\-]*\//dockerdata-nfs\/'"$1"'\//g' {} \; |
| 65 | rm -f $3/*.yaml-e |
Mike Elliott | d17accd | 2017-08-14 16:21:40 -0400 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 69 | #MAINs |
| 70 | NS= |
| 71 | INCL_SVC=true |
| 72 | APP= |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame] | 73 | INSTANCE=1 |
| 74 | MAX_INSTANCE=5 |
Borislav Glozman | 5197e2e | 2017-07-24 10:45:28 +0300 | [diff] [blame] | 75 | DU=$ONAP_DOCKER_USER |
| 76 | DP=$ONAP_DOCKER_PASS |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 77 | |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame] | 78 | while getopts ":n:u:s:i:a:du:dp:" PARAM; do |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 79 | case $PARAM in |
| 80 | u) |
| 81 | usage |
| 82 | exit 1 |
| 83 | ;; |
| 84 | n) |
| 85 | NS=${OPTARG} |
| 86 | ;; |
| 87 | s) |
| 88 | INCL_SVC=${OPTARG} |
| 89 | ;; |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame] | 90 | i) |
| 91 | INSTANCE=${OPTARG} |
| 92 | ;; |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 93 | a) |
| 94 | APP=${OPTARG} |
| 95 | if [[ -z $APP ]]; then |
| 96 | usage |
| 97 | exit 1 |
| 98 | fi |
| 99 | ;; |
Borislav Glozman | 5197e2e | 2017-07-24 10:45:28 +0300 | [diff] [blame] | 100 | du) |
| 101 | DU=${OPTARG} |
| 102 | ;; |
| 103 | dp) |
| 104 | DP=${OPTARG} |
| 105 | ;; |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 106 | ?) |
| 107 | usage |
| 108 | exit |
| 109 | ;; |
| 110 | esac |
| 111 | done |
| 112 | |
| 113 | if [[ -z $NS ]]; then |
| 114 | usage |
| 115 | exit 1 |
| 116 | fi |
| 117 | |
| 118 | if [[ ! -z "$APP" ]]; then |
| 119 | ONAP_APPS=($APP) |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 120 | fi |
| 121 | |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame] | 122 | if [[ "$INCL_SVC" == true ]]; then |
| 123 | |
| 124 | if [ "$INSTANCE" -gt "$MAX_INSTANCE" ];then |
| 125 | printf "\n********** You choose to create ${INSTANCE}th instance of ONAP \n" |
| 126 | printf "\n********** Due to port allocation only ${MAX_INSTANCE} instances of ONAP is allowed per kubernetes deployment\n" |
| 127 | exit 1 |
| 128 | fi |
| 129 | |
| 130 | start=$((300+2*INSTANCE)) |
| 131 | end=$((start+1)) |
| 132 | printf "\n********** Creating instance ${INSTANCE} of ONAP with port range ${start}00 and ${end}99\n" |
| 133 | |
| 134 | fi |
| 135 | |
Mike Elliott | d17accd | 2017-08-14 16:21:40 -0400 | [diff] [blame] | 136 | printf "\n********** Creating ONAP: ${ONAP_APPS[*]}\n" |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 137 | |
| 138 | for i in ${ONAP_APPS[@]}; do |
Mike Elliott | d17accd | 2017-08-14 16:21:40 -0400 | [diff] [blame] | 139 | printf "\nCreating namespace **********\n" |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 140 | create_namespace $NS $i |
| 141 | |
Mike Elliott | d17accd | 2017-08-14 16:21:40 -0400 | [diff] [blame] | 142 | printf "\nCreating registry secret **********\n" |
| 143 | create_registry_key $NS $i $ONAP_DOCKER_REGISTRY_KEY $ONAP_DOCKER_REGISTRY $DU $DP $ONAP_DOCKER_MAIL |
| 144 | |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 145 | if [[ "$INCL_SVC" == true ]]; then |
Mike Elliott | d17accd | 2017-08-14 16:21:40 -0400 | [diff] [blame] | 146 | printf "\nCreating service **********\n" |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame] | 147 | create_service $NS $i $start $end |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 148 | fi |
| 149 | |
| 150 | printf "\n" |
| 151 | done |
| 152 | |
Mike Elliott | d17accd | 2017-08-14 16:21:40 -0400 | [diff] [blame] | 153 | printf "\n\n********** Creating deployments for ${ONAP_APPS[*]} ********** \n" |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 154 | for i in ${ONAP_APPS[@]}; do |
kerenj | 74d723a | 2017-08-22 15:27:04 +0000 | [diff] [blame] | 155 | _FILES_PATH=$(echo ../$i) |
| 156 | configure_app $NS $i $_FILES_PATH $start $end |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 157 | /bin/bash $i.sh $NS $i 'create' |
| 158 | done |
| 159 | |
kerenj | 74d723a | 2017-08-22 15:27:04 +0000 | [diff] [blame] | 160 | for i in ${HELM_APPS[@]}; do |
| 161 | printf "\nCreating namespace **********\n" |
| 162 | create_namespace $NS $i |
| 163 | |
| 164 | printf "\nCreating registry secret **********\n" |
| 165 | create_registry_key $NS $i $ONAP_DOCKER_REGISTRY_KEY $ONAP_DOCKER_REGISTRY $DU $DP $ONAP_DOCKER_MAIL |
| 166 | |
| 167 | printf "\nCreating deployments and services **********\n" |
| 168 | _FILES_PATH=$(echo ../$i/templates) |
| 169 | configure_app $NS $i $_FILES_PATH $start $end |
| 170 | create_onap_helm $NS $i |
| 171 | |
| 172 | printf "\n" |
| 173 | done |
| 174 | |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame] | 175 | printf "\n**** Done ****\n" |
kerenj | 74d723a | 2017-08-22 15:27:04 +0000 | [diff] [blame] | 176 | |