+# This function starts a pod that cleans a the contents of a path mounted as a pvc
+# After this action the pod should terminate
+# This should only be executed when the pod owning the pvc is not running
+# args: <appname> <namespace> <pvc-name> <path-to remove>
+# (Not for test scripts)
+__kube_clean_pvc() {
+
+ export PVC_CLEANER_NAMESPACE=$2
+ export PVC_CLEANER_CLAIMNAME=$3
+ export PVC_CLEANER_RM_PATH=$4
+ input_yaml=$SIM_GROUP"/pvc-cleaner/"pvc-cleaner.yaml
+ output_yaml=$PWD/tmp/$2-pvc-cleaner.yaml
+
+ envsubst < $input_yaml > $output_yaml
+
+ kubectl delete -f $output_yaml 1> /dev/null 2> /dev/null # Delete the previous terminated pod - if existing
+
+ __kube_create_instance pod pvc-cleaner $input_yaml $output_yaml
+ if [ $? -ne 0 ]; then
+ echo $YELLOW" Could not clean pvc for app: $1 - persistent storage not clean - tests may not work"
+ return 1
+ fi
+
+ term_ts=$(($SECONDS+30))
+ while [ $term_ts -gt $SECONDS ]; do
+ pod_status=$(kubectl get pod pvc-cleaner -n $PVC_CLEANER_NAMESPACE --no-headers -o custom-columns=":status.phase")
+ if [ "$pod_status" == "Succeeded" ]; then
+ return 0
+ fi
+ done
+ return 1
+}
+