Skip to content

Support for env variables expansion for image name for kubernetes executor

What does this MR do?

This MR brings the expansion of the env variables for kubernetes executor in the log files for the image name

Why was this MR needed?

This MR was needed to bring more clarity in the log files when using the kubernetes executor

What's the best way to test this MR?

To test this MR, the following steps must be followed (steps for macos)

All variables exist

gitlab-ci.yml
variables:
  IMAGE_NAME: alpine
  IMAGE_VERSION: latest

start_evaluation:
  script:
    - echo Done
config.toml
concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "Local GitLab Runner for tests and debugging"
  url = "https://gitlab.com"
  token = "YOUR_TOKEN_HERE"
  executor = "kubernetes"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]
  [runners.kubernetes]
    host = "CLUSTER_ADDRESS"
    cert_file = "MINIKUBE_CERTIFICATE_CLIENT_FILE"
    key_file = "MINIKUBE_KEY_CLIENT_FILE"
    ca_file = "MINIKUBE_CERTIFICATE_AUTHORITY_FILE"
    bearer_token_overwrite_allowed = false
    image = "$IMAGE_NAME:$IMAGE_VERSION"
    namespace = "default"
    namespace_overwrite_allowed = "default"
    privileged = false
    service_account_overwrite_allowed = ""
    pod_annotations_overwrite_allowed = ""
    [runners.kubernetes.affinity]
    [runners.kubernetes.pod_security_context]
    [runners.kubernetes.volumes]
    [runners.kubernetes.dns_config]

Validation Prerequisites

  1. Docker Desktop installed on the machine. Click following link for the installation steps 👉🏿 Install Docker Desktop
  2. kubectl installed on the machine. Click following link for the installation steps 👉🏿 Install KubeCtl on MacOS
  3. minikube installed on the machine. Click following link for the installation steps 👉🏿 Install Minikube on MacOS

Validation Step

  1. Start the kubernetes cluster with the command minikube start
  2. Retrieve the cluster configuration with the command kubectl config view
  3. Replace the config.toml values as follow
    1. CLUSTER_ADDRESS replaced by clusters -> - cluster: -> server value
    2. MINIKUBE_CERTIFICATE_CLIENT_FILE replaced by users -> - user: -> client-certificate value
    3. MINIKUBE_KEY_CLIENT_FILE replaced by users -> - user: -> client-key value
    4. MINIKUBE_CERTIFICATE_AUTHORITY_FILE replaced by clusters -> - cluster: -> certificate-authority value
  4. Run gitlab-runner by using the config.toml
  5. Trigger a job task from the playground project

Expected result

The log file should contain alpine:latest instead of $IMAGE_NAME:$IMAGE_VERSION as displayed below
Logs

ScreenShots

Screen_Shot_2021-02-25_at_12.01.53_AM

At least one variable doesn't exist

gitlab-ci.yml
variables:
  IMAGE_NAME: alpine

start_evaluation:
  script:
    - echo Done
config.toml
concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "Local GitLab Runner for tests and debugging"
  url = "https://gitlab.com"
  token = "YOUR_TOKEN_HERE"
  executor = "kubernetes"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]
  [runners.kubernetes]
    host = "CLUSTER_ADDRESS"
    cert_file = "MINIKUBE_CERTIFICATE_CLIENT_FILE"
    key_file = "MINIKUBE_KEY_CLIENT_FILE"
    ca_file = "MINIKUBE_CERTIFICATE_AUTHORITY_FILE"
    bearer_token_overwrite_allowed = false
    image = "$IMAGE_NAME:$IMAGE_VERSION"
    namespace = "default"
    namespace_overwrite_allowed = "default"
    privileged = false
    service_account_overwrite_allowed = ""
    pod_annotations_overwrite_allowed = ""
    [runners.kubernetes.affinity]
    [runners.kubernetes.pod_security_context]
    [runners.kubernetes.volumes]
    [runners.kubernetes.dns_config]

Validation Prerequisites

As above

Validation Step

As above

Expected result

The log file should contain alpine:latest instead of $IMAGE_NAME:$IMAGE_VERSION as displayed below
Logs

ScreenShots

Screen_Shot_2021-03-08_at_10.31.02_AM

What are the relevant issue numbers?

closes: #25875 (closed)

Edited by Romuald Atchadé

Merge request reports