#! /bin/sh

namespace="ci"

pods=$(kubectl get pods -n ${namespace} | egrep -i 'Terminated|Evicted|Error|NodeShutdown' | awk '{print $1 }')

for i in ${pods[@]}; do
	kubectl delete pod --force=true --wait=false --grace-period=0 --namespace ${namespace} $i
done

replicasets=$(kubectl get replicaset -n ${namespace} -o json)

for i in `echo $replicasets | jq '.items[] | if .spec.replicas == 0 then .metadata.name else "" end' | tr -d '"'`; do
	kubectl delete replicaset --force=true --wait=false --grace-period=0 --namespace ${namespace} $i
done
