Merge "[DCAE] Update dcaegen2 cloudify manager image"
[oom.git] / kubernetes / dcaegen2 / components / dcae-redis / resources / redis / scripts / redis-cluster-config.sh
1 #!/bin/bash
2 # ================================================================================
3 # Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
4 # Modifications Copyright © 2018 Amdocs, Bell Canada
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 #
10 #     http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 # ============LICENSE_END=========================================================
18
19 (if [[ "$HOSTNAME" == *{{.Chart.Name}}-0 ]]; then
20   echo "delay by 10 seconds for redis server starting"
21   sleep 10
22
23   NODES=""
24   echo "====> wait for all {{.Values.replicaCount}} redis pods up"
25   while [ "$(echo $NODES | wc -w)" -lt {{.Values.replicaCount}} ]
26   do
27     echo "======> $(echo $NODES |wc -w) / {{.Values.replicaCount}} pods up"
28     sleep 5
29     RESP=$(wget -vO- --ca-certificate /var/run/secrets/kubernetes.io/serviceaccount/ca.crt  --header "Authorization: Bearer $(</var/run/secrets/kubernetes.io/serviceaccount/token)" https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT_443_TCP_PORT/api/v1/namespaces/{{.Release.Namespace}}/pods?labelSelector=app={{.Chart.Name}})
30
31     IPS=$(echo $RESP | jq -r '.items[].status.podIP')
32     IPS2=$(echo $IPS | sed -e 's/[a-zA-Z]*//g')
33     echo "======> IPs: ["$IPS2"]"
34     NODES=""
35     for I in $IPS2; do NODES="$NODES $I:{{.Values.service.externalPort}}"; done
36     echo "======> nodes: ["$NODES"]"
37   done
38   echo "====> all {{.Values.replicaCount}} redis cluster pods are up. wait 10 seconds before the next step"; echo
39   sleep 10
40
41   echo "====> Configure the cluster"
42
43   # $NODES w/o quotes
44   echo "======> nodes: [$(echo $NODES |paste -s)]"
45   redis-trib create --replicas 1 $(echo $NODES |paste -s)
46 fi ) &
47
48 redis-server /conf/redis.conf
49