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