Skip to content

[bugfix] add-resource-quotas-for-pg-jobs-and-fix-install-generate - #1051

Merged
klinch0 merged 1 commit into
mainfrom
(bugfix)--add-resource-quotas-for-pg-jobs
Jun 12, 2025
Merged

[bugfix] add-resource-quotas-for-pg-jobs-and-fix-install-generate#1051
klinch0 merged 1 commit into
mainfrom
(bugfix)--add-resource-quotas-for-pg-jobs

Conversation

@klinch0

@klinch0 klinch0 commented Jun 11, 2025

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features
    • Added default resource specifications for PostgreSQL jobs to ensure consistent CPU and memory allocation.
  • Chores
    • Updated the chart version for the PostgreSQL application.
    • Refreshed version mapping to reflect the latest release.
    • Improved Node.js setup and package installation in the pre-commit workflow.
  • Tests
    • Increased memory allocation for QEMU virtual machines in end-to-end tests.

@coderabbitai

coderabbitai Bot commented Jun 11, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The PostgreSQL Helm chart version was updated to 0.13.0. New Helm template helpers were added to define default resource requests and limits for PostgreSQL jobs and to sanitize these resources via an external helper. These helpers were integrated into the backup CronJob and init job container specifications. The version mapping for PostgreSQL was updated. Additionally, the Node.js setup in the pre-commit GitHub Actions workflow was revised, changing the installation method and package versions.

Changes

Files/Groups Change Summary
packages/apps/postgres/Chart.yaml Chart version incremented from 0.12.1 to 0.13.0
packages/apps/postgres/templates/_postgresjobs.tpl Added Helm templates postgresjobs.defaultResources and postgresjobs.resources for resource defaults and sanitization
packages/apps/postgres/templates/backup-cronjob.yaml,
packages/apps/postgres/templates/init-job.yaml
Included postgresjobs.resources template output in container specs to set resource requests and limits
packages/apps/versions_map Updated "postgres" version mapping: 0.12.1 changed from "HEAD" to commit hash, 0.13.0 added as "HEAD"
.github/workflows/pre-commit.yml Modified Node.js setup and readme-generator-for-helm installation process in GitHub Actions workflow
hack/e2e-cluster.bats Increased memory allocation for QEMU VMs from 16 GB to 24 GB

Sequence Diagram(s)

sequenceDiagram
    participant Helm as Helm Chart
    participant K8s as Kubernetes API
    participant Namespace as Namespace ResourceQuota

    Helm->>K8s: Lookup ResourceQuota in release namespace
    K8s-->>Helm: Return ResourceQuota (if exists)
    Helm->>Helm: Evaluate resource limits/requests (from quota or defaults)
    Helm->>K8s: Render Job/CronJob manifest with computed resources
    K8s-->>Namespace: Deploy Job/CronJob with appropriate resources
Loading

Possibly related PRs

Suggested labels

documentation, enhancement, size:S, lgtm

Suggested reviewers

  • kvaps

Poem

🐇
A hop and a skip, the chart takes a leap,
With resources set smartly, no need to lose sleep.
Quotas are checked, defaults in tow,
Postgres jobs now flex wherever they go!
Version bumped up, the map’s looking neat—
This rabbit’s work is truly complete!
🚀


📜 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 9c962b2 and 8e79f24.

📒 Files selected for processing (7)
  • .github/workflows/pre-commit.yml (1 hunks)
  • hack/e2e-cluster.bats (1 hunks)
  • packages/apps/postgres/Chart.yaml (1 hunks)
  • packages/apps/postgres/templates/_postgresjobs.tpl (1 hunks)
  • packages/apps/postgres/templates/backup-cronjob.yaml (1 hunks)
  • packages/apps/postgres/templates/init-job.yaml (1 hunks)
  • packages/apps/versions_map (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • packages/apps/postgres/templates/backup-cronjob.yaml
  • hack/e2e-cluster.bats
🚧 Files skipped from review as they are similar to previous changes (5)
  • .github/workflows/pre-commit.yml
  • packages/apps/postgres/templates/_postgresjobs.tpl
  • packages/apps/postgres/Chart.yaml
  • packages/apps/versions_map
  • packages/apps/postgres/templates/init-job.yaml
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

@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

🧹 Nitpick comments (2)
packages/apps/postgres/templates/_postgresjobs.tpl (1)

29-45: Nit – quote defaults for consistency

The quota-derived values are wrapped in | quote, whereas the hard-coded defaults (500m, 512Mi, etc.) are not.
Quoting them as well avoids type surprises in downstream tooling and keeps YAML style consistent.

-    cpu: 500m
+    cpu: "500m"-    memory: 512Mi
+    memory: "512Mi"-    cpu: 250m
+    cpu: "250m"-    memory: 256Mi
+    memory: "256Mi"
packages/apps/postgres/Chart.yaml (1)

19-19: Chart version bumped – remember to update CHANGELOG

Version 0.13.0 is fine; ensure the chart’s CHANGELOG (if any) captures the new helper and the behavioural change around job resources.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 632224a and 7bfdfa2.

📒 Files selected for processing (5)
  • packages/apps/postgres/Chart.yaml (1 hunks)
  • packages/apps/postgres/templates/_postgresjobs.tpl (1 hunks)
  • packages/apps/postgres/templates/backup-cronjob.yaml (1 hunks)
  • packages/apps/postgres/templates/init-job.yaml (1 hunks)
  • packages/apps/versions_map (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build
🔇 Additional comments (3)
packages/apps/postgres/templates/backup-cronjob.yaml (1)

84-85: Indentation looks correct but please validate with yamllint

nindent 12 should align resources: with securityContext: (12 spaces) given the current structure.
A quick helm template | yamllint run will confirm there’s no shift that would push resources outside the container block.

packages/apps/postgres/templates/init-job.yaml (1)

53-54: Same indentation caveat as backup CronJob

nindent 8 is expected to align resources: with volumeMounts: inside the container spec.
Please lint the rendered manifest to ensure the block is in the correct location.

packages/apps/versions_map (1)

112-113: HEAD pointer update LGTM

Mapping is consistent with the chart bump.

Comment on lines +26 to +46
{{- if $hasLimitsCPU }}
cpu: {{ $rq.spec.hard.limits.cpu | quote }}
{{- else }}
cpu: 500m
{{- end }}
{{- if $hasLimitsMemory }}
memory: {{ $rq.spec.hard.limits.memory | quote }}
{{- else }}
memory: 512Mi
{{- end }}
requests:
{{- if $hasRequestsCPU }}
cpu: {{ $rq.spec.hard.requests.cpu | quote }}
{{- else }}
cpu: 250m
{{- end }}
{{- if $hasRequestsMemory }}
memory: {{ $rq.spec.hard.requests.memory | quote }}
{{- else }}
memory: 256Mi
{{- 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.

⚠️ Potential issue

Bug – ResourceQuota keys containing dots are being dereferenced incorrectly

limits.cpu, limits.memory, requests.cpu, and requests.memory are flat keys in spec.hard.
Using dot-notation ($rq.spec.hard.limits.cpu) splits the key at the first . and therefore always yields <no value>, causing Helm rendering failures or empty values.

Fix by indexing the map with the full key string:

-    cpu: {{ $rq.spec.hard.limits.cpu | quote }}
+    cpu: {{ index $rq.spec.hard "limits.cpu" | quote }}

-    memory: {{ $rq.spec.hard.limits.memory | quote }}
+    memory: {{ index $rq.spec.hard "limits.memory" | quote }}

-    cpu: {{ $rq.spec.hard.requests.cpu | quote }}
+    cpu: {{ index $rq.spec.hard "requests.cpu" | quote }}

-    memory: {{ $rq.spec.hard.requests.memory | quote }}
+    memory: {{ index $rq.spec.hard "requests.memory" | quote }}
📝 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
{{- if $hasLimitsCPU }}
cpu: {{ $rq.spec.hard.limits.cpu | quote }}
{{- else }}
cpu: 500m
{{- end }}
{{- if $hasLimitsMemory }}
memory: {{ $rq.spec.hard.limits.memory | quote }}
{{- else }}
memory: 512Mi
{{- end }}
requests:
{{- if $hasRequestsCPU }}
cpu: {{ $rq.spec.hard.requests.cpu | quote }}
{{- else }}
cpu: 250m
{{- end }}
{{- if $hasRequestsMemory }}
memory: {{ $rq.spec.hard.requests.memory | quote }}
{{- else }}
memory: 256Mi
{{- end }}
{{- if $hasLimitsCPU }}
cpu: {{ index $rq.spec.hard "limits.cpu" | quote }}
{{- else }}
cpu: 500m
{{- end }}
{{- if $hasLimitsMemory }}
memory: {{ index $rq.spec.hard "limits.memory" | quote }}
{{- else }}
memory: 512Mi
{{- end }}
requests:
{{- if $hasRequestsCPU }}
cpu: {{ index $rq.spec.hard "requests.cpu" | quote }}
{{- else }}
cpu: 250m
{{- end }}
{{- if $hasRequestsMemory }}
memory: {{ index $rq.spec.hard "requests.memory" | quote }}
{{- else }}
memory: 256Mi
{{- end }}
🤖 Prompt for AI Agents
In packages/apps/postgres/templates/_postgresjobs.tpl between lines 26 and 46,
the resource quota keys like limits.cpu and requests.memory are accessed using
dot notation, which incorrectly splits the keys and results in no values. To fix
this, replace dot notation with map indexing using the full key string in
quotes, for example, use $rq.spec.hard["limits.cpu"] instead of
$rq.spec.hard.limits.cpu, and similarly for the other keys.

@klinch0
klinch0 force-pushed the (bugfix)--add-resource-quotas-for-pg-jobs branch 4 times, most recently from 4967dbc to 6d07123 Compare June 11, 2025 07:38
@klinch0 klinch0 changed the title [bugfix] add-resource-quotas-for-pg-jobs [bugfix] add-resource-quotas-for-pg-jobs-and-fix-install-generate Jun 11, 2025
Comment on lines +1 to +11
{{/*
Generate resource requirements based on ResourceQuota named as the namespace.
*/}}
{{- define "postgresjobs.resources" }}
{{- $rq := (lookup "v1" "ResourceQuota" .Release.Namespace .Release.Namespace) }}
{{- $hasLimitsCPU := false }}
{{- $hasLimitsMemory := false }}
{{- $hasRequestsCPU := false }}
{{- $hasRequestsMemory := false }}
{{- if $rq }}
{{- if hasKey $rq.spec.hard "limits.cpu" }}
{{- $hasLimitsCPU = true }}
{{- end }}
{{- if hasKey $rq.spec.hard "limits.memory" }}
{{- $hasLimitsMemory = true }}
{{- end }}
{{- if hasKey $rq.spec.hard "requests.cpu" }}
{{- $hasRequestsCPU = true }}
{{- end }}
{{- if hasKey $rq.spec.hard "requests.memory" }}
{{- $hasRequestsMemory = true }}
{{- end }}
{{- end }}
resources:
limits:
{{- if $hasLimitsCPU }}
cpu: {{ $rq.spec.hard.limits.cpu | quote }}
{{- else }}
cpu: 500m
{{- end }}
{{- if $hasLimitsMemory }}
memory: {{ $rq.spec.hard.limits.memory | quote }}
{{- else }}
memory: 512Mi
{{- end }}
requests:
{{- if $hasRequestsCPU }}
cpu: {{ $rq.spec.hard.requests.cpu | quote }}
{{- else }}
cpu: 250m
{{- end }}
{{- if $hasRequestsMemory }}
memory: {{ $rq.spec.hard.requests.memory | quote }}
{{- else }}
memory: 256Mi
{{- end }}
{{- end }}

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.

Suggested change
{{/*
Generate resource requirements based on ResourceQuota named as the namespace.
*/}}
{{- define "postgresjobs.resources" }}
{{- $rq := (lookup "v1" "ResourceQuota" .Release.Namespace .Release.Namespace) }}
{{- $hasLimitsCPU := false }}
{{- $hasLimitsMemory := false }}
{{- $hasRequestsCPU := false }}
{{- $hasRequestsMemory := false }}
{{- if $rq }}
{{- if hasKey $rq.spec.hard "limits.cpu" }}
{{- $hasLimitsCPU = true }}
{{- end }}
{{- if hasKey $rq.spec.hard "limits.memory" }}
{{- $hasLimitsMemory = true }}
{{- end }}
{{- if hasKey $rq.spec.hard "requests.cpu" }}
{{- $hasRequestsCPU = true }}
{{- end }}
{{- if hasKey $rq.spec.hard "requests.memory" }}
{{- $hasRequestsMemory = true }}
{{- end }}
{{- end }}
resources:
limits:
{{- if $hasLimitsCPU }}
cpu: {{ $rq.spec.hard.limits.cpu | quote }}
{{- else }}
cpu: 500m
{{- end }}
{{- if $hasLimitsMemory }}
memory: {{ $rq.spec.hard.limits.memory | quote }}
{{- else }}
memory: 512Mi
{{- end }}
requests:
{{- if $hasRequestsCPU }}
cpu: {{ $rq.spec.hard.requests.cpu | quote }}
{{- else }}
cpu: 250m
{{- end }}
{{- if $hasRequestsMemory }}
memory: {{ $rq.spec.hard.requests.memory | quote }}
{{- else }}
memory: 256Mi
{{- end }}
{{- end }}
{{/*
Generate resource requirements based on ResourceQuota named as the namespace.
*/}}
{{- define "postgresjobs.defaultResources" }}
resources:
cpu: "1"
memory: 512Mi
{{- end }}
{{- define "postgresjobs.resources" }}
{{- include "cozy-lib.resources.sanitize" (list (include "postgresjobs.defaultResources" $ | fromYaml) $) }}
{{- end }}

@kvaps Andrei Kvapil (kvaps) added the backport Should change be backported on previous release label Jun 11, 2025
@klinch0
klinch0 force-pushed the (bugfix)--add-resource-quotas-for-pg-jobs branch from 6d07123 to a0c1177 Compare June 11, 2025 08:52

@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

🧹 Nitpick comments (2)
packages/apps/postgres/templates/_postgresjobs.tpl (2)

2-3: Comment is misleading – implementation no longer references ResourceQuota

The header still claims resources are “based on ResourceQuota”, but the helper now hard-codes static defaults and delegates everything else to cozy-lib.resources.sanitize.
Please update the comment (or re-introduce the dynamic logic) to avoid future confusion.


10-10: Indent the rendered block to match surrounding YAML

When this helper is inserted in backup-cronjob.yaml / init-job.yaml, it appears under the container stanza that is already indented.
Piping through nindent (or indent) avoids malformed YAML:

-  {{- include "cozy-lib.resources.sanitize" (list (include "postgresjobs.defaultResources" $ | fromYaml) $) }}
+  {{- include "cozy-lib.resources.sanitize" (list (include "postgresjobs.defaultResources" $ | fromYaml) $) | nindent 2 }}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6d07123 and a0c1177.

📒 Files selected for processing (6)
  • .github/workflows/pre-commit.yml (1 hunks)
  • packages/apps/postgres/Chart.yaml (1 hunks)
  • packages/apps/postgres/templates/_postgresjobs.tpl (1 hunks)
  • packages/apps/postgres/templates/backup-cronjob.yaml (1 hunks)
  • packages/apps/postgres/templates/init-job.yaml (1 hunks)
  • packages/apps/versions_map (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/apps/postgres/templates/backup-cronjob.yaml
🚧 Files skipped from review as they are similar to previous changes (4)
  • packages/apps/versions_map
  • packages/apps/postgres/Chart.yaml
  • .github/workflows/pre-commit.yml
  • packages/apps/postgres/templates/init-job.yaml
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build

Comment on lines +4 to +7
{{- define "postgresjobs.defaultResources" }}
resources:
cpu: "1"
memory: 512Mi
{{- 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.

🛠️ Refactor suggestion

Default map shape is not a valid Kubernetes resources object

resources: must contain requests and/or limits sub-maps, not raw cpu/memory keys.
Placing the current output inside a container spec will render as

resources:
  resources:
    cpu: "1"
    memory: 512Mi

which is invalid.

Suggested fix:

-{{- define "postgresjobs.defaultResources" }}
-resources:
-  cpu: "1"
-  memory: 512Mi
+{{- define "postgresjobs.defaultResources" }}
+requests:
+  cpu: "100m"
+  memory: "512Mi"
+limits:
+  cpu:  "1"
+  memory: "1Gi"
 {{- end }}

This keeps sane defaults and produces a structure the API server accepts.

🤖 Prompt for AI Agents
In packages/apps/postgres/templates/_postgresjobs.tpl lines 4 to 8, the
resources map incorrectly uses raw cpu and memory keys directly under resources,
which is invalid in Kubernetes. To fix this, nest the cpu and memory values
inside a requests sub-map under resources, so the output has resources:
requests: cpu and memory, ensuring it matches the valid Kubernetes resource
specification.

@klinch0
klinch0 force-pushed the (bugfix)--add-resource-quotas-for-pg-jobs branch from a0c1177 to 9c962b2 Compare June 11, 2025 11:57

@lllamnyp Timofei Larkin (lllamnyp) 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

Signed-off-by: kklinch0 <kklinch0@gmail.com>
@klinch0
klinch0 force-pushed the (bugfix)--add-resource-quotas-for-pg-jobs branch from 9c962b2 to 8e79f24 Compare June 11, 2025 19:48
@klinch0
klinch0 merged commit b14c82d into main Jun 12, 2025
@klinch0
klinch0 deleted the (bugfix)--add-resource-quotas-for-pg-jobs branch June 12, 2025 07:10
@github-actions

Copy link
Copy Markdown

Backport failed for release-0.31, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin release-0.31
git worktree add -d .worktree/backport-1051-to-release-0.31 origin/release-0.31
cd .worktree/backport-1051-to-release-0.31
git switch --create backport-1051-to-release-0.31
git cherry-pick -x 8e79f24c5ba40421514cf30203f965250140fcaa

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

Labels

backport Should change be backported on previous release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants