Skip to content

Conversation

kvaps
Copy link
Member

@kvaps kvaps commented Jul 3, 2025

Add. missing commits from #1127, which were skipped by mistake

  • [cozy-lib, bug] divf by cpu ratio, not mulf ([cozy-lib, bug] divf by cpu ratio, not mulf #1125)
  • [cozy-lib] remove handler for nested resources/requests map
  • [cozy-lib] Introduce memory-allocation-ratio and ephemeral-strorage-allocation-ratio options
  • [system] Recuce resources for some system apps

What this PR does

Release note

[cozy-lib] refactor resources

Summary by CodeRabbit

  • New Features

    • Introduced support for memory and ephemeral storage allocation ratios, allowing more flexible resource allocation.
  • Refactor

    • Simplified resource preset structure for easier configuration and management.
    • Updated resource preset logic to use a new sanitization process for resource values.
  • Bug Fixes

    • Improved error handling for invalid resource preset keys.
  • Chores

    • Adjusted resource requests and limits for Redis master, FluxCD operator, and Vertical Pod Autoscaler components to optimize resource usage.

@kvaps kvaps requested review from lllamnyp and klinch0 as code owners July 3, 2025 11:58
Copy link
Contributor

coderabbitai bot commented Jul 3, 2025

Walkthrough

Resource preset and sanitization templates were refactored to use flat resource maps and allocation ratios for CPU, memory, and ephemeral storage. Resource values in several system component Helm charts were updated to reflect new defaults and ratios. The resource preset template signature was updated to accept a global context argument.

Changes

File(s) Change Summary
packages/library/cozy-lib/templates/_resourcepresets.tpl Refactored to use flat resource definitions, increased CPU values, unified ephemeral storage preset, updated signature.
packages/library/cozy-lib/templates/_resources.tpl Added memory and ephemeral storage allocation ratios, updated sanitize logic for flat maps, new ratio functions added.
packages/system/dashboard/values.yaml Updated Redis master memory request (32Mi→128Mi) and limit (256Mi→128Mi).
packages/system/fluxcd-operator/values.yaml Reduced flux-operator CPU (limit 1000m→100m, request 10m→100m) and memory (limit 1Gi→350Mi, request 64Mi→350Mi).
packages/system/vertical-pod-autoscaler/values.yaml Reduced updater and recommender memory limits and requests by 10x (1100Mi→110Mi, 1600Mi→160Mi).

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Template
    participant SanitizeFunc
    participant GlobalContext

    User->>Template: Call cozy-lib.resources.preset(presetKey, global)
    Template->>Template: Lookup flat preset map for presetKey
    Template->>SanitizeFunc: Pass preset map and global context
    SanitizeFunc->>SanitizeFunc: Validate flat map (no nested requests/limits)
    SanitizeFunc->>GlobalContext: Retrieve allocation ratios (CPU, memory, ephemeral storage)
    SanitizeFunc->>SanitizeFunc: Compute requests = limits / ratio
    SanitizeFunc->>Template: Return resource map with requests and limits
    Template->>User: Output sanitized resource YAML
Loading

Possibly related PRs

Suggested labels

enhancement, size:S, lgtm

Suggested reviewers

  • lllamnyp

Poem

In burrows deep, I tweak and tune,
Resource maps are flat as the moon.
Ratios for memory, CPU, and store,
Templates are simpler than ever before.
Limits and requests, all in their place—
A cozy stack, a tidy space!
🐇✨


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@kvaps kvaps changed the title resources [cozy-lib] refactor resources Jul 3, 2025
kvaps added 4 commits July 3, 2025 15:00
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

* **Refactor**
* Updated the structure of resource presets for improved clarity and
processing.
* Adjusted template logic to streamline resource handling and removed
previous resource limit calculations.
* Modified template parameters to enhance flexibility in resource
processing.
* **Chores**
* Improved internal template invocation for better compatibility with
resource data.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
…llocation-ratio options

Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
packages/library/cozy-lib/templates/_resources.tpl (2)

7-9: Consider the implications of the high ephemeral storage allocation ratio.

An allocation ratio of 40 for ephemeral storage means requests will be 1/40th of limits. This allows for significant overcommitment which could lead to node disk pressure if multiple pods consume their full ephemeral storage limits simultaneously.


87-118: Bug fix correctly implemented, but consider precision loss in int conversion.

The division by allocation ratios correctly fixes the bug from issue #1125. However, converting float results to int for memory and ephemeral-storage (lines 105, 110) can cause precision loss.

Consider preserving precision by keeping the float value or rounding appropriately:

-{{-       $_ := set $output.requests $k ($memoryRequestF64 | int) }}
+{{-       $_ := set $output.requests $k ($memoryRequestF64 | printf "%.0f") }}
-{{-       $_ := set $output.requests $k ($ephemeralStorageRequestF64 | int) }}
+{{-       $_ := set $output.requests $k ($ephemeralStorageRequestF64 | printf "%.0f") }}
packages/library/cozy-lib/templates/_resourcepresets.tpl (1)

30-38: Consider scaling ephemeral storage with preset size.

All presets from "nano" to "2xlarge" have the same 2Gi ephemeral storage. Larger workloads typically need more ephemeral storage proportional to their CPU and memory.

Consider scaling ephemeral storage similar to memory:

{{-   $baseEphemeralStorage := dict
-        "nano"    (dict "ephemeral-storage" "2Gi" )
-        "micro"   (dict "ephemeral-storage" "2Gi" )
-        "small"   (dict "ephemeral-storage" "2Gi" )
-        "medium"  (dict "ephemeral-storage" "2Gi" )
-        "large"   (dict "ephemeral-storage" "2Gi" )
-        "xlarge"  (dict "ephemeral-storage" "2Gi" )
-        "2xlarge" (dict "ephemeral-storage" "2Gi" )
+        "nano"    (dict "ephemeral-storage" "1Gi" )
+        "micro"   (dict "ephemeral-storage" "2Gi" )
+        "small"   (dict "ephemeral-storage" "4Gi" )
+        "medium"  (dict "ephemeral-storage" "8Gi" )
+        "large"   (dict "ephemeral-storage" "16Gi" )
+        "xlarge"  (dict "ephemeral-storage" "32Gi" )
+        "2xlarge" (dict "ephemeral-storage" "64Gi" )
}}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0d46393 and 0b7bbb1.

📒 Files selected for processing (5)
  • packages/library/cozy-lib/templates/_resourcepresets.tpl (1 hunks)
  • packages/library/cozy-lib/templates/_resources.tpl (3 hunks)
  • packages/system/dashboard/values.yaml (1 hunks)
  • packages/system/fluxcd-operator/values.yaml (1 hunks)
  • packages/system/vertical-pod-autoscaler/values.yaml (2 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: NickVolynkin
PR: cozystack/cozystack#1120
File: packages/apps/clickhouse/README.md:60-67
Timestamp: 2025-07-03T05:54:50.989Z
Learning: The `cozy-lib.resources.sanitize` function in packages/library/cozy-lib/templates/_resources.tpl supports both standard Kubernetes resource format (with limits:/requests: sections) and flat format (direct resource specifications). The flat format takes priority over nested values. CozyStack apps include cozy-lib as a chart dependency through symlinks in packages/apps/*/charts/cozy-lib directories.
packages/library/cozy-lib/templates/_resourcepresets.tpl (1)
Learnt from: NickVolynkin
PR: cozystack/cozystack#1120
File: packages/apps/clickhouse/README.md:60-67
Timestamp: 2025-07-03T05:54:50.989Z
Learning: The `cozy-lib.resources.sanitize` function in packages/library/cozy-lib/templates/_resources.tpl supports both standard Kubernetes resource format (with limits:/requests: sections) and flat format (direct resource specifications). The flat format takes priority over nested values. CozyStack apps include cozy-lib as a chart dependency through symlinks in packages/apps/*/charts/cozy-lib directories.
packages/library/cozy-lib/templates/_resources.tpl (1)
Learnt from: NickVolynkin
PR: cozystack/cozystack#1120
File: packages/apps/clickhouse/README.md:60-67
Timestamp: 2025-07-03T05:54:50.989Z
Learning: The `cozy-lib.resources.sanitize` function in packages/library/cozy-lib/templates/_resources.tpl supports both standard Kubernetes resource format (with limits:/requests: sections) and flat format (direct resource specifications). The flat format takes priority over nested values. CozyStack apps include cozy-lib as a chart dependency through symlinks in packages/apps/*/charts/cozy-lib directories.
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build
  • GitHub Check: pre-commit
🔇 Additional comments (4)
packages/system/dashboard/values.yaml (1)

27-32: LGTM! Memory allocation adjusted to match request and limit.

The change to equal memory request and limit (128Mi) eliminates overcommit and ensures Redis gets exactly the memory it needs. This aligns with the new resource management approach.

packages/system/vertical-pod-autoscaler/values.yaml (1)

6-11: Verify the 10x memory reduction is sufficient for VPA components.

The memory allocations have been reduced by 90%:

  • updater: 1100Mi → 110Mi
  • recommender: 1600Mi → 160Mi

While reducing resource usage is good, such dramatic reductions could impact VPA performance, especially for the recommender component which analyzes metrics.

Have these reduced values been tested under typical workload conditions? Consider monitoring memory usage after deployment to ensure VPA components don't experience OOM issues.

Also applies to: 26-31

packages/system/fluxcd-operator/values.yaml (1)

8-14: Resource allocation properly adjusted for guaranteed QoS.

The changes set request equal to limit for both CPU (100m) and memory (350Mi), which:

  • Guarantees the pod gets exactly these resources
  • Places it in the Guaranteed QoS class
  • Prevents resource overcommit

The values appear reasonable for a Flux operator workload.

packages/library/cozy-lib/templates/_resourcepresets.tpl (1)

40-43: Resource preset refactoring looks good.

The changes correctly:

  • Merge all resource types into a single presets dictionary
  • Pass the flat resource map to sanitize function
  • Include global context for accessing allocation ratios

This aligns perfectly with the new flat resource map approach.

NickVolynkin added a commit that referenced this pull request Jul 3, 2025
- Change wording for `resources` and `resourcesPreset` variables.
- Explain and give exampls of other object-type variables,
  if their child fields are not annotated.
- Fix a few typos, improve wording.
- Bump all application charts to ensure that new texts are shown
  immediately after updating Cozystack.

Incorporate changes in resourcesPreset values from
#1155
@kvaps kvaps merged commit 73fe621 into main Jul 3, 2025
30 of 32 checks passed
@kvaps kvaps deleted the resources branch July 3, 2025 12:40
kvaps added a commit that referenced this pull request Jul 3, 2025
Merge after #1117 and
#1155


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Documentation**
* Improved clarity and detail in parameter descriptions across multiple
app documentation files, especially for resource configuration options.
* Expanded explanations for `resources` and `resourcesPreset`
parameters, including explicit usage, allowed values, and fallback
behavior.
* Added new sections with YAML configuration examples and reference
tables for resource presets in several app READMEs.
* Corrected typos, improved formatting, and updated terminology for
better readability and consistency.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants