Skip to content
GitLab
Next
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • GitLab GitLab
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 44,761
    • Issues 44,761
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
    • Requirements
  • Merge requests 1,332
    • Merge requests 1,332
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Metrics
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • GitLab.orgGitLab.org
  • GitLabGitLab
  • Issues
  • #324275
Closed
Open
Issue created Mar 12, 2021 by Mikhail Mazurskiy@ash2kDeveloper

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
Edited Jul 31, 2021 by Viktor Nagy (GitLab)
Assignee
Assign to
Time tracking