f4547525c9d81e1b8b52cfb70fcfda7582b0a0bc
[oom.git] / kubernetes / dcaegen2 / charts / 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 # ================================================================================
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
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 # ============LICENSE_END=========================================================
17
18 (if [[ "$HOSTNAME" == *{{.Chart.Name}}-0 ]]; then
19   echo "delay by 10 seconds for redis server starting"
20   sleep 10
21
22   NODES=""
23   echo "====> wait for all {{.Values.replicaCount}} redis pods up"
24   while [ "$(echo $NODES | wc -w)" -lt {{.Values.replicaCount}} ]
25   do
26     echo "======> $(echo $NODES |wc -w) / {{.Values.replicaCount}} pods up"
27     sleep 5
28     RESP=$(wget -vO- --ca-certificate /var/run/secrets/kubernetes.io/serviceaccount/ca.crt  --header "Authorization
29 : Bearer $(</var/run/secrets/kubernetes.io/serviceaccount/token)" https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT
30 _443_TCP_PORT/api/v1/namespaces/{{.Release.Namespace}}/pods?labelSelector=app={{.Chart.Name}})
31
32     IPS=$(echo $RESP | jq -r '.items[].status.podIP')
33     IPS2=$(echo $IPS | sed -e 's/[a-zA-Z]*//g')
34     echo "======> IPs: ["$IPS2"]"
35     NODES=""
36     for I in $IPS2; do NODES="$NODES $I:{{.Values.service.externalPort}}"; done
37     echo "======> nodes: ["$NODES"]"
38   done
39   echo "====> all {{.Values.replicaCount}} redis cluster pods are up. wait 10 seconds before the next step"; echo
40   sleep 10
41
42   echo "====> Configure the cluster"
43
44   # $NODES w/o quotes
45   echo "======> nodes: [$(echo $NODES |paste -s)]"
46   redis-trib create --replicas 1 $(echo $NODES |paste -s)
47 fi ) &
48
49 redis-server /conf/redis.conf
50