blob: f6ea65769d2c2faa460cb4623d7c471bf900492d [file] [log] [blame]
Andy Bavierac5a1922018-07-09 17:19:19 -07001#!/bin/bash
2
3# Copyright 2017 The Openstack-Helm Authors.
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may
6# not use this file except in compliance with the License. You may obtain
7# 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, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations
15# under the License.
16set -e
17
18# From Kolla-Kubernetes, orginal authors Kevin Fox & Serguei Bezverkhi
19# Default wait timeout is 600 seconds
20end=$(date +%s)
21if ! [ -z $2 ]; then
22 end=$((end + $2))
23else
24 end=$((end + 900))
25fi
26while true; do
27 kubectl get pods --namespace=$1 -o json | jq -r \
28 '.items[].status.phase' | grep Pending > /dev/null && \
29 PENDING=True || PENDING=False
30 query='.items[]|select(.status.phase=="Running")'
31 query="$query|.status.containerStatuses[].ready"
32 kubectl get pods --namespace=$1 -o json | jq -r "$query" | \
33 grep false > /dev/null && READY="False" || READY="True"
34 kubectl get jobs -o json --namespace=$1 | jq -r \
35 '.items[] | .spec.completions == .status.succeeded' | \
36 grep false > /dev/null && JOBR="False" || JOBR="True"
37 [ $PENDING == "False" -a $READY == "True" -a $JOBR == "True" ] && \
38 break || true
39 sleep 5
40 now=$(date +%s)
41 [ $now -gt $end ] && echo containers failed to start. && \
42 kubectl get pods --namespace $1 -o wide && exit -1
43done