#!/usr/bin/env bash

debug() {
    >&2 echo "DEBUG: $@"
}

error() {
    >&2 echo "ERROR: $@"
    exit 1
}

check_and_uninstall() {
    release_name="$1"
    if [[ -z "${release_name}" ]]; then
        # the chart was never created
        debug "Release doesn't exist"
        return
    fi
    debug "Uninstalling ${release_name}"
    helm uninstall ${release_name} | error "Could not uninstall chart $release_name"
}

source ./ci_tests/get_release_names.sh
check_and_uninstall "${GRB_RELEASE_NAME}"