Skip to content
Snippets Groups Projects
create_pvc.sh 783 B
Newer Older
#!/usr/bin/env bash

if [[ $# -eq 2 ]]; then
    ns=$1
    pvc=$2
David Hoese's avatar
David Hoese committed
    EXTRA_ARGS="--namespace $ns"
elif [[ $# -eq 3 ]]; then
    ns=$1
    pvc=$2
    kubeconfig=$3
David Hoese's avatar
David Hoese committed
    EXTRA_ARGS="--namespace $ns --kubeconfig $kubeconfig"
else
    echo "Usage: ./create_pvc.sh <kubernetes namespace> <PVC YAML definition> <kubernetes config file>"
    exit 1
fi


# If another project started this build then we know the provided definition
# didn't change. Let's make sure it exists on the cluster and if so, don't
# try to recreate it.
if [[ $CI_PIPELINE_SOURCE == "pipeline" ]]; then
David Hoese's avatar
David Hoese committed
    pvc_exists=$(kubectl $EXTRA_ARGS get pvc $pvc -o jsonpath="{.metadata.name}" || echo "")
    if [[ "$pvc_exists" != "" ]]; then
        # it exists
        exit 0
    fi
fi

kubectl $EXTRA_ARGS replace -f $pvc