8000 Let users specify CPU requests in VCPUs by lllamnyp · Pull Request #972 · cozystack/cozystack · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Let users specify CPU requests in VCPUs #972

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

Merged
merged 2 commits into from
May 30, 2025
Merged

Let users specify CPU requests in VCPUs #972

merged 2 commits into from
May 30, 2025

Conversation

lllamnyp
Copy link
Member
@lllamnyp lllamnyp commented May 22, 2025

With this change a request for a virtual machine with 3 vCPUs will reserve exactly the same amount of physical compute, as a request for a Clickhouse instance with {"resources": {"cpu": "3"}} in its values, with the scaling factor being KubeVirt's CPU allocation ratio.

Summary by CodeRabbit

  • New Features

    • Introduced configurable CPU allocation ratio for resource management, allowing CPU requests to be scaled relative to limits.
    • Added new templates for input validation and automatic loading of configuration from Kubernetes ConfigMaps.
  • Bug Fixes

    • Improved resource sanitization and preset logic to handle CPU and memory requests/limits more accurately.
  • Chores

    • Updated chart dependencies and versioning to reflect changes in library usage.

@lllamnyp lllamnyp requested review from kvaps and klinch0 as code owners May 22, 2025 06:36
Copy link
Contributor
coderabbitai bot commented May 22, 2025

Warning

Rate limit exceeded

@kvaps has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 6 minutes and 36 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 50aed6a and 7023abd.

📒 Files selected for processing (7)
  • packages/apps/clickhouse/Chart.yaml (1 hunks)
  • packages/apps/clickhouse/templates/clickhouse.yaml (1 hunks)
  • packages/library/cozy-lib/Chart.yaml (1 hunks)
  • packages/library/cozy-lib/templates/_checkinput.tpl (1 hunks)
  • packages/library/cozy-lib/templates/_cozyconfig.tpl (1 hunks)
  • packages/library/cozy-lib/templates/_resourcepresets.tpl (1 hunks)
  • packages/library/cozy-lib/templates/_resources.tpl (1 hunks)

Walkthrough

This change updates the ClickHouse Helm chart to explicitly declare a dependency on the internal cozy-lib library chart. It also upgrades the cozy-lib chart version, introduces new resource management templates, and modifies resource preset and sanitization logic to support CPU allocation ratios and improved context handling.

Changes

File(s) Change Summary
packages/apps/clickhouse/Chart.yaml Added cozy-lib as a dependency in the Helm chart metadata.
packages/library/cozy-lib/Chart.yaml Bumped cozy-lib chart version from 0.1.0 to 0.2.0.
packages/library/cozy-lib/templates/_resources.tpl Introduced CPU allocation ratio logic, resource quantity parsing, and enhanced resource sanitization template.
packages/apps/clickhouse/templates/clickhouse.yaml Updated resource template calls to pass both resource values and context as a list to resource helpers.
packages/library/cozy-lib/templates/_checkinput.tpl Added new template for input type checking, failing on incorrect input kinds.
packages/library/cozy-lib/templates/_cozyconfig.tpl Added new template to load cozyConfig from a ConfigMap if not already present in context.
packages/library/cozy-lib/templates/_resourcepresets.tpl Updated resource preset logic to use CPU allocation ratios and new internal dictionaries for CPU/memory requests/limits.

Sequence Diagram(s)

sequenceDiagram
    participant Helm as Helm Chart Renderer
    participant ClickHouse as ClickHouse Chart
    participant CozyLib as cozy-lib Templates
    participant K8s as Kubernetes API

    Helm->>ClickHouse: Render ClickHouse chart
    ClickHouse->>CozyLib: Call resources.sanitize/preset with [values, context]
    CozyLib->>CozyLib: Check input type (checkInput)
    CozyLib->>CozyLib: Load cozyConfig if missing (loadCozyConfig)
    CozyLib->>CozyLib: Sanitize/merge resources, apply CPU allocation ratio
    CozyLib->>ClickHouse: Return sanitized resource YAML
    ClickHouse->>K8s: Deploy with computed resources
Loading

Possibly related PRs

  • cozystack/cozystack#935: Also modifies ClickHouse resource templating to use cozy-lib resource sanitization and presets, directly overlapping with this PR's changes.

Suggested reviewers

  • lllamnyp
  • klinch0

Poem

In cozy stacks where charts reside,
A rabbit hops with Helm as guide.
CPU ratios now in play,
Resource presets lead the way.
With context passed and checks anew,
ClickHouse shines with cozy hue!
🐇✨


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.

@lllamnyp lllamnyp self-assigned this May 23, 2025
@lllamnyp lllamnyp force-pushed the fix/no-user-facing-limits branch 5 times, most recently from efd7ccb to abf9652 Compare May 23, 2025 11:03
@lllamnyp lllamnyp force-pushed the feat/user-facing-vcpu branch from 6095caa to 3ebf2e2 Compare May 23, 2025 11:04
@lllamnyp lllamnyp force-pushed the fix/no-user-facing-limits branch 3 times, most recently from 860d18c to 6f702b5 Compare May 23, 2025 13:06
@lllamnyp lllamnyp force-pushed the feat/user-facing-vcpu branch from 3ebf2e2 to 3e8d115 Compare May 23, 2025 13:27
@lllamnyp lllamnyp force-pushed the fix/no-user-facing-limits branch from 6f702b5 to 9592f7f Compare May 23, 2025 14:33
@lllamnyp lllamnyp force-pushed the feat/user-facing-vcpu branch from 3e8d115 to 99d4ec5 Compare May 23, 2025 14:34
Base automatically changed from fix/no-user-facing-limits to main May 23, 2025 15:11
@lllamnyp lllamnyp force-pushed the feat/user-facing-vcpu branch from 99d4ec5 to a1fbed1 Compare May 28, 2025 04:02
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: 2

🔭 Outside diff range comments (1)
packages/library/cozy-lib/templates/_resources.tpl (1)

56-83: ⚠️ Potential issue

Add validation for CPU allocation ratio and error handling.

The sanitize function needs protection against edge cases:

  1. Division by zero if $cpuAllocationRatio is 0
  2. Invalid CPU values that can't be converted to float

Add validation before the division:

 {{-   $cpuAllocationRatio := include "cozy-lib.resources.cpuAllocationRatio" dict | float64 }}
+{{-   if le $cpuAllocationRatio 0.0 }}
+{{-     fail "CPU allocation ratio must be greater than 0" }}
+{{-   end }}

Consider adding error handling for the float conversion:

 {{-       $vcpuRequestF64 := (include "cozy-lib.resources.toFloat" $v) | float64 }}
+{{-       if eq $vcpuRequestF64 0.0 }}
+{{-         fail (printf "Invalid CPU value: %s" $v) }}
+{{-       end }}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f9f8bb2 and a1fbed1.

📒 Files selected for processing (5)
  • packages/apps/clickhouse/Chart.yaml (1 hunks)
  • packages/library/cozy-lib/00-init.tpl (1 hunks)
  • packages/library/cozy-lib/Chart.yaml (1 hunks)
  • packages/library/cozy-lib/templates/_resources.tpl (3 hunks)
  • packages/library/versions_map (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build and Test
🔇 Additional comments (4)
packages/library/cozy-lib/Chart.yaml (1)

18-18: Version bump looks appropriate for new features.

The version increment from 0.1.0 to 0.2.0 correctly follows semantic versioning for the new CPU allocation ratio functionality.

packages/library/versions_map (1)

1-2: Version mapping correctly tracks releases.

Good practice to pin the previous version to a specific commit while the new version tracks HEAD.

packages/apps/clickhouse/Chart.yaml (1)

27-30: Dependency declaration is correctly configured.

The addition of cozy-lib as a dependency is properly formatted with the correct internal repository URL.

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

13-27: Well-implemented resource quantity converter.

The toFloat function correctly handles both base-2 and base-10 units with appropriate multipliers. Good use of hex float literals for precise base-2 values.

@lllamnyp lllamnyp force-pushed the feat/user-facing-vcpu branch from a1fbed1 to 0839b4b Compare May 29, 2025 13:21
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: 2

♻️ Duplicate comments (1)
packages/library/cozy-lib/templates/_resources.tpl (1)

5-13: Variable scoping issue appears to be resolved.

The previous review comment about $cozyConfig scoping has been addressed. The template now calls include "cozy-lib.loadCozyConfig" . and accesses the config via index . 1 "cozyConfig", which suggests the config is properly loaded into the context.

🧹 Nitpick comments (3)
packages/library/cozy-lib/templates/_cozyconfig.tpl (1)

1-7: Consider adding error handling for missing ConfigMap.

The template correctly loads the ConfigMap, but doesn't handle the case where the cozystack ConfigMap might not exist in the cozy-system namespace. This could lead to silent failures.

Consider adding a check:

 {{- define "cozy-lib.loadCozyConfig" }}
 {{-   include "cozy-lib.checkInput" . }}
 {{-   if not (hasKey (index . 1) "cozyConfig") }}
 {{-     $cozyConfig := lookup "v1" "ConfigMap" "cozy-system" "cozystack" }}
+{{-     if not $cozyConfig }}
+{{-       fail "ConfigMap 'cozystack' not found in namespace 'cozy-system'" }}
+{{-     end }}
 {{-     $_ := set (index . 1) "cozyConfig" $cozyConfig }}
 {{-   end }}
 {{- end }}
packages/library/cozy-lib/templates/_resources.tpl (2)

15-29: Add validation for edge cases in unit conversion.

The toFloat function handles unit conversion well, but consider adding validation for edge cases:

  1. Empty strings or invalid numeric values
  2. Unknown units that might not be caught by the suffix matching

Consider adding basic validation:

{{- define "cozy-lib.resources.toFloat" -}}
    {{- $value := . -}}
+   {{- if not . -}}
+       {{- fail "Empty value provided to toFloat" -}}
+   {{- end -}}
    {{- $unit := 1.0 -}}
    {{- if typeIs "string" . -}}
        {{- $base2 := dict "Ki" 0x1p10 "Mi" 0x1p20 "Gi" 0x1p30 "Ti" 0x1p40 "Pi" 0x1p50 "Ei" 0x1p60 -}}
        {{- $base10 := dict "m" 1e-3 "k" 1e3 "M" 1e6 "G" 1e9 "T" 1e12 "P" 1e15 "E" 1e18 -}}
        {{- range $k, $v := merge $base2 $base10 -}}
            {{- if hasSuffix $k $ -}}
                {{- $value = trimSuffix $k $ -}}
                {{- $unit = $v -}}
            {{- end -}}
        {{- end -}}
    {{- end -}}
+   {{- if not (kindIs "float64" (float64 $value)) -}}
+       {{- fail (printf "Invalid numeric value: %s" $value) -}}
+   {{- end -}}
    {{- mulf (float64 $value) $unit | toString -}}
{{- end -}}

85-87: CPU allocation calculation aligns with PR objectives.

The CPU allocation logic correctly implements the PR objective of allowing users to specify CPU requests in vCPUs. The vCPU value is divided by the allocation ratio to determine the actual CPU request, which aligns with KubeVirt's CPU allocation behavior.

However, consider potential precision issues when converting between float64 and string representations.

To improve precision handling, consider using a more controlled string formatting:

-{{-       $_ := set $output.requests $k ($cpuRequestF64 | toString) }}
+{{-       $_ := set $output.requests $k (printf "%.3f" $cpuRequestF64) }}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a1fbed1 and 0839b4b.

📒 Files selected for processing (7)
  • packages/apps/clickhouse/templates/clickhouse.yaml (1 hunks)
  • packages/library/cozy-lib/Chart.yaml (1 hunks)
  • packages/library/cozy-lib/templates/_checkinput.tpl (1 hunks)
  • packages/library/cozy-lib/templates/_cozyconfig.tpl (1 hunks)
  • packages/library/cozy-lib/templates/_resourcepresets.tpl (1 hunks)
  • packages/library/cozy-lib/templates/_resources.tpl (1 hunks)
  • packages/library/versions_map (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/library/versions_map
  • packages/library/cozy-lib/Chart.yaml
🔇 Additional comments (5)
packages/library/cozy-lib/templates/_checkinput.tpl (1)

1-5: LGTM! Clean input validation helper.

The template provides clear validation for the expected input format and helpful error messages.

packages/apps/clickhouse/templates/clickhouse.yaml (1)

124-128: LGTM! Template calls correctly updated for new argument format.

The changes properly adapt to the new cozy-lib template signatures by passing arguments as lists with context.

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

17-42: Good refactoring to separate CPU and memory resources.

The separation of CPU and memory resources into distinct dictionaries improves maintainability. The dynamic CPU limit calculation based on the allocation ratio is a nice enhancement that aligns with the PR objective of standardizing CPU resource allocation.


14-14:

❌ Incorrect review comment

Verify the existence of required helper templates.

The template references cozy-lib.resources.cpuAllocationRatio and cozy-lib.resources.toFloat which are not visible in the provided files.

Also applies to: 37-37


🏁 Script executed:

#!/bin/bash
# Description: Search for the missing helper templates that are referenced but not provided

# Search for cpuAllocationRatio template definition
echo "Searching for cpuAllocationRatio template..."
rg -A 10 'define\s+"cozy-lib\.resources\.cpuAllocationRatio"' packages/library/cozy-lib/

# Search for toFloat template definition
echo "Searching for toFloat template..."
rg -A 10 'define\s+"cozy-lib\.resources\.toFloat"' packages/library/cozy-lib/

# Check if there's a _resources.tpl file that might contain these
echo "Checking for _resources.tpl file..."
fd -t f "_resources.tpl" packages/library/cozy-lib/

Length of output: 2616


Helper templates verified in _resources.tpl

The referenced templates are already defined in packages/library/cozy-lib/templates/_resources.tpl:

  • cozy-lib.resources.cpuAllocationRatio
  • cozy-lib.resources.toFloat

No missing helpers—no changes required.

Likely an incorrect or invalid review comment.

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

63-78:

✅ Verification successful

Parameter structure change may impact existing consumers.

The template now expects arguments at index . 0 instead of direct access to .. This is a breaking change that could affect existing consumers of this template.

Verify that all consumers of cozy-lib.resources.sanitize have been updated to pass arguments in the new format.


🏁 Script executed:

#!/bin/bash
# Description: Find all usages of cozy-lib.resources.sanitize to verify parameter format
# Expected: All calls should pass context with resources at index 0

echo "Searching for all usages of cozy-lib.resources.sanitize:"
rg -A 3 -B 1 "cozy-lib\.resources\.sanitize"

echo -e "\nSearching for potential old-style calls:"
rg -A 3 -B 1 "include.*cozy-lib\.resources\.sanitize.*\.Values\.resources"

Length of output: 2867


All consumers updated to new cozy-lib.resources.sanitize signature

I searched the repo for calls to cozy-lib.resources.sanitize and confirmed that:

  • packages/apps/clickhouse/templates/clickhouse.yaml now invokes it with (list .Values.resources $).
  • The only remaining “old-style” invocation is the example comment in _resources.tpl itself, which isn’t executed by consumers.

No breaking impact—no changes required.

*/}}
{{- define "cozy-lib.resources.sanitize" }}
{{- $cpuAllocationRatio := include "cozy-lib.resources.cpuAllocationRatio" . | float64 }}
Copy link
Contributor
@coderabbitai coderabbitai bot May 29, 2025

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add validation for CPU allocation ratio.

The CPU allocation ratio should be validated to ensure it's positive and non-zero to prevent division by zero errors.

Add validation after retrieving the ratio:

{{-   $cpuAllocationRatio := include "cozy-lib.resources.cpuAllocationRatio" . | float64 }}
+{{-   if le $cpuAllocationRatio 0.0 }}
+{{-     fail "CPU allocation ratio must be positive and non-zero" }}
+{{-   end }}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{{- $cpuAllocationRatio := include "cozy-lib.resources.cpuAllocationRatio" . | float64 }}
{{- $cpuAllocationRatio := include "cozy-lib.resources.cpuAllocationRatio" . | float64 }}
{{- if le $cpuAllocationRatio 0.0 }}
{{- fail "CPU allocation ratio must be positive and non-zero" }}
{{- end }}
🤖 Prompt for AI Agents
In packages/library/cozy-lib/templates/_resources.tpl at line 61, add validation
for the CPU allocation ratio after retrieving it to ensure it is positive and
non-zero. Check if the value is less than or equal to zero, and if so, handle
the error appropriately (e.g., set a default positive value or raise an error)
to prevent division by zero errors later in the code.

Copy link
Collaborator

Choose a reason for hiding this comment

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

worth considering

Copy link
Contributor

Choose a reason for hiding this comment

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

@NickVolynkin You're absolutely right! The validation would be crucial here since the CPU allocation ratio is used in division operations. Without proper validation, invalid configuration values (like 0 or negative numbers) could lead to runtime failures or unexpected resource calculations.

The suggested validation would catch these issues early and provide clear error messages, making the template more robust and easier to debug when misconfigured.

  /|   /|  
 ( :v:  ) 
  |(_)|

@lllamnyp lllamnyp force-pushed the feat/user-facing-vcpu branch 2 times, most recently from ba4aa36 to 37b95e1 Compare May 29, 2025 13:30
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

♻️ Duplicate comments (1)
packages/library/cozy-lib/templates/_resources.tpl (1)

61-61: 🛠️ Refactor suggestion

Add validation for CPU allocation ratio to prevent runtime errors.

The CPU allocation ratio should be validated to ensure it's positive and non-zero to prevent division by zero errors in the CPU request calculation.

Add validation after retrieving the ratio:

{{-   $cpuAllocationRatio := include "cozy-lib.resources.cpuAllocationRatio" . | float64 }}
+{{-   if le $cpuAllocationRatio 0.0 }}
+{{-     fail "CPU allocation ratio must be positive and non-zero" }}
+{{-   end }}
🧹 Nitpick comments (1)
packages/library/cozy-lib/templates/_resources.tpl (1)

85-87: Consider precision handling in CPU request calculation.

The conversion from float64 back to string may result in precision loss or unexpected formatting (e.g., scientific notation for very small values). Consider formatting the output to maintain appropriate precision for Kubernetes resource specifications.

Consider using a more controlled string formatting:

-{{-       $_ := set $output.requests $k ($cpuRequestF64 | toString) }}
+{{-       $cpuRequestStr := printf "%.3f" $cpuRequestF64 }}
+{{-       $_ := set $output.requests $k $cpuRequestStr }}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0839b4b and 37b95e1.

📒 Files selected for processing (7)
  • packages/apps/clickhouse/templates/clickhouse.yaml (1 hunks)
  • packages/library/cozy-lib/Chart.yaml (1 hunks)
  • packages/library/cozy-lib/templates/_checkinput.tpl (1 hunks)
  • packages/library/cozy-lib/templates/_cozyconfig.tpl (1 hunks)
  • packages/library/cozy-lib/templates/_resourcepresets.tpl (1 hunks)
  • packages/library/cozy-lib/templates/_resources.tpl (1 hunks)
  • packages/library/versions_map (0 hunks)
💤 Files with no reviewable changes (1)
  • packages/library/versions_map
🚧 Files skipped from review as they are similar to previous changes (5)
  • packages/library/cozy-lib/Chart.yaml
  • packages/library/cozy-lib/templates/_checkinput.tpl
  • packages/library/cozy-lib/templates/_cozyconfig.tpl
  • packages/apps/clickhouse/templates/clickhouse.yaml
  • packages/library/cozy-lib/templates/_resourcepresets.tpl
🔇 Additional comments (5)
packages/library/cozy-lib/templates/_resources.tpl (5)

1-3: LGTM: Simple default value template.

The default CPU allocation ratio of 10 is clearly defined and follows good templating practices.


5-13: LGTM: CPU allocation ratio retrieval with proper fallback.

The template correctly loads the cozy configuration and provides a fallback to the default value when the ConfigMap is not available. The use of dig for safe nested key access is appropriate.


15-29: LGTM: Comprehensive unit conversion implementation.

The resource quantity to float conversion properly handles both binary (Ki, Mi, Gi, etc.) and decimal (m, k, M, etc.) unit prefixes, which aligns with Kubernetes resource quantity standards.


74-78: LGTM: Correct precedence handling for resource merging.

The logic correctly implements the documented precedence where top-level resource keys take priority over requests and limits sections. This provides flexibility while maintaining predictable behavior.


80-90: LGTM: Appropriate CPU vs non-CPU resource handling.

The differentiated handling correctly implements the PR objective: CPU resources are scaled by the allocation ratio for requests while maintaining the original limit, and non-CPU resources have equal requests and limits. This aligns with the goal of allowing vCPU specifications while maintaining consistent resource allocation.

@kvaps kvaps force-pushed the feat/user-facing-vcpu branch from 37b95e1 to 50aed6a Compare May 29, 2025 22:21
@kvaps kvaps enabled auto-merge May 29, 2025 22:43
lllamnyp added 2 commits May 30, 2025 00:55
This patch introduces reusable library charts that provide
backward-compatibility for users that specify their resources as
explicit requests and limits for cpu, however this input is processed so
that limits are set equal to requests except for CPU which only gets
requests. Users can now embrace the new form by directly specifying
resources in the first level of nesting (e.g. resources.cpu=100m instead
of .resources.requests.cpu=100m). The order of precedence is top-level,
then requests, then limits, ensuring that nothing will break in terms of
scheduling, however workloads that specified limits much higher than
requests might get a performance hit, now that they cannot use all this
excess capacity. This should only affect memory-hungry workloads in
low-contention environments.

Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>
With this change a request for a virtual machine with 3 vCPUs will
reserve exactly the same amount of physical compute, as a request for a
Clickhouse instance with `{"resources": {"cpu": "3"}}` in its values,
with the scaling factor being KubeVirt's CPU allocation ratio.

Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>
@kvaps kvaps force-pushed the feat/user-facing-vcpu branch from 50aed6a to 7023abd Compare May 29, 2025 22:55
to have equal requests and limits, except CPU, that has only requests. The
template expects to receive a dict {"requests":{...}, "limits":{...}} as
input, e.g. {{ include "cozy-lib.resources.sanitize" .Values.resources }}.
to have equal requests and limits, except CPU, where the limit is increased
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is ambiguous, and can be understood in two ways:

  • All resources use the same (equal) request and limit preset
  • In each given resource's default preset, requests equal limits

Copy link
Member Author
@lllamnyp lllamnyp May 30, 2025

Choose a reason for hiding this comment

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

Re your first point, I don't think anyone can imagine having all requests/limits equal among each other across different resources. 1Mi (1048576) of memory (unit of bytes implied) and 1048576 of cpu (unit of seconds implied) would be pretty wild.

Re your second point -- there aren't any presets here, what do you mean?

Anyway, I'm open to a better wording if you'd like to suggest something.

Example input:
==============
limits:
cpu: 100m
cpu: "1"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Limit of 1 and request of 2 — how does it work? Shouldn't the limit be more or equal to the request?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, hence the name sanitize. The user can input any garbage he or she desires and the function will coerce it to something reasonable and reasonably backwards-compatible. See the comments of the example output bellow.

Copy link
Member
@kvaps kvaps left a comment

Choose a reason for hiding this comment

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

LGTM

@kvaps kvaps merged commit 228e198 into main May 30, 2025
10 of 13 checks passed
@kvaps kvaps deleted the feat/user-facing-vcpu branch May 30, 2025 10:50
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.

3 participants
0