Skip to content

Add support for resources requests and limits #100

Closed

Description

@AlexisColes

The actions runner controller allows me to run a bunch of github agents waiting for container jobs in k8.
As these agents don't really do anything it would be good if I could keep a whole bunch of these agents running ready to pick up jobs as and when required with minimal resource requests.

resources:
        requests:
          cpu: 5m
          memory: 150Mi

I would then like the container jobs to define the amount of resources they want for each container and for this information to be passed through to the container spec.

jobs:
  container-test-job:
    runs-on: my-container-waiter
    container:
      image: node:14.16
      resources:
         requests:
           cpu: 500m
           memory: 2Gi
    services:
      postgres:
        image: postgres
         resources:
           requests:
             cpu: 500m
             memory: 2Gi

This would be very useful as we would not have to keep warm compute running for all the different permutations of required resources for out jobs and could just keep an amount of warm low priority compute to be share by all the different jobs.

Unfortunately there is no resources property for either a container or a service but maybe we can supply this information via the env property, something like.

jobs:
  container-test-job:
    runs-on: my-container-waiter
    container:
      image: node:14.16
      env:
         k8_resource_request_cpu:  500m
         k8_resource_request_memory: 2Gi
    services:
      postgres:
        image: postgres
        env:
           k8_resource_request_cpu:  500m
           k8_resource_request_memory: 2Gi

Activity

  1. changed the title [-]Adding support for resources requests and limits[/-] [+]Add support for resources requests and limits[/+] on Aug 16, 2023
  2. nikola-jokic commented on Aug 16, 2023

    @nikola-jokic
    Collaborator

    Hey @AlexisColes,

    Thank you for submitting this issue so clearly! There is an ongoing work right now to allow merges and customization of container specs. But based on your description, I can see that it can't fit all cases well, especially for different workflows requiring different sets of limits and requests based on containers it needs to spin up.

    Right now, I would prefer the env approach. It would eliminate changes in the workflow yaml file, but can carry a special meaning to the hook. I will bring this up to the team, but it seems like a great suggestion to me

  3. self-assigned this
    on Aug 16, 2023
  4. added
    enhancement
    on Aug 16, 2023
  5. nikola-jokic commented on Oct 2, 2023

    @nikola-jokic
    Collaborator

    Hey, closing this issue since it has been fixed with 0.4.0 release allowing definition overrides ☺️

  6. jmccarty3 commented on Apr 12, 2024

    @jmccarty3

    @nikola-jokic I'm not sure how the overrides that were introduced in 0.4.0 (and refined in later versions) fixes this specific issue. The template overrides that can be provided for containers are great for static mutations like imagePullSecrets, sidecars, volumets, etc.

    The overrides however do not allow for dynamic resource setting as originally proposed in the issue. Static resources could be added with the $job entry but that would only allow a user to provide every job container with the same resource requests/limits. If pulling information from the container env variables is not ideal, it would be a nice middle ground to have the job resource request/limits set from reading the --cpus and --memory options from the jobs.*.container.options.

    I think this issue should be reopend until proper support is in place or is stated as not going to be supported.

  7. velkovb commented on Dec 17, 2024

    @velkovb

    One more vote for re-opening the issue. We are using the template for jobs but if the pod is too big and there is no space on the runner node we get errors. This shouldn't work like that. The runner pod should be minimal and just scheduling pods with the desired resources.

  8. jasonwbarnett commented on Jan 26, 2025

    @jasonwbarnett

    Here is my rough plan to address this:

    1. Update the actions-runner-controller to add a new label here to the ephemeral runner pod, i.e.

             labels["ephemeral-runner-name"] = runner.ObjectMeta.Name
    2. Update the runner-container-hooks to dynamically add podAffinity using the label selector matching the ephemeral runner name

      With this change plus setting ACTIONS_RUNNER_USE_KUBE_SCHEDULER to true, this should guarantee the the pod is spun up on the same node as the ephemeral runner pod. Even if resources aren't immediately available it would continue to try to be scheduled.

    3. Lastly, I think I can modify runner-container-hooks to pull out a nested YAML structure from jobs.<job_id>.container.options and apply it to the -workflow pod spec allowing for dynamic cpu and memory requests.

      name: CI
      on:
        push:
          branches: [ main ]
      jobs:
        container-test-job:
          runs-on: ubuntu-latest
          container:
            image: node:18
            options: |
              resources:
                requests:
                  memory: "64Mi"
                  cpu: "250m"
                limits:
                  memory: "128Mi"
                  cpu: "500m"
          steps:
            - name: Check for dockerenv file
              run: (ls /.dockerenv && echo Found dockerenv) || (echo No dockerenv)

    Ideally the jobs.<job_id>.container spec would be extended with a new key, but without that I could hack the existing schema and make it all work.

    Any others thoughts?

  9. velkovb commented on Jan 26, 2025

    @velkovb

    That still seems like a workaround and there are edge cases where it might never work, i.e. the workflow pod being bigger than the node the runner is on.

    Is there any possibility to work towards a different method than the PVC to share information, as those limitations stem from it?

  10. AlexisColes commented on Jan 26, 2025

    @AlexisColes
    Author

    There should definitely be some work around supporting runners working on different nodes as well. The limitation for them running on the same node is far from ideal and always going to cause some issues.

    But either way the work for defining the resources in the workflow and getting that applied to the workflow container would be a great enhancement. Using the options seems a sensible way to go. 👍

    What do you think @nikola-jokic ?

  11. anlesk commented on Sep 4, 2025

    @anlesk

    Also bumping this up with the support for re-opening.
    As there is an ongoing attempt to get PVCless (#244), some of the concerns from above will not be a problem.

    However, letting the workflow pod specify the resources needed for a run would add a lot of flexibility and freedom for workflows design.
    So far, this can be achieved with either providing runners with pre-defined specs (populated via $job) or by overriding ACTIONS_RUNNER_CONTAINER_HOOK_TEMPLATE with the path to yaml file (For different templates, different files have to be present on the runner before hand, making it impossible to change it "on the fly").

    @nikola-jokic would that be possible to allow workflow pods to read resources and limits from the workflow file directly?

  12. tmilnthorp commented on Nov 5, 2026

    @tmilnthorp

    Adding to the reopen requests above — the 0.4.0 hook-template overrides are per runner set, so they can't size an individual job. GitLab's Kubernetes executor solves exactly this, and the same shape would fit the k8s hook here:

    • Job-level hints, read by the hook in prepare_job from the job container's env, e.g.
      container:
        image: …
        env:
          ACTIONS_POD_CPU_REQUEST: "2"
          ACTIONS_POD_MEMORY_REQUEST: 4Gi
          ACTIONS_POD_MEMORY_LIMIT: 6Gi
      (or parsed from container.options: --cpus/--memory, as in Added resource requirement based on --cpus and --memory,-m #1).
    • Admin ceilings in the hook template / runner-set env (like GitLab's *_OVERWRITE_MAX_ALLOWED), so a workflow can't request more than the cluster operator allows; absent hints = template default.
    • The job pod is then created with those requests/limits, so the scheduler queues it when the node is full instead of OOM-killing it, and runner pods can stay tiny (the original ask).

    Use case: a self-hosted ARC pool where builds need 4–6 GiB but most jobs need <1 GiB; per-set sizes force either over-reservation or one runner set per size.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementk8s

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions