Gitlab agent not selected by default after environment deployment

Problem

When using the Kubernetes GitLab agent in a project to have it deployed as a review environment, the resulting deployment isn't automatically linked to any KAS agent, thus leaving the tab “Kubernetes dashboard” empty. Users have to manually edit the environment and select an agent to establish the link.

Ideally, users would like to avoid this step and have a default KAS agent automatically assigned, so that the dashboard is filled with the correct items, and readily usable after deployment. 

Steps to reproduce

  • Deploy an environment to Kubernetes using CI
  • Go to the environments page
  • The Kubernetes dashboard says “No Kubernetes clusters configured”
  • It's then necessary to click on “Edit environment” and select the GitLab agent, then select the namespace.

Configuration


An example code for the CI job is as follows:

deploy:review-app:
  stage: deploy
  interruptible: true
  image: ...
  variables:
    DASHBOARD_URL: https://dashboard-$CI_MERGE_REQUEST_IID.review-apps.mycompany.tech
    HELM_NAMESPACE: gimreviewapp-$CI_MERGE_REQUEST_IID
  rules:
    - if: $CI_MERGE_REQUEST_LABELS !~ /deploy_review_app_gitlab/
      when: never
  script:
    - helm upgrade --install gim-$CI_MERGE_REQUEST_IID $CI_PROJECT_DIR/review_app/chart --create-namespace --wait --timeout=20m
  environment:
    name: review-app/$CI_COMMIT_REF_NAME
    url: $DASHBOARD_URL
    on_stop: deploy:stop_review
    kubernetes:
      namespace: $HELM_NAMESPACE

 

Edited by Daniel Diniz