#!/bin/bash

REAL_PATH=$(python -c "import os,sys;print os.path.realpath('$0')")
cd "$(dirname "$REAL_PATH")/.."

UUID_REGEX="[a-f0-9]{8}(-[a-f0-9]{4}){3}-[a-f0-9]{12}"

pods=$(kubectl get pods -o template -t '{{range .items}}{{.id}} {{end}}')
for pod in $pods; do
    if [[ $pod =~ $UUID_REGEX ]]; then
	# Stopping a k8s replicationController doesn't delete the associated
	# pods, which names are UUIDs.
	# Assuming all pods named by UUID are leftover replication pods.
	kubectl delete pod $pod
    else
	kubectl delete -f "k8s/pod/${pod}-pod.yaml" 2>/dev/null
    fi
done
