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 | |
Frank A. Zdarsky | 8407a7a | 2018-03-20 11:07:13 +0100 | [diff] [blame] | 86 | cmd=`echo helm install $LOCATION/$2/ --name $1-$2 --namespace $1 --set nsPrefix=$1,nodePortPrefix=$3 ${HELM_VALUES_ADDITION}` |
tzvika avni | 213d2ef | 2017-09-07 17:54:15 +0300 | [diff] [blame] | 87 | eval ${cmd} |
| 88 | check_return_code $cmd |
Mike Elliott | d17accd | 2017-08-14 16:21:40 -0400 | [diff] [blame] | 89 | } |
| 90 | |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 91 | #MAINs |
| 92 | NS= |
tzvika avni | 67a8111 | 2017-09-07 19:43:57 +0300 | [diff] [blame] | 93 | HELM_VALUES_FILEPATH="" |
| 94 | LOCATION="../" |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 95 | INCL_SVC=true |
| 96 | APP= |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame] | 97 | INSTANCE=1 |
| 98 | MAX_INSTANCE=5 |
Borislav Glozman | 5197e2e | 2017-07-24 10:45:28 +0300 | [diff] [blame] | 99 | DU=$ONAP_DOCKER_USER |
| 100 | DP=$ONAP_DOCKER_PASS |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 101 | |
BorislavG | 8bfc6cf | 2018-02-27 15:04:26 +0000 | [diff] [blame] | 102 | SINGLE_COMPONENT=false |
| 103 | |
tzvika avni | 67a8111 | 2017-09-07 19:43:57 +0300 | [diff] [blame] | 104 | 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] | 105 | case $PARAM in |
| 106 | u) |
| 107 | usage |
| 108 | exit 1 |
| 109 | ;; |
| 110 | n) |
| 111 | NS=${OPTARG} |
| 112 | ;; |
tzvika avni | e3cbfa3 | 2017-09-07 16:42:37 +0300 | [diff] [blame] | 113 | v) |
| 114 | HELM_VALUES_FILEPATH=${OPTARG} |
| 115 | ;; |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame] | 116 | i) |
| 117 | INSTANCE=${OPTARG} |
| 118 | ;; |
tzvika avni | 67a8111 | 2017-09-07 19:43:57 +0300 | [diff] [blame] | 119 | l) |
| 120 | LOCATION=${OPTARG} |
| 121 | ;; |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 122 | a) |
BorislavG | 8bfc6cf | 2018-02-27 15:04:26 +0000 | [diff] [blame] | 123 | SINGLE_COMPONENT=true |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 124 | APP=${OPTARG} |
| 125 | if [[ -z $APP ]]; then |
| 126 | usage |
| 127 | exit 1 |
| 128 | fi |
| 129 | ;; |
Borislav Glozman | 5197e2e | 2017-07-24 10:45:28 +0300 | [diff] [blame] | 130 | du) |
| 131 | DU=${OPTARG} |
| 132 | ;; |
| 133 | dp) |
| 134 | DP=${OPTARG} |
| 135 | ;; |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 136 | ?) |
| 137 | usage |
| 138 | exit |
| 139 | ;; |
| 140 | esac |
| 141 | done |
| 142 | |
| 143 | if [[ -z $NS ]]; then |
| 144 | usage |
| 145 | exit 1 |
| 146 | fi |
| 147 | |
| 148 | if [[ ! -z "$APP" ]]; then |
kerenj | 8010284 | 2017-08-24 13:54:21 +0000 | [diff] [blame] | 149 | HELM_APPS=($APP) |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 150 | fi |
| 151 | |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame] | 152 | |
kerenj | 8010284 | 2017-08-24 13:54:21 +0000 | [diff] [blame] | 153 | if [ "$INSTANCE" -gt "$MAX_INSTANCE" ];then |
| 154 | printf "\n********** You choose to create ${INSTANCE}th instance of ONAP \n" |
| 155 | printf "\n********** Due to port allocation only ${MAX_INSTANCE} instances of ONAP is allowed per kubernetes deployment\n" |
| 156 | exit 1 |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame] | 157 | fi |
| 158 | |
kerenj | 8010284 | 2017-08-24 13:54:21 +0000 | [diff] [blame] | 159 | start=$((300+2*INSTANCE)) |
| 160 | end=$((start+1)) |
| 161 | |
| 162 | printf "\n********** Creating instance ${INSTANCE} of ONAP with port range ${start}00 and ${end}99\n" |
| 163 | |
| 164 | |
Mike Elliott | d17accd | 2017-08-14 16:21:40 -0400 | [diff] [blame] | 165 | printf "\n********** Creating ONAP: ${ONAP_APPS[*]}\n" |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 166 | |
BorislavG | 8bfc6cf | 2018-02-27 15:04:26 +0000 | [diff] [blame] | 167 | if [ "$SINGLE_COMPONENT" == "false" ] |
| 168 | then |
| 169 | printf "\nCreating namespace **********\n" |
| 170 | create_namespace $NS |
| 171 | |
| 172 | printf "\nCreating registry secret **********\n" |
| 173 | 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] | 174 | |
| 175 | printf "\nCreating service account **********\n" |
| 176 | create_service_account $NS |
BorislavG | 8bfc6cf | 2018-02-27 15:04:26 +0000 | [diff] [blame] | 177 | fi |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 178 | |
kerenj | 8010284 | 2017-08-24 13:54:21 +0000 | [diff] [blame] | 179 | printf "\n\n********** Creating deployments for ${HELM_APPS[*]} ********** \n" |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 180 | |
kerenj | 74d723a | 2017-08-22 15:27:04 +0000 | [diff] [blame] | 181 | for i in ${HELM_APPS[@]}; do |
kerenj | 74d723a | 2017-08-22 15:27:04 +0000 | [diff] [blame] | 182 | |
kerenj | 74d723a | 2017-08-22 15:27:04 +0000 | [diff] [blame] | 183 | printf "\nCreating deployments and services **********\n" |
tzvika avni | 67a8111 | 2017-09-07 19:43:57 +0300 | [diff] [blame] | 184 | create_onap_helm $NS $i $start |
kerenj | 74d723a | 2017-08-22 15:27:04 +0000 | [diff] [blame] | 185 | |
| 186 | printf "\n" |
| 187 | done |
| 188 | |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame] | 189 | printf "\n**** Done ****\n" |