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) |
tzvika avni | e3cbfa3 | 2017-09-07 16:42:37 +0300 | [diff] [blame] | 11 | -v [VALUES] : HELM values filepath (usefull when deploying one component at a time) |
tzvika avni | 67a8111 | 2017-09-07 19:43:57 +0300 | [diff] [blame] | 12 | -l [LOCATION] : Location of oom project |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame] | 13 | -i [INSTANCE] : ONAP deployment instance # (default: 1) |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 14 | -a [APP] : Specify a specific ONAP component (default: all) |
| 15 | from the following choices: |
Dusan Rozman | 03aa27e | 2017-10-11 13:04:23 -0400 | [diff] [blame] | 16 | sdc, aai ,mso, message-router, robot, vid, aaf, uui |
Dusan Rozman | 75c07c4 | 2017-09-25 10:28:28 -0400 | [diff] [blame] | 17 | sdnc, portal, policy, appc, multicloud, clamp, consul, vnfsdk |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 18 | EOF |
| 19 | } |
| 20 | |
tzvika avni | 213d2ef | 2017-09-07 17:54:15 +0300 | [diff] [blame] | 21 | check_return_code(){ |
| 22 | ret=$? |
| 23 | if [ $ret -ne 0 ]; then |
| 24 | printf "The command $1 returned with error code $ret \n" 1>&2 |
| 25 | exit $ret |
| 26 | fi |
| 27 | } |
| 28 | |
Anaël Closson | 40cdf49 | 2017-10-09 14:52:24 +0200 | [diff] [blame] | 29 | create_service_account() { |
BorislavG | 8bfc6cf | 2018-02-27 15:04:26 +0000 | [diff] [blame] | 30 | # cmd=`echo kubectl create clusterrolebinding $1-$2-admin-binding --clusterrole=cluster-admin --serviceaccount=$1-$2:default` |
| 31 | cmd=`echo kubectl create clusterrolebinding $1-$2-admin-binding --clusterrole=cluster-admin --serviceaccount=$1:default` |
Anaël Closson | 40cdf49 | 2017-10-09 14:52:24 +0200 | [diff] [blame] | 32 | eval ${cmd} |
| 33 | check_return_code $cmd |
| 34 | } |
tzvika avni | 213d2ef | 2017-09-07 17:54:15 +0300 | [diff] [blame] | 35 | |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 36 | create_namespace() { |
BorislavG | 8bfc6cf | 2018-02-27 15:04:26 +0000 | [diff] [blame] | 37 | cmd=`echo kubectl create namespace $1` |
tzvika avni | 213d2ef | 2017-09-07 17:54:15 +0300 | [diff] [blame] | 38 | eval ${cmd} |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 39 | } |
| 40 | |
Borislav Glozman | 5197e2e | 2017-07-24 10:45:28 +0300 | [diff] [blame] | 41 | create_registry_key() { |
BorislavG | 8bfc6cf | 2018-02-27 15:04:26 +0000 | [diff] [blame] | 42 | # cmd=`echo kubectl --namespace $1-$2 create secret docker-registry $3 --docker-server=$4 --docker-username=$5 --docker-password=$6 --docker-email=$7` |
| 43 | cmd=`echo kubectl --namespace $1 create secret docker-registry $2 --docker-server=$3 --docker-username=$4 --docker-password=$5 --docker-email=$6` |
tzvika avni | 213d2ef | 2017-09-07 17:54:15 +0300 | [diff] [blame] | 44 | eval ${cmd} |
| 45 | check_return_code $cmd |
Borislav Glozman | 5197e2e | 2017-07-24 10:45:28 +0300 | [diff] [blame] | 46 | } |
| 47 | |
Mandeep Khinda | de8d47e | 2017-09-21 18:22:10 +0000 | [diff] [blame] | 48 | configure_dcaegen2() { |
| 49 | if [ ! -s "$OPENSTACK_PRIVATE_KEY_PATH" ] |
| 50 | then |
| 51 | echo "ERROR: $OPENSTACK_PRIVATE_KEY_PATH does not exist or is empty. Cannot launch dcae gen2." |
| 52 | return 1 |
| 53 | fi |
| 54 | |
| 55 | cmd=`echo kubectl --namespace $1-$2 create secret generic $2-openstack-ssh-private-key --from-file=key=${OPENSTACK_PRIVATE_KEY_PATH}` |
| 56 | eval ${cmd} |
| 57 | check_return_code $cmd |
| 58 | |
| 59 | if [ ! -s "$DCAEGEN2_CONFIG_INPUT_FILE_PATH" ] |
| 60 | then |
| 61 | echo "ERROR: $DCAEGEN2_CONFIG_INPUT_FILE_PATH does not exist or is empty. Cannot launch dcae gen2." |
| 62 | return 1 |
| 63 | fi |
| 64 | |
| 65 | cmd=`echo kubectl --namespace $1-$2 create configmap $2-config-inputs --from-file=inputs.yaml=${DCAEGEN2_CONFIG_INPUT_FILE_PATH}` |
| 66 | eval ${cmd} |
| 67 | check_return_code $cmd |
| 68 | } |
| 69 | |
kerenj | 74d723a | 2017-08-22 15:27:04 +0000 | [diff] [blame] | 70 | create_onap_helm() { |
tzvika avni | e3cbfa3 | 2017-09-07 16:42:37 +0300 | [diff] [blame] | 71 | HELM_VALUES_ADDITION="" |
tzvika avni | 67a8111 | 2017-09-07 19:43:57 +0300 | [diff] [blame] | 72 | if [[ ! -z $HELM_VALUES_FILEPATH ]]; then |
| 73 | HELM_VALUES_ADDITION="--values=$HELM_VALUES_FILEPATH" |
tzvika avni | e3cbfa3 | 2017-09-07 16:42:37 +0300 | [diff] [blame] | 74 | fi |
Mandeep Khinda | de8d47e | 2017-09-21 18:22:10 +0000 | [diff] [blame] | 75 | # Have to put a check for dcaegen2 because it requires external files to helm |
| 76 | # which should not be part of the Chart. |
| 77 | if [ "$2" = "dcaegen2" ]; |
| 78 | then |
| 79 | configure_dcaegen2 $1 $2 |
| 80 | local result=$? |
| 81 | if [ $result -ne 0 ] |
| 82 | then |
| 83 | echo "ERROR: dcaegen2 failed to configure: Pre-requisites not met. Skipping deploying it and continue" |
| 84 | return |
| 85 | fi |
| 86 | fi |
| 87 | |
tzvika | 58a0c10 | 2018-01-11 10:41:47 +0200 | [diff] [blame] | 88 | # assign default auth token |
| 89 | if [[ -z $ONAP_DEFAULT_AUTH_TOKEN ]]; then |
BorislavG | 8bfc6cf | 2018-02-27 15:04:26 +0000 | [diff] [blame] | 90 | DEFAULT_SECRET=`kubectl get secrets -n $1 | grep default-token | awk '{ print $1}'` |
| 91 | ONAP_DEFAULT_AUTH_TOKEN=`kubectl get secrets $DEFAULT_SECRET -n $1 -o yaml | grep 'token:' | awk '{ print $2}' | base64 --decode` |
tzvika | 58a0c10 | 2018-01-11 10:41:47 +0200 | [diff] [blame] | 92 | fi |
| 93 | |
| 94 | cmd=`echo helm install $LOCATION/$2/ --name $1-$2 --namespace $1 --set nsPrefix=$1,nodePortPrefix=$3,kubeMasterAuthToken=$ONAP_DEFAULT_AUTH_TOKEN ${HELM_VALUES_ADDITION}` |
tzvika avni | 213d2ef | 2017-09-07 17:54:15 +0300 | [diff] [blame] | 95 | eval ${cmd} |
| 96 | check_return_code $cmd |
Mike Elliott | d17accd | 2017-08-14 16:21:40 -0400 | [diff] [blame] | 97 | } |
| 98 | |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 99 | #MAINs |
| 100 | NS= |
tzvika avni | 67a8111 | 2017-09-07 19:43:57 +0300 | [diff] [blame] | 101 | HELM_VALUES_FILEPATH="" |
| 102 | LOCATION="../" |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 103 | INCL_SVC=true |
| 104 | APP= |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame] | 105 | INSTANCE=1 |
| 106 | MAX_INSTANCE=5 |
Borislav Glozman | 5197e2e | 2017-07-24 10:45:28 +0300 | [diff] [blame] | 107 | DU=$ONAP_DOCKER_USER |
| 108 | DP=$ONAP_DOCKER_PASS |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 109 | |
BorislavG | 8bfc6cf | 2018-02-27 15:04:26 +0000 | [diff] [blame] | 110 | SINGLE_COMPONENT=false |
| 111 | |
tzvika avni | 67a8111 | 2017-09-07 19:43:57 +0300 | [diff] [blame] | 112 | while getopts ":n:u:s:i:a:du:dp:l:v:" PARAM; do |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 113 | case $PARAM in |
| 114 | u) |
| 115 | usage |
| 116 | exit 1 |
| 117 | ;; |
| 118 | n) |
| 119 | NS=${OPTARG} |
| 120 | ;; |
tzvika avni | e3cbfa3 | 2017-09-07 16:42:37 +0300 | [diff] [blame] | 121 | v) |
| 122 | HELM_VALUES_FILEPATH=${OPTARG} |
| 123 | ;; |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame] | 124 | i) |
| 125 | INSTANCE=${OPTARG} |
| 126 | ;; |
tzvika avni | 67a8111 | 2017-09-07 19:43:57 +0300 | [diff] [blame] | 127 | l) |
| 128 | LOCATION=${OPTARG} |
| 129 | ;; |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 130 | a) |
BorislavG | 8bfc6cf | 2018-02-27 15:04:26 +0000 | [diff] [blame] | 131 | SINGLE_COMPONENT=true |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 132 | APP=${OPTARG} |
| 133 | if [[ -z $APP ]]; then |
| 134 | usage |
| 135 | exit 1 |
| 136 | fi |
| 137 | ;; |
Borislav Glozman | 5197e2e | 2017-07-24 10:45:28 +0300 | [diff] [blame] | 138 | du) |
| 139 | DU=${OPTARG} |
| 140 | ;; |
| 141 | dp) |
| 142 | DP=${OPTARG} |
| 143 | ;; |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 144 | ?) |
| 145 | usage |
| 146 | exit |
| 147 | ;; |
| 148 | esac |
| 149 | done |
| 150 | |
| 151 | if [[ -z $NS ]]; then |
| 152 | usage |
| 153 | exit 1 |
| 154 | fi |
| 155 | |
| 156 | if [[ ! -z "$APP" ]]; then |
kerenj | 8010284 | 2017-08-24 13:54:21 +0000 | [diff] [blame] | 157 | HELM_APPS=($APP) |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 158 | fi |
| 159 | |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame] | 160 | |
kerenj | 8010284 | 2017-08-24 13:54:21 +0000 | [diff] [blame] | 161 | if [ "$INSTANCE" -gt "$MAX_INSTANCE" ];then |
| 162 | printf "\n********** You choose to create ${INSTANCE}th instance of ONAP \n" |
| 163 | printf "\n********** Due to port allocation only ${MAX_INSTANCE} instances of ONAP is allowed per kubernetes deployment\n" |
| 164 | exit 1 |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame] | 165 | fi |
| 166 | |
kerenj | 8010284 | 2017-08-24 13:54:21 +0000 | [diff] [blame] | 167 | start=$((300+2*INSTANCE)) |
| 168 | end=$((start+1)) |
| 169 | |
| 170 | printf "\n********** Creating instance ${INSTANCE} of ONAP with port range ${start}00 and ${end}99\n" |
| 171 | |
| 172 | |
Mike Elliott | d17accd | 2017-08-14 16:21:40 -0400 | [diff] [blame] | 173 | printf "\n********** Creating ONAP: ${ONAP_APPS[*]}\n" |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 174 | |
BorislavG | 8bfc6cf | 2018-02-27 15:04:26 +0000 | [diff] [blame] | 175 | if [ "$SINGLE_COMPONENT" == "false" ] |
| 176 | then |
| 177 | printf "\nCreating namespace **********\n" |
| 178 | create_namespace $NS |
| 179 | |
| 180 | printf "\nCreating registry secret **********\n" |
| 181 | create_registry_key $NS ${NS}-docker-registry-key $ONAP_DOCKER_REGISTRY $DU $DP $ONAP_DOCKER_MAIL |
| 182 | fi |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 183 | |
kerenj | 8010284 | 2017-08-24 13:54:21 +0000 | [diff] [blame] | 184 | printf "\n\n********** Creating deployments for ${HELM_APPS[*]} ********** \n" |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 185 | |
kerenj | 74d723a | 2017-08-22 15:27:04 +0000 | [diff] [blame] | 186 | for i in ${HELM_APPS[@]}; do |
kerenj | 74d723a | 2017-08-22 15:27:04 +0000 | [diff] [blame] | 187 | |
Anaël Closson | 40cdf49 | 2017-10-09 14:52:24 +0200 | [diff] [blame] | 188 | printf "\nCreating service account **********\n" |
| 189 | create_service_account $NS $i |
| 190 | |
kerenj | 74d723a | 2017-08-22 15:27:04 +0000 | [diff] [blame] | 191 | printf "\nCreating deployments and services **********\n" |
tzvika avni | 67a8111 | 2017-09-07 19:43:57 +0300 | [diff] [blame] | 192 | create_onap_helm $NS $i $start |
kerenj | 74d723a | 2017-08-22 15:27:04 +0000 | [diff] [blame] | 193 | |
| 194 | printf "\n" |
| 195 | done |
| 196 | |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame] | 197 | printf "\n**** Done ****\n" |