Teach runner how to set pod-level resources for build pods

What does this MR do?

This MR allows the k8s runner to specify pod-level resources for build pods.

  • Add entries to configure build pod cpu/memory requests and limits for the Kubernetes runner.
  • Use these entries values to generate build pod resources at the pod level.

Why was this MR needed?

Since k8s v1.32, it's possible to set resource requests and limits at the Pod level, creating a shared pool that all containers in the Pod can dynamically use. This reduces the operational complexity of managing resource allocations across containers.

What's the best way to test this MR?

Run the TestKubernetesBuildPodResources integration test on a k8s v1.34 cluster:

  1. Create the test namespace: kubectl create namespace k8s-runner-integration-tests
  2. Run the integration test: go test -count=1 -tags=integration,kubernetes -run TestKubernetesBuildPodResources -v gitlab.com/gitlab-org/gitlab-runner/executors/kubernetes

Alternatively you can deploy the new runner in a k8s v1.34 cluster and test it manually:

  1. Define pod_cpu_request and/or pod_cpu_limit and/or pod_memory_request and/or pod_memory_limitvalues in runner toml config.
  2. Deploy or update the new runner on a v1.34 k8s cluster (or a v1.32+ k8s with PodLevelResources feature gate enabled).
  3. Run pipelines on the previous runner.
  4. Use kubectl get pods -n <runner-namespace> <runner-build-pod-name> -o jsonpath-as-json='{.spec.resources}' when the pipeline is running (you must have access to the runner cluster)
  5. You should see something like that (with resources matching what defined in step 1)
[
    {
        "limits": {
            "cpu": "4",
            "memory": "8Gi"
        },
        "requests": {
            "cpu": "1",
            "memory": "1Gi"
        }
    }
]

What are the relevant issue numbers?

close #39085 (closed)

Edited by Romuald Atchadé

Merge request reports

Loading
Loading