util.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/bash
  2. # Copyright 2015 The Kubernetes Authors.
  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. # Wait for background jobs to finish. Return with
  16. # an error status if any of the jobs failed.
  17. kube::util::wait-for-jobs() {
  18. local fail=0
  19. local job
  20. for job in $(jobs -p); do
  21. wait "${job}" || fail=$((fail + 1))
  22. done
  23. return ${fail}
  24. }
  25. # kube::util::join <delim> <list...>
  26. # Concatenates the list elements with the delimiter passed as first parameter
  27. #
  28. # Ex: kube::util::join , a b c
  29. # -> a,b,c
  30. function kube::util::join {
  31. local IFS="$1"
  32. shift
  33. echo "$*"
  34. }
  35. # Some useful colors.
  36. if [[ -z "${color_start-}" ]]; then
  37. declare -r color_start="\033["
  38. declare -r color_red="${color_start}0;31m"
  39. declare -r color_yellow="${color_start}0;33m"
  40. declare -r color_green="${color_start}0;32m"
  41. declare -r color_norm="${color_start}0m"
  42. fi