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: |
| 16 | sdc, aai ,mso, message-router, robot, |
| 17 | vid, sdnc, portal, policy, appc |
| 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 | |
| 29 | |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 30 | create_namespace() { |
tzvika avni | 213d2ef | 2017-09-07 17:54:15 +0300 | [diff] [blame^] | 31 | cmd=`echo kubectl create namespace $1-$2` |
| 32 | eval ${cmd} |
| 33 | check_return_code $cmd |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 34 | } |
| 35 | |
Borislav Glozman | 5197e2e | 2017-07-24 10:45:28 +0300 | [diff] [blame] | 36 | create_registry_key() { |
tzvika avni | 213d2ef | 2017-09-07 17:54:15 +0300 | [diff] [blame^] | 37 | cmd=`echo kubectl --namespace $1-$2 create secret docker-registry $3 --docker-server=$4 --docker-username=$5 --docker-password=$6 --docker-email=$7` |
| 38 | eval ${cmd} |
| 39 | check_return_code $cmd |
Borislav Glozman | 5197e2e | 2017-07-24 10:45:28 +0300 | [diff] [blame] | 40 | } |
| 41 | |
kerenj | 74d723a | 2017-08-22 15:27:04 +0000 | [diff] [blame] | 42 | create_onap_helm() { |
tzvika avni | e3cbfa3 | 2017-09-07 16:42:37 +0300 | [diff] [blame] | 43 | HELM_VALUES_ADDITION="" |
tzvika avni | 67a8111 | 2017-09-07 19:43:57 +0300 | [diff] [blame] | 44 | if [[ ! -z $HELM_VALUES_FILEPATH ]]; then |
| 45 | HELM_VALUES_ADDITION="--values=$HELM_VALUES_FILEPATH" |
tzvika avni | e3cbfa3 | 2017-09-07 16:42:37 +0300 | [diff] [blame] | 46 | fi |
tzvika avni | 213d2ef | 2017-09-07 17:54:15 +0300 | [diff] [blame^] | 47 | cmd=`echo helm install $LOCATION/$2/ --name $1-$2 --namespace $1 --set nsPrefix=$1,nodePortPrefix=$3 ${HELM_VALUES_ADDITION}` |
| 48 | eval ${cmd} |
| 49 | check_return_code $cmd |
Mike Elliott | d17accd | 2017-08-14 16:21:40 -0400 | [diff] [blame] | 50 | } |
| 51 | |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 52 | #MAINs |
| 53 | NS= |
tzvika avni | 67a8111 | 2017-09-07 19:43:57 +0300 | [diff] [blame] | 54 | HELM_VALUES_FILEPATH="" |
| 55 | LOCATION="../" |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 56 | INCL_SVC=true |
| 57 | APP= |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame] | 58 | INSTANCE=1 |
| 59 | MAX_INSTANCE=5 |
Borislav Glozman | 5197e2e | 2017-07-24 10:45:28 +0300 | [diff] [blame] | 60 | DU=$ONAP_DOCKER_USER |
| 61 | DP=$ONAP_DOCKER_PASS |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 62 | |
tzvika avni | 67a8111 | 2017-09-07 19:43:57 +0300 | [diff] [blame] | 63 | 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] | 64 | case $PARAM in |
| 65 | u) |
| 66 | usage |
| 67 | exit 1 |
| 68 | ;; |
| 69 | n) |
| 70 | NS=${OPTARG} |
| 71 | ;; |
tzvika avni | e3cbfa3 | 2017-09-07 16:42:37 +0300 | [diff] [blame] | 72 | v) |
| 73 | HELM_VALUES_FILEPATH=${OPTARG} |
| 74 | ;; |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame] | 75 | i) |
| 76 | INSTANCE=${OPTARG} |
| 77 | ;; |
tzvika avni | 67a8111 | 2017-09-07 19:43:57 +0300 | [diff] [blame] | 78 | l) |
| 79 | LOCATION=${OPTARG} |
| 80 | ;; |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 81 | a) |
| 82 | APP=${OPTARG} |
| 83 | if [[ -z $APP ]]; then |
| 84 | usage |
| 85 | exit 1 |
| 86 | fi |
| 87 | ;; |
Borislav Glozman | 5197e2e | 2017-07-24 10:45:28 +0300 | [diff] [blame] | 88 | du) |
| 89 | DU=${OPTARG} |
| 90 | ;; |
| 91 | dp) |
| 92 | DP=${OPTARG} |
| 93 | ;; |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 94 | ?) |
| 95 | usage |
| 96 | exit |
| 97 | ;; |
| 98 | esac |
| 99 | done |
| 100 | |
| 101 | if [[ -z $NS ]]; then |
| 102 | usage |
| 103 | exit 1 |
| 104 | fi |
| 105 | |
| 106 | if [[ ! -z "$APP" ]]; then |
kerenj | 8010284 | 2017-08-24 13:54:21 +0000 | [diff] [blame] | 107 | HELM_APPS=($APP) |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 108 | fi |
| 109 | |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame] | 110 | |
kerenj | 8010284 | 2017-08-24 13:54:21 +0000 | [diff] [blame] | 111 | if [ "$INSTANCE" -gt "$MAX_INSTANCE" ];then |
| 112 | printf "\n********** You choose to create ${INSTANCE}th instance of ONAP \n" |
| 113 | printf "\n********** Due to port allocation only ${MAX_INSTANCE} instances of ONAP is allowed per kubernetes deployment\n" |
| 114 | exit 1 |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame] | 115 | fi |
| 116 | |
kerenj | 8010284 | 2017-08-24 13:54:21 +0000 | [diff] [blame] | 117 | start=$((300+2*INSTANCE)) |
| 118 | end=$((start+1)) |
| 119 | |
| 120 | printf "\n********** Creating instance ${INSTANCE} of ONAP with port range ${start}00 and ${end}99\n" |
| 121 | |
| 122 | |
Mike Elliott | d17accd | 2017-08-14 16:21:40 -0400 | [diff] [blame] | 123 | printf "\n********** Creating ONAP: ${ONAP_APPS[*]}\n" |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 124 | |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 125 | |
kerenj | 8010284 | 2017-08-24 13:54:21 +0000 | [diff] [blame] | 126 | printf "\n\n********** Creating deployments for ${HELM_APPS[*]} ********** \n" |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 127 | |
kerenj | 74d723a | 2017-08-22 15:27:04 +0000 | [diff] [blame] | 128 | for i in ${HELM_APPS[@]}; do |
| 129 | printf "\nCreating namespace **********\n" |
tzvika avni | 67a8111 | 2017-09-07 19:43:57 +0300 | [diff] [blame] | 130 | create_namespace $NS $i |
kerenj | 74d723a | 2017-08-22 15:27:04 +0000 | [diff] [blame] | 131 | |
| 132 | printf "\nCreating registry secret **********\n" |
Mandeep Khinda | 0e8f889 | 2017-08-25 03:31:17 +0000 | [diff] [blame] | 133 | 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] | 134 | |
| 135 | printf "\nCreating deployments and services **********\n" |
tzvika avni | 67a8111 | 2017-09-07 19:43:57 +0300 | [diff] [blame] | 136 | create_onap_helm $NS $i $start |
kerenj | 74d723a | 2017-08-22 15:27:04 +0000 | [diff] [blame] | 137 | |
| 138 | printf "\n" |
| 139 | done |
| 140 | |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame] | 141 | printf "\n**** Done ****\n" |