Skip to content

Set all existing variables into the build container

Romuald Atchadé requested to merge k8s-retrieve-all-variables-for-container into main

What does this MR do?

Before this MR, when executing a job with the k8s executor, only the public or internal variables were directly set as env variables for the container. This defacto blocks any image with a custom entrypoint to make use of them. On the docker executor side, the behaviour is different as such distinction is not made.

With this MR, we make the k8s executor behaves as the docker one by setting all existing variables as container env variables

Why was this MR needed?

To allow custom entrypoint to make use of all variables at the start of the container

What's the best way to test this MR?

  1. Create a group (or use an existing one) and create the variable MY_GROUP_LEVEL_ENV with the value This is my group level environment variable (nor masked, nor protected)
  2. Create a project within this group and create the variable MY_PROJECT_LEVEL_ENV with the value This is my project level env variable (nor masked, nor protected)
  3. Use the following gitlab-ci.yml
gitlab-ci
stages:
  - test

variables:
  FF_KUBERNETES_HONOR_ENTRYPOINT: "true"

format:
  stage: test
  image: aaro301/alpine:custom-entrypoint
  script:
    - sleep 30

The image used has been created using the following dockerfile

dockerfile
FROM alpine:latest@sha256:1304f174557314a7ed9eddb4eab12fed12cb0cd9809e4c28f29af86979a3c870

COPY ./entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
entrypoint.sh
#!/bin/sh

echo "=================================="
echo "This is the custom entrypoint"
echo "$MY_GROUP_LEVEL_ENV";
echo "$MY_PROJECT_LEVEL_ENV";
echo "=================================="

exec "$@"
  1. Use the following config.toml
config.toml
concurrent = 1
check_interval = 1
log_level = "debug"

[session_server]
  session_timeout = 1800

[[runners]]
  url = "https://gitlab.com/"
  token = "__TOKEN__"
  executor = "kubernetes"
  [runners.kubernetes]
    terminationGracePeriodSeconds = 0
    [runners.kubernetes.affinity]
    [runners.kubernetes.volumes]
    [runners.kubernetes.dns_config]
  1. Run the job and display the build container logs using the command
kubectl logs -f <POD_NAME> build -n <NAMESPACE>
  1. The log will show the print of the Group Level and Project Level variables
==================================
This is the custom entrypoint
This is my group level environment variable
This is my project level env variable
==================================
$ sleep 30

What are the relevant issue numbers?

close https://gitlab.com/gitlab-com/ops-sub-department/section-ops-request-for-help/-/issues/27

Edited by Romuald Atchadé

Merge request reports