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