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 | |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 5 | usage() { |
| 6 | cat <<EOF |
| 7 | Usage: $0 [PARAMs] |
| 8 | -u : Display usage |
| 9 | -n [NAMESPACE] : Kubernetes namespace (required) |
| 10 | -s false : Exclude services (default: true) |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame^] | 11 | -i [INSTANCE] : ONAP deployment instance # (default: 1) |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 12 | -a [APP] : Specify a specific ONAP component (default: all) |
| 13 | from the following choices: |
| 14 | sdc, aai ,mso, message-router, robot, |
| 15 | vid, sdnc, portal, policy, appc |
| 16 | EOF |
| 17 | } |
| 18 | |
| 19 | create_namespace() { |
| 20 | kubectl create namespace $1-$2 |
| 21 | } |
| 22 | |
Borislav Glozman | 5197e2e | 2017-07-24 10:45:28 +0300 | [diff] [blame] | 23 | create_registry_key() { |
| 24 | kubectl --namespace $1-$2 create secret docker-registry $3 --docker-server=$4 --docker-username=$5 --docker-password=$6 --docker-email=$7 |
| 25 | } |
| 26 | |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 27 | create_service() { |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame^] | 28 | sed -i -- 's/nodePort: [0-9]\{2\}[02468]\{1\}/nodePort: '"$3"'/g' ../$2/all-services.yaml |
| 29 | sed -i -- 's/nodePort: [0-9]\{2\}[13579]\{1\}/nodePort: '"$4"'/g' ../$2/all-services.yaml |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 30 | kubectl --namespace $1-$2 create -f ../$2/all-services.yaml |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame^] | 31 | mv ../$2/all-services.yaml-- ../$2/all-services.yaml |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | #MAINs |
| 35 | NS= |
| 36 | INCL_SVC=true |
| 37 | APP= |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame^] | 38 | INSTANCE=1 |
| 39 | MAX_INSTANCE=5 |
Borislav Glozman | 5197e2e | 2017-07-24 10:45:28 +0300 | [diff] [blame] | 40 | DU=$ONAP_DOCKER_USER |
| 41 | DP=$ONAP_DOCKER_PASS |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 42 | |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame^] | 43 | while getopts ":n:u:s:i:a:du:dp:" PARAM; do |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 44 | case $PARAM in |
| 45 | u) |
| 46 | usage |
| 47 | exit 1 |
| 48 | ;; |
| 49 | n) |
| 50 | NS=${OPTARG} |
| 51 | ;; |
| 52 | s) |
| 53 | INCL_SVC=${OPTARG} |
| 54 | ;; |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame^] | 55 | i) |
| 56 | INSTANCE=${OPTARG} |
| 57 | ;; |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 58 | a) |
| 59 | APP=${OPTARG} |
| 60 | if [[ -z $APP ]]; then |
| 61 | usage |
| 62 | exit 1 |
| 63 | fi |
| 64 | ;; |
Borislav Glozman | 5197e2e | 2017-07-24 10:45:28 +0300 | [diff] [blame] | 65 | du) |
| 66 | DU=${OPTARG} |
| 67 | ;; |
| 68 | dp) |
| 69 | DP=${OPTARG} |
| 70 | ;; |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 71 | ?) |
| 72 | usage |
| 73 | exit |
| 74 | ;; |
| 75 | esac |
| 76 | done |
| 77 | |
| 78 | if [[ -z $NS ]]; then |
| 79 | usage |
| 80 | exit 1 |
| 81 | fi |
| 82 | |
| 83 | if [[ ! -z "$APP" ]]; then |
| 84 | ONAP_APPS=($APP) |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 85 | fi |
| 86 | |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame^] | 87 | if [[ "$INCL_SVC" == true ]]; then |
| 88 | |
| 89 | if [ "$INSTANCE" -gt "$MAX_INSTANCE" ];then |
| 90 | printf "\n********** You choose to create ${INSTANCE}th instance of ONAP \n" |
| 91 | printf "\n********** Due to port allocation only ${MAX_INSTANCE} instances of ONAP is allowed per kubernetes deployment\n" |
| 92 | exit 1 |
| 93 | fi |
| 94 | |
| 95 | start=$((300+2*INSTANCE)) |
| 96 | end=$((start+1)) |
| 97 | printf "\n********** Creating instance ${INSTANCE} of ONAP with port range ${start}00 and ${end}99\n" |
| 98 | |
| 99 | fi |
| 100 | |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 101 | printf "\n********** Creating up ONAP: ${ONAP_APPS[*]}\n" |
| 102 | |
| 103 | for i in ${ONAP_APPS[@]}; do |
| 104 | printf "\nCreating namespaces **********\n" |
| 105 | create_namespace $NS $i |
| 106 | |
| 107 | if [[ "$INCL_SVC" == true ]]; then |
| 108 | printf "\nCreating services **********\n" |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame^] | 109 | create_service $NS $i $start $end |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 110 | fi |
| 111 | |
| 112 | printf "\n" |
| 113 | done |
| 114 | |
| 115 | printf "\n\n********** Creating deployments for ${ONAP_APPS[*]} ********** \n" |
| 116 | for i in ${ONAP_APPS[@]}; do |
Borislav Glozman | 5197e2e | 2017-07-24 10:45:28 +0300 | [diff] [blame] | 117 | create_registry_key $NS $i $ONAP_DOCKER_REGISTRY_KEY $ONAP_DOCKER_REGISTRY $DU $DP $ONAP_DOCKER_MAIL |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 118 | /bin/bash $i.sh $NS $i 'create' |
| 119 | done |
| 120 | |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame^] | 121 | printf "\n**** Done ****\n" |