Commit ff3ff1b1 authored by João Cunha's avatar João Cunha
Browse files

fix: allow --minify to fail w/o current-context

`kubectl config view --minify` needs a current-context
so it can show the information minified. Minify basically means to
remove all data that is not relevant to the current-context.

Since we call `kubectl config view --minify` in the root scope of the
file, every parent process that uses this file to call one of its
functions will endup reexecuting this piece of code. So by allowing
minify to fail when the context is not setup, we allow the user to call
use_kube_context before calling other scripts, which would avoid
breaking the execution.
parent 191aac4e
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -34,6 +34,24 @@
          echo "Failed as expected and exited with $?"
        }

test-use-kube-context:
  <<: *test-job
  variables:
    KUBE_CONTEXT: default
  script:
    # This test that any function will be properly
    # loaded. Even when calling `kubectl config --minify`
    # without a current context pre-setup
    - kubectl config unset current-context
    - kubectl config get-contexts
    - auto-deploy use_kube_context
    - context=$(kubectl config current-context)
    - |
      if [[ "$context" != "default" ]]; then
        echo "Failed to assign context"
        exit 1
      fi

test-dependencies:
  <<: *test-job
  variables:
+1 −1
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ export ASSETS_CHART_DIR="${ASSETS_DIR}/auto-deploy-app"
export ROLLOUT_RESOURCE_TYPE="${ROLLOUT_RESOURCE_TYPE:-deployment}"

if [[ -z "$KUBE_NAMESPACE" ]]; then
  context_namespace=$(kubectl config view --minify -o jsonpath='{..namespace}')
  context_namespace=$(kubectl config view --minify -o jsonpath='{..namespace}' || true)
  if [[ -n "$context_namespace" ]]; then
    export KUBE_NAMESPACE="$context_namespace"
  else