diff --git a/scripts/driver/driver.sh b/scripts/driver/driver.sh index 20babe4e..a2ac8269 100755 --- a/scripts/driver/driver.sh +++ b/scripts/driver/driver.sh @@ -43,7 +43,7 @@ done [[ -z "$wait_timeout" ]] && wait_timeout=600 # Getting the directory of the running script -DIR="$(realpath $(dirname $0))" +DIR="$(dirname $0)" echo $DIR namespace_key="$(docker run --entrypoint=/bin/extract_schema_key.py --rm "$deployer" --type NAMESPACE)" @@ -51,7 +51,7 @@ NAME="$(echo "$parameters" \ | docker run -i --entrypoint=/bin/print_config.py --rm "$deployer" \ --values_file=- --param '{"x-google-marketplace": {"type": "NAME"}}')" -export NAMESPACE="apptest-$(uuidgen)" +export NAMESPACE="apptest-$(cat /dev/urandom | xxd -l 4 -ps -c 4)" export NAME kubectl version @@ -134,15 +134,24 @@ $DIR/../stop.sh \ deletion_timeout=180 echo "INFO Wait for the applications to be deleted" -timeout --foreground $deletion_timeout "$DIR/wait_for_deletion.sh" "$NAMESPACE" applications \ +"$DIR/wait_for_deletion.sh" \ + --namespace="$NAMESPACE" \ + --kind=applications \ + --timeout="$deletion_timeout" \ || clean_and_exit "ERROR Some applications where not deleted" echo "INFO Wait for standard resources were deleted." -timeout --foreground $deletion_timeout "$DIR/wait_for_deletion.sh" "$NAMESPACE" all \ +"$DIR/wait_for_deletion.sh" \ + --namespace="$NAMESPACE" \ + --kind=all \ + --timeout="$deletion_timeout" \ || clean_and_exit "ERROR Some resources where not deleted" echo "INFO Wait for service accounts to be deleted." -timeout --foreground $deletion_timeout "$DIR/wait_for_deletion.sh" "$NAMESPACE" serviceaccounts,roles,rolebindings \ +"$DIR/wait_for_deletion.sh" \ + --namespace="$NAMESPACE" \ + --kind=serviceaccounts,roles,rolebindings \ + --timeout="$deletion_timeout" \ || clean_and_exit "ERROR Some service accounts or roles where not deleted" delete_namespace diff --git a/scripts/driver/wait_for_deletion.sh b/scripts/driver/wait_for_deletion.sh index ce7042e0..909eac1b 100755 --- a/scripts/driver/wait_for_deletion.sh +++ b/scripts/driver/wait_for_deletion.sh @@ -14,14 +14,34 @@ # See the License for the specific language governing permissions and # limitations under the License. -set -e -set -o pipefail +set -eo pipefail -namespace=$1 -kind=$2 -deleted=false +for i in "$@" +do +case $i in + --namespace=*) + namespace="${i#*=}" + shift + ;; + --kind=*) + kind="${i#*=}" + shift + ;; + --timeout=*) + timeout="${i#*=}" + shift + ;; + *) + echo "Unrecognized flag: $i" + exit 1 + ;; +esac +done + +start_time=$(date +%s) +poll_interval=4 -while [[ "$deleted" = "false" ]]; do +while true; do # Everything under the namespace needs to be removed after app/uninstall echo "INFO Checking if $kind were deleted" resources=$(kubectl get $kind \ @@ -32,15 +52,21 @@ while [[ "$deleted" = "false" ]]; do res_count=$(echo $resources | wc -w) if [[ "$res_count" -eq 0 ]]; then - deleted=true + break else # Ignore service account default if [[ "$resources" = "ServiceAccount/default" ]]; then - deleted=true + break else echo "INFO Remaining: $res_count" echo "INFO $resources" - sleep 4 + + elapsed_time=$(( $(date +%s) - $start_time )) + if [[ "$elapsed_time" -gt "$timeout" ]]; then + exit 1 + fi + + sleep "$poll_interval" fi fi done