Add default labels/annotations to kubernetes executors

Description

Pod Labels/Annotations can make debugging Gitlab Runners much easier. For example, I need to optimize resource utilization of pods. In order to see the utilization of a certain job, I need to be able to group dashboards of gitlab runners CPU utilization by:

  • job name
  • project path
  • stage name

Proposal

Gitlab Runner can add some default labels/annotations, which are commonly requested by the community. Here is a quick explanation of the difference between labels and annotations.

Labels

  • Key Syntax: 63 characters or less, beginning and ending with an alphanumeric character ([a-z0-9A-Z]) with dashes (-), underscores (_), dots (.), and alphanumerics between
  • Value Syntax: same as key
  • used to group metrics
  • categorizing jobs

Suggested Labels:

gitlab.com/job_name = "${CI_JOB_NAME_SLUG}" # CI_JOB_NAME_SLUG is a new variable
gitlab.com/job_image = "${CI_JOB_IMAGE_SLUG}" # CI_JOB_IMAGE_SLUG is a new variable
gitlab.com/pipeline_id = "${CI_PIPELINE_ID}"
gitlab.com/pipeline_iid = "${CI_PIPELINE_IID}"
gitlab.com/project_path = "${CI_PROJECT_PATH_SLUG}"
gitlab.com/project_name = "${CI_PROJECT_NAME}"
gitlab.com/branch_name = "${CI_COMMIT_BRANCH}"
gitlab.com/environment_name = "${CI_ENVIRONMENT_SLUG}"
gitlab.com/environment_tier = "${CI_ENVIRONMENT_TIER}"

Annotations

  • Key Syntax: 63 characters or less, beginning and ending with an alphanumeric character ([a-z0-9A-Z]) with dashes (-), underscores (_), dots (.), and alphanumerics between
  • Value Syntax: no syntax
  • used for descriptive metadata
  • unstructured

Suggested Annotations:

gitlab.com/job_id = "${CI_JOB_ID}"
gitlab.com/job_name = "${CI_JOB_NAME}"
gitlab.com/job_url = "${CI_JOB_NAME}"
gitlab.com/job_image = "${CI_JOB_IMAGE}"
gitlab.com/job_stage = "${CI_JOB_STAGE}"
gitlab.com/pipeline_url = "${CI_PIPELINE_URL}"
gitlab.com/environment_name = "${CI_ENVIRONMENT_NAME}"
gitlab.com/project_path = "${CI_PROJECT_PATH}"
gitlab.com/project_url = "${CI_PROJECT_URL}"

Links to related issues and merge requests / references

Edited by Jason D'Amour