Inject kubectl-compatible config file into the CI job
Release notes
Until now users of the Kubernetes Agent CI tunnel had to inject a corresponding kubeconfig
file into the CI manually. Creating this kubeconfig
required the editing of the CI pipeline definition, the knowledge of the Agent ID and the understanding of how a kubeconfig
is structured, and introduced boilerplate code into the CI pipeline definition. GitLab now ships with an automatically injected kubeconfig
file that contains all the available agent connections for the given project, and the user has to simply choose just the right kubecontext
to use.
The injected kubeconfig
contains contexts for every available agent in the form of group/agent-config-project/slug:agent-name
. Users can easily select the agent connection they want to use by providing just the context name following this pattern.
Proposal
The context name should use the format <config project path>:<agent name>
:
$ kubectl config set-context group/config/project:agent-name
$ kubectl config get-contexts | grep "group/config/project"
Going that route will also make it easier/more robust to select a default current-context
via future .gitlab-ci.yaml
syntactic sugar, see environment.kubernetes.context
below:
deploy:
stage: deploy
variables:
AGENT_CONFIG_PROJECT: group/config/project
parallel:
matrix:
- AGENT: us-west1
- AGENT: us-east1
- AGENT: us-central1
environment:
name: production
kubernetes:
context: $AGENT_CONFIG_PROJECT:$AGENT # easy to construct + maps 1:1 with context name
script:
- kubectl config current-context # -> "group/config/project:us-..."
- make deploy-app
Scope
- [ ] inject the kubecontext
Not in scope
- the CI extension of
environment.kubernetes.context