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 | |
Mike Elliott | d17accd | 2017-08-14 16:21:40 -0400 | [diff] [blame] | 34 | configure_app() { |
| 35 | # if previous configuration exists put back original template file |
| 36 | for file in ../$2/*.yaml; do |
| 37 | if [ -e "$file-template" ]; then |
| 38 | mv "$file-template" "${file%}" |
| 39 | fi |
| 40 | done |
| 41 | |
| 42 | # replace the default 'onap' namespace qualification of K8s hostnames within |
| 43 | # the config files |
| 44 | # note: this will create a '-template' file within the component's directory |
| 45 | # this is not ideal and should be addressed (along with the replacement |
| 46 | # of sed commands for configuration) by the future configuration |
| 47 | # user stories (ie. OOM-51 to OOM-53) |
| 48 | find ../$2 -type f -exec sed -i -template "s/onap-/$1-/g" {} \; |
| 49 | |
Munir Ahmad | 76610be | 2017-08-17 11:56:15 -0400 | [diff] [blame] | 50 | # replace the default '/dockerdata-nfs/onapdemo' volume mount paths |
| 51 | find ../$2 -iname "*.yaml" -type f -exec sed -i -e 's/dockerdata-nfs\/[a-zA-Z0-9\\-]*\//dockerdata-nfs\/'"$1"'\//g' {} \; |
Mike Elliott | d17accd | 2017-08-14 16:21:40 -0400 | [diff] [blame] | 52 | rm -f ../$2/*.yaml-e |
| 53 | } |
| 54 | |
| 55 | |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 56 | #MAINs |
| 57 | NS= |
| 58 | INCL_SVC=true |
| 59 | APP= |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame] | 60 | INSTANCE=1 |
| 61 | MAX_INSTANCE=5 |
Borislav Glozman | 5197e2e | 2017-07-24 10:45:28 +0300 | [diff] [blame] | 62 | DU=$ONAP_DOCKER_USER |
| 63 | DP=$ONAP_DOCKER_PASS |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 64 | |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame] | 65 | while getopts ":n:u:s:i:a:du:dp:" PARAM; do |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 66 | case $PARAM in |
| 67 | u) |
| 68 | usage |
| 69 | exit 1 |
| 70 | ;; |
| 71 | n) |
| 72 | NS=${OPTARG} |
| 73 | ;; |
| 74 | s) |
| 75 | INCL_SVC=${OPTARG} |
| 76 | ;; |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame] | 77 | i) |
| 78 | INSTANCE=${OPTARG} |
| 79 | ;; |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 80 | a) |
| 81 | APP=${OPTARG} |
| 82 | if [[ -z $APP ]]; then |
| 83 | usage |
| 84 | exit 1 |
| 85 | fi |
| 86 | ;; |
Borislav Glozman | 5197e2e | 2017-07-24 10:45:28 +0300 | [diff] [blame] | 87 | du) |
| 88 | DU=${OPTARG} |
| 89 | ;; |
| 90 | dp) |
| 91 | DP=${OPTARG} |
| 92 | ;; |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 93 | ?) |
| 94 | usage |
| 95 | exit |
| 96 | ;; |
| 97 | esac |
| 98 | done |
| 99 | |
| 100 | if [[ -z $NS ]]; then |
| 101 | usage |
| 102 | exit 1 |
| 103 | fi |
| 104 | |
| 105 | if [[ ! -z "$APP" ]]; then |
| 106 | ONAP_APPS=($APP) |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 107 | fi |
| 108 | |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame] | 109 | if [[ "$INCL_SVC" == true ]]; then |
| 110 | |
| 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 |
| 115 | fi |
| 116 | |
| 117 | start=$((300+2*INSTANCE)) |
| 118 | end=$((start+1)) |
| 119 | printf "\n********** Creating instance ${INSTANCE} of ONAP with port range ${start}00 and ${end}99\n" |
| 120 | |
| 121 | fi |
| 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 | |
| 125 | for i in ${ONAP_APPS[@]}; do |
Mike Elliott | d17accd | 2017-08-14 16:21:40 -0400 | [diff] [blame] | 126 | printf "\nCreating namespace **********\n" |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 127 | create_namespace $NS $i |
| 128 | |
Mike Elliott | d17accd | 2017-08-14 16:21:40 -0400 | [diff] [blame] | 129 | printf "\nCreating registry secret **********\n" |
| 130 | create_registry_key $NS $i $ONAP_DOCKER_REGISTRY_KEY $ONAP_DOCKER_REGISTRY $DU $DP $ONAP_DOCKER_MAIL |
| 131 | |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 132 | if [[ "$INCL_SVC" == true ]]; then |
Mike Elliott | d17accd | 2017-08-14 16:21:40 -0400 | [diff] [blame] | 133 | printf "\nCreating service **********\n" |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame] | 134 | create_service $NS $i $start $end |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 135 | fi |
| 136 | |
| 137 | printf "\n" |
| 138 | done |
| 139 | |
Mike Elliott | d17accd | 2017-08-14 16:21:40 -0400 | [diff] [blame] | 140 | printf "\n\n********** Creating deployments for ${ONAP_APPS[*]} ********** \n" |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 141 | for i in ${ONAP_APPS[@]}; do |
Mike Elliott | d17accd | 2017-08-14 16:21:40 -0400 | [diff] [blame] | 142 | configure_app $NS $i |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 143 | /bin/bash $i.sh $NS $i 'create' |
| 144 | done |
| 145 | |
Munir Ahmad | 87b0109 | 2017-08-09 14:51:11 -0400 | [diff] [blame] | 146 | printf "\n**** Done ****\n" |