From 2faf7f6275d51b60a8fb5010ec8ac16ec5fc619a Mon Sep 17 00:00:00 2001
From: David Hoese <david.hoese@ssec.wisc.edu>
Date: Fri, 24 Jul 2020 10:05:04 -0500
Subject: [PATCH] Fix elif in create_pvc.sh

---
 .gitlab-ci.yml        | 2 +-
 helpers/create_pvc.sh | 9 ++++-----
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 9b768cf..78ce9bb 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -68,7 +68,7 @@ create geotiff storage:
     # copy secret kubeconfig to the mounted (pwd) directory
     - cp $kubekorner_k3s_config .
     - kubeconfig=$(basename $kubekorner_k3s_config)
-    - ./helpers/create_pvc.sh $ns production/geotiff-pvc.yaml $kubeconfig
+    - ./helpers/create_pvc.sh "$ns" "production/geotiff-pvc.yaml" "$kubeconfig"
   rules:
     - changes:
         - production/geotiff-pvc.yaml
diff --git a/helpers/create_pvc.sh b/helpers/create_pvc.sh
index 9cb3868..1097ec7 100755
--- a/helpers/create_pvc.sh
+++ b/helpers/create_pvc.sh
@@ -3,12 +3,12 @@
 if [[ $# -eq 2 ]]; then
     ns=$1
     pvc=$2
-    EXTRA_ARGS=""
-else if [[ $# -eq 3 ]]; then
+    EXTRA_ARGS="--namespace $ns"
+elif [[ $# -eq 3 ]]; then
     ns=$1
     pvc=$2
     kubeconfig=$3
-    EXTRA_ARGS="--kubeconfig $kubeconfig"
+    EXTRA_ARGS="--namespace $ns --kubeconfig $kubeconfig"
 else
     echo "Usage: ./create_pvc.sh <kubernetes namespace> <PVC YAML definition> <kubernetes config file>"
     exit 1
@@ -19,7 +19,7 @@ fi
 # 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
-    pvc_exists=$(kubectl $EXTRA_ARGS get pvc --namespace $ns $pvc -o jsonpath="{.metadata.name}" || echo "")
+    pvc_exists=$(kubectl $EXTRA_ARGS get pvc $pvc -o jsonpath="{.metadata.name}" || echo "")
     if [[ "$pvc_exists" != "" ]]; then
         # it exists
         exit 0
@@ -27,4 +27,3 @@ if [[ $CI_PIPELINE_SOURCE == "pipeline" ]]; then
 fi
 
 kubectl $EXTRA_ARGS apply -f $pvc
-
-- 
GitLab