Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting resources for kubernetes on a per-step basis #1767

Merged
merged 13 commits into from
Jun 3, 2023

Conversation

smuth4
Copy link
Contributor

@smuth4 smuth4 commented May 19, 2023

This add a simple implementation of requests/limits for individual steps. There is no validation of what the resource actually is beyond checking that it can successfully be converted to a Quantity, so it can be used for things other than just memory/CPU.

close #1809

@woodpecker-bot
Copy link
Collaborator

woodpecker-bot commented May 19, 2023

Deployment of preview was successful: https://woodpecker-ci-woodpecker-pr-1767.surge.sh

pipeline/backend/types/step.go Outdated Show resolved Hide resolved
docs/docs/30-administration/80-kubernetes.md Outdated Show resolved Hide resolved
docs/docs/30-administration/15-agent-config.md Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented May 19, 2023

Codecov Report

Patch coverage has no change and project coverage change: -0.08 ⚠️

Comparison is base (1417763) 39.01% compared to head (83d3354) 38.94%.

❗ Current head 83d3354 differs from pull request most recent head 926205d. Consider uploading reports for the commit 926205d to get more accurate results

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1767      +/-   ##
==========================================
- Coverage   39.01%   38.94%   -0.08%     
==========================================
  Files         166      166              
  Lines       10343    10349       +6     
==========================================
- Hits         4035     4030       -5     
- Misses       6045     6055      +10     
- Partials      263      264       +1     
Impacted Files Coverage Δ
pipeline/backend/kubernetes/pod.go 0.00% <0.00%> (ø)
pipeline/frontend/yaml/compiler/convert.go 0.00% <0.00%> (ø)
pipeline/frontend/yaml/container.go 77.77% <ø> (ø)

... and 10 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@anbraten
Copy link
Member

In general a really nice, clean and thoughtful PR. Thanks for that.

@pat-s
Copy link
Contributor

pat-s commented May 19, 2023

Ah great! I was just playing around with this a few days ago without success...

Would it be hard to add a global resource definition? Which is overwritten by definitions in individual steps?

@smuth4
Copy link
Contributor Author

smuth4 commented May 19, 2023

Ah great! I was just playing around with this a few days ago without success...

Would it be hard to add a global resource definition? Which is overwritten by definitions in individual steps?

It certainly sounds like a good idea, how does a top-level backend_options sound @anbraten? It might not be a good idea to try and over-generalize the solution with some sort of top>step merge (since you might want to handle things like arrays differently depending on context), but the structure could at least be the same.

---
backend_options:
  kubernetes:
    resources:
      request:
        cpu: 1000m
        memory: 1024Mi
pipeline:
  my-step:
    image: golang
    backend_options:
      kubernetes:
        resources:
          request:
            cpu: 2000m # Requests 2000m CPU
                       # Requests 1024 Mi memory

@6543
Copy link
Member

6543 commented May 23, 2023

I would not add a top level definition feature as you can do that already with: https://woodpecker-ci.org/docs/next/usage/advanced-yaml-syntax#map-merges-and-overwrites

if it's an agent config that do overwrite step config ... if step.limit>agent.limit that's of course another request and valid

@pat-s
Copy link
Contributor

pat-s commented May 23, 2023

I would not add a top level definition feature as you can do that already with: woodpecker-ci.org/docs/next/usage/advanced-yaml-syntax#map-merges-and-overwrites

Are you sure this is possible? To my knowledge this is not parsed to pod.go and the object created there. This is the nr.1 feature I am still waiting for (would take any workaround that works!). AFAICS the resources are currently hardcoded to 1 CPU, 2 GB mem.

@smuth4
Copy link
Contributor Author

smuth4 commented May 23, 2023

I would not add a top level definition feature as you can do that already with: https://woodpecker-ci.org/docs/next/usage/advanced-yaml-syntax#map-merges-and-overwrites

That's what I get for working with tools that scaffold YAML for me all day, I completely blanked on the native features. 😞

if it's an agent config that do overwrite step config ... if step.limit>agent.limit that's of course another request and valid

I thought about adding this, but kubernetes already has native tools for setting default/limit ranges (although only on a per-namespace basis): https://kubernetes.io/docs/concepts/policy/limit-range/

I would not add a top level definition feature as you can do that already with: woodpecker-ci.org/docs/next/usage/advanced-yaml-syntax#map-merges-and-overwrites

Are you sure this is possible? To my knowledge this is not parsed to pod.go and the object created there. This is the nr.1 feature I am still waiting for (would take any workaround that works!). AFAICS the resources are currently hardcoded to 1 CPU, 2 GB mem.

I tested it and it should work, e.g.

variables:
  - &resources
    requests:
      memory: "4Gi"
      cpu: "250m"
    limits:
      memory: "8Gi"
      cpu: "1000m"
pipeline:
  build:
    image: golang
    backend_options:
      kubernetes:
        # Gets 4Gi & 250m requests, 2000m limits
        resources:
          <<: *resources
          limits:
            cpu: "2000m"

@pat-s
Copy link
Contributor

pat-s commented May 24, 2023

I tested it and it should work, e.g.

But does it work without explicit mapping? I.e. usually I would like to write it as follows

variables:
  - &resources
    requests:
      memory: "4Gi"
      cpu: "250m"
    limits:
      memory: "8Gi"
      cpu: "1000m"
pipeline:
  build:
    image: golang

and this should result in the step honoring the top-level resources unless they are explicitly set/overwritten in the respective step.

Imagine a pipeline with many steps: it should be possible that each step follows a global resource definition without a redundant resources mapping within each step.

@6543 Given that other top-level arguments like platform exist, I think it would be "cleaner" to have resources being an "official" top level setting rather than forcing users to invoke it via map-merges?

@zc-devs
Copy link
Contributor

zc-devs commented May 27, 2023

@smuth4, great work and thank you for this desired functionality!

As I understand, this configuration is per step or per pipeline. Could we add per agent configuration (like I've done here 8eb240b)?

@smuth4
Copy link
Contributor Author

smuth4 commented May 27, 2023

@smuth4, great work and thank you for this desired functionality!

As I understand, this configuration is per step or per pipeline. Could we add per agent configuration (like I've done here 8eb240b)?

I understand the desire for the feature, but can you explain the use case which requires it to be part of the woodpecker code? Specifically, I'm trying to avoid re-implementing LimitRanges, which are very powerful and native to kubernetes, but do require application at the namespace level.

@qwerty287 qwerty287 added enhancement improve existing features backend/kubernetes labels May 28, 2023
@qwerty287 qwerty287 added this to the 1.0.0 milestone May 28, 2023
@zc-devs
Copy link
Contributor

zc-devs commented May 28, 2023

@smuth4, yeah, you're right. Cool feature.

@6543
Copy link
Member

6543 commented Jun 3, 2023

@6543 Given that other top-level arguments like platform exist ...

well it does exist but I consider this an legacy and we do move to labels ... witch can filter backend, platform, ...

so there might come the time where it will be deprecated in favour of a simpler and more generic solution

but that's something for the #567 to talk about :D

@6543 6543 dismissed anbraten’s stale review June 3, 2023 22:40

outdated & addressed

@6543 6543 enabled auto-merge (squash) June 3, 2023 22:40
@6543 6543 mentioned this pull request Jun 3, 2023
9 tasks
@6543 6543 disabled auto-merge June 3, 2023 22:49
@6543 6543 merged commit 2941e50 into woodpecker-ci:master Jun 3, 2023
@smuth4 smuth4 deleted the feature/k8s-resources branch June 4, 2023 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend/kubernetes enhancement improve existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

document Kubernetes backend
8 participants