#helm2 check and convert, if fail exit. 
if /usr/local/bin/helm tiller run -- helm get manifest "$HELM_RELEASE_NAME" &> /dev/null; then
	echo "HELM2 release: $HELM_RELEASE_NAME found. I will convert it to HELM3 ..."
	if ! /usr/local/bin/helm3 2to3 convert --delete-v2-releases --tiller-out-cluster --release-storage "$TO3_RELEASE_STORAGE" "$HELM_RELEASE_NAME" &> /dev/null; then
		echo "Conversion of HELM2 release: $HELM_RELEASE_NAME to HELM3 version: $HELM_RELEASE_NAME failed." >&2
		exit 1
	fi
fi

set -x 

#helm3 update or new install
if ! /usr/local/bin/helm3 secrets upgrade --install "${HELM_PARAMS[@]}" --timeout "$HELM_TIMEOUT" --namespace "$HELM_RELEASE_NAMESPACE" "$HELM_RELEASE_NAME" "$HELM_CHART_PATH" &> /dev/null; then
	echo "Something went wrong, and I was unable to update HELM3 release: $HELM_RELEASE_NAME Exiting." >&2
	exit 1
fi