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