

function lib::require_cluster_id() {
    local cur_context
    cur_context=$(kubectl config current-context)
    local context_prefix="dedicated."
    local cluster_id=""
    if [[ ${cur_context} == ${context_prefix}* ]]; then
        cluster_id="${cur_context#${context_prefix}}"
    else
        echo "Current context is not dedicated cluster, please switch to context of dedicated cluster first."
        exit 1
    fi
    echo "${cluster_id}"
}

function lib::wait_pod_ready() {
    local namespace="${1}"
    local name="${2}"

    echo "Waiting pod ${namespace}/${name} to be ready..."
    kubectl wait --timeout=60s --for=condition=Ready -n "${namespace}" pod/${name} > /dev/null
}