Skip to content

[cozy-lib, bug] divf by cpu ratio, not mulf - #1125

Merged
Andrei Kvapil (kvaps) merged 1 commit into
resourcesfrom
bug/div-by-cpuratio
Jun 27, 2025
Merged

Andrei Kvapil (kvaps) merged 1 commit into
resourcesfrom
bug/div-by-cpuratio

Conversation

@lllamnyp

@lllamnyp Timofei Larkin (lllamnyp) commented Jun 26, 2025 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • 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.

@coderabbitai

coderabbitai Bot commented Jun 26, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

The changes update the structure and processing of resource presets in the template system. The resource dictionaries for CPU and memory are flattened, and logic for generating "limits" from "requests" is removed. Template signatures are updated to accept an additional parameter, and invocations of the sanitize template are adjusted to reflect the new argument structure.

Changes

File(s) Change Summary
packages/library/cozy-lib/templates/_resourcepresets.tpl Flattened CPU/memory dictionaries, removed "limits" logic, added $global parameter, updated sanitize call.
packages/library/cozy-lib/templates/_resources.tpl Changed sanitize template invocation to pass a tuple of resources and context as arguments.

Poem

In templates deep, the presets shift,
No more nested keys adrift.
Limits and requests, now set free,
Flattened fields for all to see.
With new parameters in the air,
The sanitize call gets extra care.
🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4369b03 and 7bacdb9.

📒 Files selected for processing (2)
  • packages/library/cozy-lib/templates/_resourcepresets.tpl (2 hunks)
  • packages/library/cozy-lib/templates/_resources.tpl (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build
  • GitHub Check: pre-commit
🔇 Additional comments (6)
packages/library/cozy-lib/templates/_resources.tpl (2)

37-37: LGTM: Example updated to match new template signature.

The example invocation correctly reflects the updated template signature that now accepts two arguments.


86-86: LGTM: CPU ratio calculation correctly uses division.

This implements the bug fix mentioned in the PR title. Using divf to divide the virtual CPU request by the allocation ratio correctly calculates the actual CPU request (e.g., 1 vCPU ÷ 10 ratio = 100m actual CPU).

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

16-16: LGTM: Template signature updated to accept global context.

The addition of the $global parameter correctly extracts the second argument for passing to the sanitize template.


19-24: LGTM: CPU resource dictionaries correctly flattened.

Removing the nested "requests" structure simplifies the preset data since the sanitize template now handles the requests/limits generation.


28-34: LGTM: Memory resource dictionaries correctly flattened.

Consistent with the CPU changes, the memory dictionaries are properly flattened.


69-70: LGTM: Template invocation updated for new signature.

The preset data extraction and sanitize template call correctly pass both the flattened dictionary and global context as required by the updated template signature.


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
Andrei Kvapil (kvaps) changed the base branch from main to resources June 27, 2025 11:16

@kvaps Andrei Kvapil (kvaps) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@kvaps
Andrei Kvapil (kvaps) merged commit 2d70ec0 into resources Jun 27, 2025
@kvaps
Andrei Kvapil (kvaps) deleted the bug/div-by-cpuratio branch June 27, 2025 11:16
@kvaps

Copy link
Copy Markdown
Member

suppressed by #1127

Andrei Kvapil (kvaps) added a commit that referenced this pull request Jul 3, 2025
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **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 -->
Andrei Kvapil (kvaps) added a commit that referenced this pull request Jul 3, 2025
<!-- 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 <[email protected]>
Andrei Kvapil (kvaps) added a commit that referenced this pull request Jul 3, 2025
Add. missing commits from
#1127, which were skipped by
mistake

- [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

<!-- Thank you for making a contribution! Here are some tips for you:
- Start the PR title with the [label] of Cozystack component:
- For system components: [platform], [system], [linstor], [cilium],
[kube-ovn], [dashboard], [cluster-api], etc.
- For managed apps: [apps], [tenant], [kubernetes], [postgres],
[virtual-machine] etc.
- For development and maintenance: [tests], [ci], [docs], [maintenance].
- If it's a work in progress, consider creating this PR as a draft.
- Don't hesistate to ask for opinion and review in the community chats,
even if it's still a draft.
- Add the label `backport` if it's a bugfix that needs to be backported
to a previous version.
-->

## What this PR does


### Release note

<!--  Write a release note:
- Explain what has changed internally and for users.
- Start with the same [label] as in the PR title
- Follow the guidelines at
https://github.com/kubernetes/community/blob/master/contributors/guide/release-notes.md.
-->

```release-note
[cozy-lib] refactor resources
```

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

## 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.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@github-actions github-actions Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress label Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants