Skip to content

Add support for Node Tolerations overwrite

What does this MR do?

Add support for overwriting Node Tolerations.

  • The environment variable KUBERNETES_NODE_TOLERATIONS_OVERWRITE_ALLOWED can be added to the gitlab-runner's K8s Deployment PodSpec. Its value is a regular expression used to validate the values of the CI Job variables whose names start with KUBERNETES_NODE_TOLERATIONS_. But typically one would add node_tolerations_overwrite_allowed in the config.toml or Helm values.yaml in the [runners.kubernetes] table.
  • One or more CI Job variables with names starting with KUBERNETES_NODE_TOLERATIONS_ can be specified describing pod tolerations to be applied to the associated CI Job pod. The syntax of the values for such CI Job variables is key[=value]:effect which follows the syntax used for adding a taint to a node using kubectl taint. This syntax is different from that used when specifying tolerations in the [runners.kubernetes.node_tolerations] configuration table which is a collection of key/value pairs in the form "key[=value]" = "effect".

Note: This MR is slightly different and completes the work effort done in MR !3915 (closed)

Why was this MR needed?

Thanks to MR !3221 (merged), we have the ability to run a CI Job on a specific class of worker node in a K8s cluster by being able to overwrite the CI Job pod's nodeSelector. However, if such nodes are tainted, the CI Job pod must also "tolerate" such taints in order to be deployed to such a node.

This MR allows us to specify pod tolerations in CI Job variables to be applied to the associated CI Job pod.

What's the best way to test this MR?

Unit tests were updated

  • added test case "support setting kubernetes pod taint tolerations via job variables" in TestSetupBuildPod in executors/kubernetes/kubernetes_test.go
  • updated test cases in TestOverwrites in executors/kubernetes/overwrites_test.go
    • test case "All ovewrites allowed"
    • test case "No overwrites allowed"

What are the relevant issue numbers?

I was thinking I might have to create a new Issue, but #28130 (closed) basically covers the feature set implemented in this MR. #28130 (closed) does use "environment variables" in the issue title but demonstrates use of CI variables in the issue description.

Edited by Marc Ostrow

Merge request reports