1 #!/usr/bin/env bash 2 # Copyright 2016 The TensorFlow Authors. All Rights Reserved. 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 # ============================================================================== 16 # 17 # Utility functions for dist_test scripts 18 19 20 # Print info and exit with code 1 21 die() { 22 echo $@ 23 exit 1 24 } 25 26 27 # Determine if all k8s pods in a namespace are all in the "Running" state 28 are_all_pods_running() { 29 # Usage: are_all_pods_running <KUBECTL_BIN> [namespace] 30 KUBECTL_BIN=$1 31 32 if [[ -z "$2" ]]; then 33 NS_FLAG="" 34 else 35 NS_FLAG="--namespace=$2" 36 fi 37 38 sleep 1 # Wait for the status to settle 39 NPODS=$("${KUBECTL_BIN}" "${NS_FLAG}" get pods | tail -n +2 | wc -l) 40 NRUNNING=$("${KUBECTL_BIN}" "${NS_FLAG}" get pods | tail -n +2 | \ 41 grep "Running" | wc -l) 42 NERR=$("${KUBECTL_BIN}" "${NS_FLAG}" get pods | tail -n +2 | \ 43 grep "Err" | wc -l) 44 45 if [[ ${NERR} != "0" ]]; then 46 # "2" signifies that error has occurred 47 echo "2" 48 elif [[ ${NPODS} == ${NRUNNING} ]]; then 49 # "1" signifies that all pods are in Running state 50 echo "1" 51 else 52 # "0" signifies that some pods have not entered Running state, but 53 # no error has occurred 54 echo "0" 55 fi 56 } 57