auto-deploy fails without $KUBE_NAMESPACE set when using GitLab Agent
When using the GitLab Agent for Kubernetes, the added functionality from !227 (merged) in the auto-deploy
script used for AutoDevOps' Deploy.gitlab-ci.yml exits with an error at line 16, as no context is selected.
Because there is no context selected by default, the kubectl command attempting to retrieve namespace and set it as $context_namespace
will always fail, making $KUBE_NAMESPACE required.
The error message is not helpful either; it's not clear what command (kubectl
) failed.
Examples
With $KUBE_INGRESS_BASE_DOMAIN
set (and no other CI/CD variables): https://gitlab.com/jrreid/dast-demo/-/jobs/1876034488
$ auto-deploy check_kube_domain
error: current-context must exist in order to minify
With $KUBE_INGRESS_BASE_DOMAIN
and $KUBE_CONTEXT
set: https://gitlab.com/jrreid/dast-demo/-/jobs/1880038258
$ auto-deploy check_kube_domain
error: current-context must exist in order to minify
Workaround
Define $KUBE_NAMESPACE
as a CI/CD variable— then the if clause doesn't match (i.e. $KUBE_NAMESPACE is non-null) and the kubectl command can't fail.
Proposed Solution
Checking for namespace only after $kube_context is set could be a potential fix.