Skip to content

add resource quota for testing ns - #1382

Merged
Andrei Kvapil (kvaps) merged 4 commits into
mainfrom
feat/tests-with-resource-quota
Sep 4, 2025
Merged

Andrei Kvapil (kvaps) merged 4 commits into
mainfrom
feat/tests-with-resource-quota

Conversation

@IvanHunters

@IvanHunters IvanHunters commented Sep 3, 2025 •

Copy link
Copy Markdown
Collaborator

What this PR does

Release note

add resource quota for testing ns

Summary by CodeRabbit

  • Tests

    • Enhanced end-to-end installation tests to configure the root tenant with host, ingress, monitoring, and storage backend enabled.
    • Added explicit resource quotas (CPU, memory, storage) for a test tenant to validate quota handling and improve reliability.
    • Minor formatting cleanup in a test for readability.
  • Refactor

    • Adjusted resource templating to omit limits for certain non-CPU/memory resources and simplified the produced YAML shape.

@coderabbitai

coderabbitai Bot commented Sep 3, 2025 •

Copy link
Copy Markdown
Contributor

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Updated the e2e install script to patch the root Tenant enabling host/ingress/monitoring/seaweedfs and to replace an empty resourceQuotas map with explicit cpu/memory/storage quotas for a test tenant; adjusted cozy-lib template resource emission to drop limits for ephemeral-storage and other non-CPU/memory resources and to return a raw mapping (no top-level resourceQuotas key).

Changes

Cohort / File(s) Summary of changes
E2E tenant configuration updates
hack/e2e-install-cozystack.bats
Added a patch step to set root Tenant spec flags (host, ingress, monitoring, seaweedfs). Replaced resourceQuotas: {} for the test Tenant with explicit quotas: cpu: "8", memory: "16Gi", storage: "100Gi". Added a blank line before the new patch command (formatting).
cozy-lib resource templates
packages/library/cozy-lib/templates/_resources.tpl
In cozy-lib.resources.sanitize: stopped emitting limits for ephemeral-storage and for non-CPU/non-memory resources (only requests are emitted for those); CPU and memory branches unchanged. In cozy-lib.resources.flatten: removed the `dict "resourceQuotas" $out

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Dev as Developer
  participant BATS as e2e-install-cozystack.bats
  participant KCTL as kubectl
  participant API as Kubernetes API
  participant Tenant as Tenant CR

  Dev->>BATS: run e2e script
  BATS->>KCTL: patch root Tenant spec (enable host/ingress/monitoring/seaweedfs)
  KCTL->>API: PATCH /apis/.../tenants/root
  API-->>KCTL: 200 OK
  BATS->>KCTL: patch test Tenant resourceQuotas (cpu/memory/storage)
  KCTL->>API: PATCH /apis/.../tenants/test
  API-->>KCTL: 200 OK
  BATS->>API: wait for applications ready
  API-->>BATS: Ready status
  BATS-->>Dev: e2e complete
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • lllamnyp
  • klinch0

Poem

I hopped through scripts at break of day,
Patched a root so apps could play.
Quotas set and limits light,
Templates lean for snug good night.
🥕🐇


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between d0bde51 and 1028799.

📒 Files selected for processing (1)
  • hack/e2e-install-cozystack.bats (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • hack/e2e-install-cozystack.bats
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/tests-with-resource-quota

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Summary of Changes

Hello IvanHunters, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the end-to-end testing environment by implementing resource quotas for the dedicated testing namespace. This change aims to simulate a more constrained environment for tests, ensuring that applications within the test tenant adhere to predefined resource limits for CPU, memory, and storage.

Highlights

  • Resource Quota Configuration: This pull request introduces specific resource quotas (CPU, memory, and storage) for the tenant-test namespace within the e2e installation script. This ensures that the testing environment operates with defined resource limits.
  • E2E Test Script Update: The hack/e2e-install-cozystack.bats script has been updated to include these resource quota definitions, which are applied when configuring the tenant-test tenant.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment Gemini (@gemini-code-assist) Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on Gemini (@gemini-code-assist) comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request adds resource quotas for the testing namespace in the e2e tests, which is a valuable addition for ensuring resource constraints are tested. The implementation is straightforward, but there is a minor style issue with YAML indentation that should be addressed for better code readability and maintainability.

Comment thread hack/e2e-install-cozystack.bats Outdated
Comment on lines +192 to +195
resourceQuotas:
cpu: "4"
memory: "4Gi"
storage: "100Gi"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The indentation for the resourceQuotas properties is unconventional. While a single space indentation might be parsed correctly by kubectl, it's against common YAML style guides which recommend two-space indentation for readability and consistency. This makes the file harder to read and maintain. Please use a two-space indent for the properties under resourceQuotas.

  resourceQuotas:
    cpu: "4"
    memory: "4Gi"
    storage: "100Gi"

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (2)
hack/e2e-install-cozystack.bats (2)

126-131: Root-tenant patch is fine; prefer fully qualified resource for clarity

Using the group-qualified resource avoids ambiguity if another CRD named “tenants” exists.

-  kubectl patch tenants/root -n tenant-root --type merge -p '{"spec":{"host":"example.org","ingress":true,"monitoring":true,"etcd":true,"isolated":true, "seaweedfs": true}}'
+  kubectl patch tenants.apps.cozystack.io/root -n tenant-root --type merge -p '{"spec":{"host":"example.org","ingress":true,"monitoring":true,"etcd":true,"isolated":true,"seaweedfs":true}}'

192-195: Normalize YAML indentation under resourceQuotas

Children of resourceQuotas are indented by 1 space; the file otherwise uses 2-space steps. Standardize for readability.

   resourceQuotas:
-   cpu: "4"
-   memory: "4Gi"
-   storage: "100Gi"
+    cpu: "4"
+    memory: "4Gi"
+    storage: "100Gi"
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between c0d5e52 and 08fbeca.

📒 Files selected for processing (1)
  • hack/e2e-install-cozystack.bats (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build
🔇 Additional comments (1)
hack/e2e-install-cozystack.bats (1)

192-200: Verify Tenant CRD schema and resource quotas

  • Manually confirm the Tenant CRD (tenants.apps.cozystack.io, version v1alpha1) defines spec.resourceQuotas with cpu, memory, and storage under its OpenAPI schema.
  • Apply the e2e install and ensure a ResourceQuota in the tenant-test namespace is created with hard limits set to cpu: "4", memory: "4Gi", and storage: "100Gi".

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
packages/library/cozy-lib/templates/_resources.tpl (2)

49-53: Bug: unit parsing uses root context ($) instead of the input value ($value).

This breaks suffix detection (and can cause type errors) for quantities like "256Mi" or "500m".

Apply this fix:

-            {{- if hasSuffix $k $ -}}
-                {{- $value = trimSuffix $k $ -}}
+            {{- if hasSuffix $k $value -}}
+                {{- $value = trimSuffix $k $value -}}
                 {{- $unit = $v -}}
             {{- end -}}

107-113: Add missing limits assignments for ephemeral-storage and other resources
In the cozy-lib.resources.sanitize template, the ephemeral-storage and default branches set only requests, leaving limits unset (lines 107–113). This diverges from the documented contract—non-CPU/memory resources must emit identical limits and requests. Restore symmetry by adding $_ := set $output.limits in both branches:

     else if eq $k "ephemeral-storage" }}
       {{- $_ := set $output.requests $k ($ephemeralStorageRequestF64 | int | toString) }}
+      {{- $_ := set $output.limits   $k ($v | toString) }}
     else }}
-      {{- $_ := set $output.requests $k $v }}
+      {{- $_ := set $output.requests $k ($v | toString) }}
+      {{- $_ := set $output.limits   $k ($v | toString) }}
     end }}
🧹 Nitpick comments (1)
packages/library/cozy-lib/templates/_resources.tpl (1)

58-86: Update the sanitize() docblock to match behavior.

The comment says “All resources are returned with equal requests and limits, except cpu…”, but the implementation currently omits limits for ephemeral-storage and others.

Propose clarifying the contract (either restore limits per previous comment or document the new requests-only behavior with examples).

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between cf71f6f and d0bde51.

📒 Files selected for processing (1)
  • packages/library/cozy-lib/templates/_resources.tpl (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build

Comment on lines +183 to 184
{{- $out | toYaml }}
{{- end }}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Breaking change: flatten() output shape dropped the resourceQuotas wrapper.

This will break any consumers expecting keys under resourceQuotas.*.

  • Please confirm all call sites/tests were updated. Run:

  • Consider a short deprecation period (feature flag or alias helper) and add a release note highlighting the YAML shape change.


🏁 Script executed:

#!/bin/bash
# Find usages relying on the old wrapper and flatten invocations
rg -nP -C2 'resourceQuotas\.' 
rg -nP -C2 'include\s+"cozy-lib\.resources\.flatten"'

Length of output: 1778


Breaking change: flatten() now drops the resourceQuotas wrapper

The only consumer of this helper is in packages/apps/tenant/templates/quota.yaml:9. After this change it will emit the quota fields unwrapped (no top-level resourceQuotas:), so that template will break. Update it to re-introduce the wrapper (or adjust its structure), and verify any tests for cozy-lib.resources.flatten have been updated. Add a release note for the YAML shape change and consider a deprecation alias or feature flag for backward compatibility.

🤖 Prompt for AI Agents
In packages/library/cozy-lib/templates/_resources.tpl around lines 183 to 184,
flatten() has been changed to emit quota fields without the top-level
resourceQuotas: wrapper which will break
packages/apps/tenant/templates/quota.yaml (line 9) and tests. Update
packages/apps/tenant/templates/quota.yaml to re-introduce the wrapper by
wrapping the flattened output under resourceQuotas: (or adjust the template
structure to match the new flat shape), update or add unit tests for
cozy-lib.resources.flatten to reflect the new output shape (or add tests for a
deprecation alias that preserves the old wrapped output), add a release note
describing the YAML shape change, and optionally implement a short-term
deprecation alias or feature flag in the library to emit the old wrapped
structure for backward compatibility.

@kvaps Andrei Kvapil (kvaps) added the kind/backport Categorizes issue or PR as requiring a backport to the current release line label Sep 4, 2025
@kvaps
Andrei Kvapil (kvaps) merged commit 17ee5c5 into main Sep 4, 2025
7 of 8 checks passed
@kvaps
Andrei Kvapil (kvaps) deleted the feat/tests-with-resource-quota branch September 4, 2025 15:22
@github-actions

github-actions Bot commented Sep 4, 2025

Copy link
Copy Markdown

Successfully created backport PR for release-0.35:

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

Labels

kind/backport Categorizes issue or PR as requiring a backport to the current release line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants