Skip to content

Use library chart for resource management - #1025

Merged
Timofei Larkin (lllamnyp) merged 1 commit into
mainfrom
chore/use-library-chart
Jun 4, 2025
Merged

Use library chart for resource management#1025
Timofei Larkin (lllamnyp) merged 1 commit into
mainfrom
chore/use-library-chart

Conversation

@lllamnyp

@lllamnyp Timofei Larkin (lllamnyp) commented Jun 4, 2025

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features

    • Introduced a shared library for resource configuration management across multiple application charts.
  • Refactor

    • Updated resource configuration handling in several application charts to use new centralized helpers for improved consistency and sanitization.
  • Chores

    • Added references to the shared library in various application chart directories.

@coderabbitai

coderabbitai Bot commented Jun 4, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This change updates multiple Helm chart templates for various applications to use resource management helpers from a centralized "cozy-lib" library. It introduces new chart links to "cozy-lib" and replaces direct YAML serialization and local resource preset logic with calls to "cozy-lib.resources.sanitize" and "cozy-lib.resources.preset" for resource configuration handling.

Changes

Files Change Summary
packages/apps/*/charts/cozy-lib Added new files referencing the shared ../../../library/cozy-lib Helm library.
packages/apps/ferretdb/templates/postgres.yaml
packages/apps/mysql/templates/mariadb.yaml
packages/apps/postgres/templates/db.yaml
packages/apps/rabbitmq/templates/rabbitmq.yaml
packages/apps/redis/templates/redisfailover.yaml
packages/apps/nats/templates/nats.yaml
packages/apps/kafka/templates/kafka.yaml
packages/apps/http-cache/templates/haproxy/deployment.yaml
packages/apps/http-cache/templates/nginx/deployment.yaml
packages/apps/tcp-balancer/templates/deployment.yaml
Updated resource specification logic to use cozy-lib.resources.sanitize and cozy-lib.resources.preset helpers instead of direct YAML serialization or local preset logic.

Sequence Diagram(s)

sequenceDiagram
    participant HelmChart
    participant CozyLib

    HelmChart->>CozyLib: resources.sanitize(resources, context)
    CozyLib-->>HelmChart: Sanitized resource YAML

    HelmChart->>CozyLib: resources.preset(presetType, context)
    CozyLib-->>HelmChart: Preset resource YAML
Loading

Possibly related PRs

  • cozystack/cozystack#935: Introduces the "cozy-lib" Helm library and updates charts to use its resource helper templates, directly related to this PR's changes.

Suggested labels

enhancement, size:M, lgtm

Poem

A cozy new library, neat and compact,
Now helps our charts to better act.
With sanitize and preset in hand,
Resources now follow a unified plan.
From Redis to Rabbit, and Kafka too,
Cozy-lib brings order—thank you!
🐇✨


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.

Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>

@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: 3

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e87994c and b6142cd.

📒 Files selected for processing (19)
  • packages/apps/ferretdb/charts/cozy-lib (1 hunks)
  • packages/apps/ferretdb/templates/postgres.yaml (1 hunks)
  • packages/apps/http-cache/charts/cozy-lib (1 hunks)
  • packages/apps/http-cache/templates/haproxy/deployment.yaml (1 hunks)
  • packages/apps/http-cache/templates/nginx/deployment.yaml (1 hunks)
  • packages/apps/kafka/charts/cozy-lib (1 hunks)
  • packages/apps/kafka/templates/kafka.yaml (2 hunks)
  • packages/apps/mysql/charts/cozy-lib (1 hunks)
  • packages/apps/mysql/templates/mariadb.yaml (1 hunks)
  • packages/apps/nats/charts/cozy-lib (1 hunks)
  • packages/apps/nats/templates/nats.yaml (1 hunks)
  • packages/apps/postgres/charts/cozy-lib (1 hunks)
  • packages/apps/postgres/templates/db.yaml (1 hunks)
  • packages/apps/rabbitmq/charts/cozy-lib (1 hunks)
  • packages/apps/rabbitmq/templates/rabbitmq.yaml (1 hunks)
  • packages/apps/redis/charts/cozy-lib (1 hunks)
  • packages/apps/redis/templates/redisfailover.yaml (1 hunks)
  • packages/apps/tcp-balancer/charts/cozy-lib (1 hunks)
  • packages/apps/tcp-balancer/templates/deployment.yaml (1 hunks)
🧰 Additional context used
🪛 YAMLlint (1.37.1)
packages/apps/kafka/templates/kafka.yaml

[error] 12-12: syntax error: could not find expected ':'

(syntax)

packages/apps/postgres/templates/db.yaml

[error] 9-9: syntax error: could not find expected ':'

(syntax)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Test
🔇 Additional comments (26)
packages/apps/tcp-balancer/charts/cozy-lib (1)

1-1:

Details

❓ Verification inconclusive

Ensure this is a valid Helm subchart symlink
Verify that charts/cozy-lib is committed as a symbolic link targeting the shared library chart and that the relative path (../../../library/cozy-lib) resolves correctly. Run a quick check and lint to confirm:


🏁 Script executed:

cd packages/apps/tcp-balancer/charts
if [ ! -L cozy-lib ]; then
  echo "Error: 'cozy-lib' is not a symlink"; exit 1
fi
target=$(readlink cozy-lib)
if [ ! -d "$target" ]; then
  echo "Error: symlink target '$target' does not exist"; exit 1
fi
helm lint ../

Length of output: 274


Verify Helm Subchart Symlink and Lint

I confirmed that packages/apps/tcp-balancer/charts/cozy-lib is a symlink pointing to ../../../library/cozy-lib. However, I couldn’t run helm lint in this environment (helm: command not found). Please run the following locally and ensure there are no errors:

cd packages/apps/tcp-balancer/charts
helm lint ../
packages/apps/tcp-balancer/templates/deployment.yaml (2)

38-38: Switch to centralized resource sanitization
This replacement with cozy-lib.resources.sanitize properly delegates resource sanitization to the shared library and keeps your chart templates DRY.


40-40: Use library preset helper for default resources
Replacing the local preset include with cozy-lib.resources.preset aligns resource defaulting across charts and removes duplication.

packages/apps/postgres/charts/cozy-lib (1)

1-1: Add symlink for shared library chart
This subchart correctly references the centralized cozy-lib using a relative path, matching the pattern in other applications.

packages/apps/nats/charts/cozy-lib (1)

1-1: Subchart linkage is correct and consistent
This symlink correctly points to the centralized cozy-lib chart (../../../library/cozy-lib), matching the pattern used in other application charts. Helm will include it as a library chart subdirectory.

packages/apps/ferretdb/charts/cozy-lib (1)

1-1:

Details

✅ Verification successful

Verify local chart symlink path
Ensure the symlink ../../../library/cozy-lib resolves correctly from packages/apps/ferretdb/charts/cozy-lib and points to the shared library chart directory (with a valid Chart.yaml file).


🏁 Script executed:

#!/bin/bash
TARGET="packages/apps/ferretdb/charts/cozy-lib"

# Check if it's a symlink
if [ ! -h "$TARGET" ]; then
  echo "ERROR: $TARGET is not a symlink" >&2
  exit 1
fi

# Verify symlink target
RESOLVED=$(readlink "$TARGET")
EXPECTED="../../../library/cozy-lib"
if [ "$RESOLVED" != "$EXPECTED" ]; then
  echo "ERROR: Symlink target is $RESOLVED, expected $EXPECTED" >&2
  exit 1
fi

# Ensure Chart.yaml exists in the resolved path
if [ ! -f "$TARGET/Chart.yaml" ]; then
  echo "ERROR: Chart.yaml not found in $TARGET" >&2
  exit 1
fi

echo "Symlink and Chart.yaml verification passed."

Length of output: 459


Symlink and Chart.yaml verification passed for cozy-lib
The symlink at packages/apps/ferretdb/charts/cozy-lib correctly resolves to ../../../library/cozy-lib and a valid Chart.yaml is present. No further changes are required.

packages/apps/redis/charts/cozy-lib (1)

1-1: Approve library chart symlink addition
The symlink correctly references the shared library/cozy-lib chart, ensuring consistent resource helpers across apps.

packages/apps/http-cache/charts/cozy-lib (1)

1-1: Add cozy-lib chart link for centralized resource helpers

This symlink ties the HTTP Cache chart to the shared library/cozy-lib so you can leverage the common cozy-lib.resources.* templates. It matches the pattern used in other app charts.
Please verify that Git recorded this as a symlink (mode 120000) so Helm will resolve it correctly.

packages/apps/mysql/charts/cozy-lib (1)

1-1:

Details

✅ Verification successful

Verify local symlink and consider using Chart dependencies.

  • Ensure the symlink target ../../../library/cozy-lib resolves to the correct shared library chart directory.
  • Alternatively, declare cozy-lib as a dependency in Chart.yaml and use helm dependency update to pull in the library, avoiding symlink complexity.

🏁 Script executed:

#!/bin/bash
# Verify cozy-lib symlink points to an existing library chart
SYMLINK="packages/apps/mysql/charts/cozy-lib"
if [ ! -L "$SYMLINK" ]; then
  echo "Error: $SYMLINK is not a symlink"
  exit 1
fi
RESOLVED=$(readlink -f "$SYMLINK")
if [ ! -d "$RESOLVED" ]; then
  echo "Error: Target directory $RESOLVED does not exist"
  exit 1
fi
echo "Symlink correctly points to $RESOLVED"

Length of output: 422


Symlink validation completed

The packages/apps/mysql/charts/cozy-lib symlink correctly resolves to /home/jailuser/git/packages/library/cozy-lib, confirming the shared library chart is linked as intended.

• Optional: to simplify chart management, you may declare cozy-lib as a dependency in Chart.yaml and run helm dependency update instead of using a local symlink.

packages/apps/rabbitmq/charts/cozy-lib (1)

1-1:

Details

✅ Verification successful

Ensure this chart alias is a symlink, not a regular file
Helm requires a directory (or symlink) under charts/ containing a valid Chart.yaml for library charts. Confirm that packages/apps/rabbitmq/charts/cozy-lib is implemented as a symlink pointing to ../../../library/cozy-lib and that the target contains its Chart.yaml.

As a remediation, replace the stub with a symlink:

rm packages/apps/rabbitmq/charts/cozy-lib
ln -s ../../../library/cozy-lib packages/apps/rabbitmq/charts/cozy-lib

To verify the chart alias is correctly implemented as a symlink and points to a valid library chart, let’s inspect its file type and target:


🏁 Script executed:

#!/bin/bash
set -e

TARGET="packages/apps/rabbitmq/charts/cozy-lib"

echo "→ Inspecting $TARGET"
if [ ! -e "$TARGET" ]; then
  echo "ERROR: $TARGET does not exist"
  exit 1
fi

ls -ld "$TARGET"

if [ -L "$TARGET" ]; then
  LINK_DEST=$(readlink "$TARGET")
  echo "✔️ Symlink detected, points to: $LINK_DEST"
  # Resolve relative paths
  RESOLVED_DEST=$(realpath -m "$TARGET")
  echo "Resolved target path: $RESOLVED_DEST"
  echo "→ Checking for Chart.yaml in the target directory"
  if [ -f "$RESOLVED_DEST/Chart.yaml" ]; then
    echo "✔️ Found Chart.yaml at $RESOLVED_DEST/Chart.yaml"
  else
    echo "⚠️ Chart.yaml not found in $RESOLVED_DEST"
    exit 1
  fi
else
  echo "❌ Not a symlink (likely a regular directory or file)"
  exit 1
fi

Length of output: 825


To confirm the library chart exists at the symlink target, let’s locate its Chart.yaml:


🏁 Script executed:

#!/bin/bash
set -e

echo "→ Searching for Chart.yaml in any cozy-lib directory under packages/"
find packages -type f -path "*/cozy-lib/Chart.yaml"

Length of output: 246


Verified: cozy-lib chart alias is correctly a symlink with a valid Chart.yaml

The packages/apps/rabbitmq/charts/cozy-lib entry is indeed a symlink pointing to packages/library/cozy-lib, and that target contains a Chart.yaml. No changes are required.

packages/apps/mysql/templates/mariadb.yaml (2)

82-82: Delegate resource sanitization using cozy-lib.resources.sanitize.
Replacing the direct toYaml call with cozy-lib.resources.sanitize correctly centralizes resource handling. Confirm that the 4-space indentation matches the surrounding block.


84-84: Use centralized preset helper.
Swapping out the local preset logic for cozy-lib.resources.preset aligns with the shared library pattern. Make sure .Values.resourcesPreset defaults are documented.

packages/apps/http-cache/templates/nginx/deployment.yaml (2)

56-56: Centralize explicit Nginx resource handling.
Calling cozy-lib.resources.sanitize instead of toYaml standardizes resource rendering and preserves the 10-space indent.


58-58: Use centralized preset for Nginx.
Replacing the local resources.preset include with cozy-lib.resources.preset keeps preset logic consistent across charts.

packages/apps/kafka/templates/kafka.yaml (4)

12-12: Centralize Kafka resource sanitization.
Replacing direct YAML serialization with cozy-lib.resources.sanitize standardizes resource handling; the 6-space indent is preserved.

🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 12-12: syntax error: could not find expected ':'

(syntax)


14-14: Use centralized preset for Kafka.
Switching to cozy-lib.resources.preset ensures DRY preset logic across components.


74-74: Centralize Zookeeper resource sanitization.
Applying cozy-lib.resources.sanitize for Zookeeper keeps behavior consistent with Kafka.


76-76: Use centralized preset for Zookeeper.
Updating to cozy-lib.resources.preset for Zookeeper aligns with the unified resource management approach.

packages/apps/postgres/templates/db.yaml (2)

9-9: Centralize PostgreSQL resource sanitization.
Delegating to cozy-lib.resources.sanitize consolidates resource logic; indentation remains consistent.

🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 9-9: syntax error: could not find expected ':'

(syntax)


11-11: Use centralized preset for PostgreSQL.
Switching to cozy-lib.resources.preset keeps preset handling DRY and maintainable.

packages/apps/rabbitmq/templates/rabbitmq.yaml (2)

15-15: Resource sanitization helper usage validated.
Using cozy-lib.resources.sanitize with list .Values.resources $ and | nindent 4 correctly replaces the previous toYaml approach.


17-17: Resource preset helper usage validated.
The conditional fallback to cozy-lib.resources.preset for non-"none" presets follows the established pattern and preserves indentation.

packages/apps/redis/templates/redisfailover.yaml (2)

29-32: Confirm top-level resources usage for sentinel.
The sentinel resource block references .Values.resources and .Values.resourcesPreset. Verify that the values schema is intended to define these at the top level rather than under a sentinel-specific key.


36-39: Confirm top-level resources usage for Redis container.
Similarly, ensure that the Redis container should inherit the same global resources and resourcesPreset values. If separate configurations are needed, consider scoping them under .Values.redis.

packages/apps/ferretdb/templates/postgres.yaml (1)

22-24: Centralized resource rendering integration is correct.
Replacing direct YAML with cozy-lib.resources.sanitize and cozy-lib.resources.preset aligns this template with the standardized pattern. The conditional logic and | nindent 4 maintain previous indentation.

packages/apps/http-cache/templates/haproxy/deployment.yaml (1)

37-40: Helm resource helpers for HAProxy container are correctly applied.
The includes for cozy-lib.resources.sanitize and cozy-lib.resources.preset use .Values.haproxy.resources and .Values.haproxy.resourcesPreset with | nindent 10, matching the prior toYaml indentation level.

Comment thread packages/apps/kafka/charts/cozy-lib
Comment thread packages/apps/nats/templates/nats.yaml
Comment thread packages/apps/nats/templates/nats.yaml
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