align Rancher/k8s with 1.6.22 post RC1
[logging-analytics.git] / deploy / aws / oom_cluster_host_install.sh
1 #!/bin/bash
2 #############################################################################
3 #
4 # Copyright © 2018 Amdocs.
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #        http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17 #############################################################################
18 # v20181105
19 # Amazon AWS specific EFS/NFS share and rancher host join script for each cluster node
20 # https://wiki.onap.org/display/DW/Cloud+Native+Deployment
21 # source from https://jira.onap.org/browse/OOM-320
22 # Michael O'Brien
23 # LOG-806 upgrade for Rancher 1.6.22, kubernetes 1.11
24
25 usage() {
26 cat <<EOF
27 Usage: $0 [PARAMs]
28 example
29  master
30  sudo ./cluster.sh -n false -s cl.onap.info -e fs-00c0f00 -r us-east-2
31  clients
32  sudo ./cluster.sh -n true -s cl.onap.info -e fs-00c0f00 -r us-east-2 -t 23D4:15:qQ -c false -a host1.onap.info -v true
33  sudo ./oom_cluster_host_install.sh -n true -s cd.onap.cloud -e 1 -r us-east-2 -t token -c false -a 104.209.158.156 -v true
34 Prereq:
35   You must create an EFS (NFS wrapper) on AWS
36
37 -u                      : Display usage
38 -n [true|false]         : is node (non master)
39 -s [master server]      : target server (ip or FQDN only)
40 -e [AWS efs id]         : AWS Elastic File System ID prefix
41 -r [AWS region prefix]  : AWS Region prefix
42 -t [token]              : registration token
43 -h [agent ver]          : agent version (default 1.2.10 for 1.6.18
44 -c [true/false]         : use computed client address
45 -a [IP address]         : client address ip - no FQDN
46 -v [validate true/false]: optional
47 EOF
48 }
49
50 register_node() {
51     #constants
52     DOCKERDATA_NFS=dockerdata-nfs
53     DOCKER_VER=17.03
54     USERNAME=ubuntu
55     PORT=8880
56
57     if [[ "$IS_NODE" != false ]]; then
58         sudo curl https://releases.rancher.com/install-docker/$DOCKER_VER.sh | sh
59         sudo usermod -aG docker $USERNAME
60     fi
61     sudo apt-get install nfs-common -y
62     sudo mkdir /$DOCKERDATA_NFS
63     sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 $AWS_EFS.efs.$AWS_REGION.amazonaws.com:/ /$DOCKERDATA_NFS
64     if [[ "$IS_NODE" != false ]]; then
65         echo "Running agent docker..."
66         if [[ "$COMPUTEADDRESS" != false ]]; then
67             echo "sudo docker run --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v$AGENT_VER http://$MASTER:$PORT/v1/scripts/$TOKEN"
68             sudo docker run --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v$AGENT_VER http://$MASTER:$PORT/v1/scripts/$TOKEN
69         else
70             echo "sudo docker run -e CATTLE_AGENT_IP=\"$ADDRESS\" --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v$AGENT_VER http://$MASTER:$PORT/v1/scripts/$TOKEN"
71             sudo docker run -e CATTLE_AGENT_IP="$ADDRESS" --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v$AGENT_VER http://$MASTER:$PORT/v1/scripts/$TOKEN
72         fi
73     fi
74 }
75
76 IS_NODE=false
77 MASTER=
78 TOKEN=
79 AWS_REGION=
80 AWS_EFS=
81 AGENT_VER=1.2.11
82 COMPUTEADDRESS=true
83 ADDRESS=
84 VALIDATE=
85 while getopts ":u:n:s:e:r:t:h:c:a:v" PARAM; do
86   case $PARAM in
87     u)
88       usage
89       exit 1
90       ;;
91     n)
92       IS_NODE=${OPTARG}
93       ;;
94     s)
95       MASTER=${OPTARG}
96       ;;
97     e)
98       AWS_EFS=${OPTARG}
99       ;;
100     r)
101       AWS_REGION=${OPTARG}
102       ;;
103     t)
104       TOKEN=${OPTARG}
105       ;;
106     h)
107       AGENT_VER=${OPTARG}
108       ;;
109     c)
110       COMPUTEADDRESS=${OPTARG}
111       ;;
112     a)
113       ADDRESS=${OPTARG}
114       ;;
115     v)
116       VALIDATE=${OPTARG}
117       ;;
118     ?)
119       usage
120       exit
121       ;;
122   esac
123 done
124
125 if [ -z $MASTER ]; then
126   usage
127   exit 1
128 fi
129
130 register_node  $IS_NODE $MASTER $AWS_EFS $AWS_REGION $TOKEN $AGENT_VER $COMPUTEADDRESS $ADDRESS $VALIDATE
131 echo "check dockerdata-nfs"
132 sudo ls /dockerdata-nfs
133 echo "if you get http://$MASTER:8880/v1 is not accessible (The requested URL returned error: 404 Not Found) - check your token"
134 printf "**** Success: Done ****\n"