Skip to content

Resolve "CI/CD tunnel based deploy fails with: current-context must exist in order to minify"

What this MR does?

Proposal

This resolves the problem where any function call inside of the auto-deploy file would fail when $KUBE_NAMESPACE is not present. This is what is happening when we try to deploy with with Auto DevOps and the Agent. See the related issue for an example: #191 (closed)

This allows kubectl config view --minify -o jsonpath='{..namespace}' to fail with || true. This might surpass errors with the kubeconfig. But it might be an ok solution to set the KUBE_NAMESPACE to default, if we can't get the namespace from the context.

It also adds 2>/dev/null to the minify command to avoid printing to the console the error message when the current context is not present, which would be misleading since we're ignoring this error. We could also implement some ... | tee minify_error.log + grep minify_error.log logic to filter this specific type of error and exit 1 if we find any other message. I'll leave to the maintainer to decide here.

Related Issues

Relates #191 (closed)

Manual QA

Set up:

  • Create a simple application.
  • Install ingress an certmanager on your cluster.
  • Add an Agent to connect the cluster to your project.
  • Add your .gitlab-ci.yml including the Auto DevOps template.
  • Edit your .gitlab-ci.yml to override the .auto-deploy.image: to point to registry.gitlab.com/gitlab-org/cluster-integration/auto-deploy-image/191-ci-cd-tunnel-based-deploy-fails-with-current-context-must-e:latest@sha256:36b409906d7b36b9a7f737830ffde3f8d9f8017f110dd395aee013c4a2a19a4d
  • Also make sure you add the CI variable KUBE_CONTEXT: 'YOUR-AGENT-CONTEXT-HERE'. Accordingly to how to choose your Agent context name from the Agent docs.

Deploy pipeline succeeded

https://gitlab.com/Alexand/min-ruby-app/-/pipelines/439247557

Website accessible

Screen_Shot_2021-12-30_at_4.48.29_PM

Edited by João Alexandre Cunha

Merge request reports

Loading