wait.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env bash
  2. # Copyright 2018 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. set -o errexit
  16. set -o nounset
  17. set -o pipefail
  18. run_wait_tests() {
  19. set -o nounset
  20. set -o errexit
  21. kube::log::status "Testing kubectl wait"
  22. create_and_use_new_namespace
  23. ### Wait for deletion using --all flag
  24. # create test data
  25. kubectl create deployment test-1 --image=busybox
  26. kubectl create deployment test-2 --image=busybox
  27. # Post-Condition: deployments exists
  28. kube::test::get_object_assert "deployments" "{{range .items}}{{.metadata.name}},{{end}}" 'test-1,test-2,'
  29. # Delete all deployments async to kubectl wait
  30. ( sleep 2 && kubectl delete deployment --all ) &
  31. # Command: Wait for all deployments to be deleted
  32. output_message=$(kubectl wait deployment --for=delete --all)
  33. # Post-Condition: Wait was successful
  34. kube::test::if_has_string "${output_message}" 'test-1 condition met'
  35. kube::test::if_has_string "${output_message}" 'test-2 condition met'
  36. set +o nounset
  37. set +o errexit
  38. }