+# Function to create a configmap in kubernetes
+# args: <configmap-name> <namespace> <labelname> <labelid> <path-to-data-file> <path-to-output-yaml>
+# (Not for test scripts)
+__kube_create_configmapXXXXXXXXXXXXX() {
+ echo -ne " Creating configmap $1 "$SAMELINE
+ #envsubst < $5 > $5"_tmp"
+ #cp $5"_tmp" $5 #Need to copy back to orig file name since create configmap neeed the original file name
+ kubectl create configmap $1 -n $2 --from-file=$5 --dry-run=client -o yaml > $6
+ if [ $? -ne 0 ]; then
+ echo -e " Creating configmap $1 $RED Failed $ERED"
+ ((RES_CONF_FAIL++))
+ return 1
+ fi
+
+ kubectl apply -f $6 1> /dev/null 2> ./tmp/kubeerr
+ if [ $? -ne 0 ]; then
+ echo -e " Creating configmap $1 $RED Apply failed $ERED"
+ echo " Message: $(<./tmp/kubeerr)"
+ ((RES_CONF_FAIL++))
+ return 1
+ fi
+ kubectl label configmap $1 -n $2 $3"="$4 --overwrite 1> /dev/null 2> ./tmp/kubeerr
+ if [ $? -ne 0 ]; then
+ echo -e " Creating configmap $1 $RED Labeling failed $ERED"
+ echo " Message: $(<./tmp/kubeerr)"
+ ((RES_CONF_FAIL++))
+ return 1
+ fi
+ # Log the resulting map
+ kubectl get configmap $1 -n $2 -o yaml > $6
+
+ echo -e " Creating configmap $1 $GREEN OK $EGREEN"
+ return 0
+}
+
+# This function runs a kubectl cmd where a single output value is expected, for example get ip with jsonpath filter.
+# The function retries up to the timeout given in the cmd flag '--cluster-timeout'
+# args: <full kubectl cmd with parameters>
+# (Not for test scripts)
+__kube_cmd_with_timeout() {
+ TS_TMP=$(($SECONDS+$CLUSTER_TIME_OUT))
+
+ while true; do
+ kube_cmd_result=$($@)
+ if [ $? -ne 0 ]; then
+ kube_cmd_result=""
+ fi
+ if [ $SECONDS -ge $TS_TMP ] || [ ! -z "$kube_cmd_result" ] ; then
+ echo $kube_cmd_result
+ return 0
+ fi
+ sleep 1
+ done
+}
+
+# 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() {
+
+ #using env vars setup in pvccleaner_api_functions.sh
+
+ export PVC_CLEANER_NAMESPACE=$2
+ export PVC_CLEANER_CLAIMNAME=$3
+ export PVC_CLEANER_RM_PATH=$4
+ input_yaml=$SIM_GROUP"/"$PVC_CLEANER_COMPOSE_DIR"/"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_APP_NAME $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
+}
+