Skip to content

Commit

Permalink
Cross compatible linux/mac (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
vcanaa authored Jun 28, 2018
1 parent 4f7b4e3 commit a2980f3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 14 deletions.
19 changes: 14 additions & 5 deletions scripts/driver/driver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ 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)"
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
Expand Down Expand Up @@ -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
44 changes: 35 additions & 9 deletions scripts/driver/wait_for_deletion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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

0 comments on commit a2980f3

Please sign in to comment.