Use library chart for resource management - #1025
Conversation
WalkthroughThis 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
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
Possibly related PRs
Suggested labels
Poem
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>
a5cf2a5 to
b6142cd
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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 thatcharts/cozy-libis 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-libis a symlink pointing to../../../library/cozy-lib. However, I couldn’t runhelm lintin 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 withcozy-lib.resources.sanitizeproperly 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 withcozy-lib.resources.presetaligns 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 centralizedcozy-libusing 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 centralizedcozy-libchart (../../../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-libresolves correctly frompackages/apps/ferretdb/charts/cozy-liband points to the shared library chart directory (with a validChart.yamlfile).
🏁 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 atpackages/apps/ferretdb/charts/cozy-libcorrectly resolves to../../../library/cozy-liband a validChart.yamlis 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 sharedlibrary/cozy-libchart, ensuring consistent resource helpers across apps.packages/apps/http-cache/charts/cozy-lib (1)
1-1: Add cozy-lib chart link for centralized resource helpersThis symlink ties the HTTP Cache chart to the shared
library/cozy-libso you can leverage the commoncozy-lib.resources.*templates. It matches the pattern used in other app charts.
Please verify that Git recorded this as a symlink (mode120000) 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-libresolves to the correct shared library chart directory.- Alternatively, declare
cozy-libas a dependency inChart.yamland usehelm dependency updateto 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-libsymlink 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-libas a dependency inChart.yamland runhelm dependency updateinstead 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) undercharts/containing a validChart.yamlfor library charts. Confirm thatpackages/apps/rabbitmq/charts/cozy-libis implemented as a symlink pointing to../../../library/cozy-liband that the target contains itsChart.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 fiLength 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-libchart alias is correctly a symlink with a valid Chart.yamlThe
packages/apps/rabbitmq/charts/cozy-libentry is indeed a symlink pointing topackages/library/cozy-lib, and that target contains aChart.yaml. No changes are required.packages/apps/mysql/templates/mariadb.yaml (2)
82-82: Delegate resource sanitization usingcozy-lib.resources.sanitize.
Replacing the directtoYamlcall withcozy-lib.resources.sanitizecorrectly 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 forcozy-lib.resources.presetaligns with the shared library pattern. Make sure.Values.resourcesPresetdefaults are documented.packages/apps/http-cache/templates/nginx/deployment.yaml (2)
56-56: Centralize explicit Nginx resource handling.
Callingcozy-lib.resources.sanitizeinstead oftoYamlstandardizes resource rendering and preserves the 10-space indent.
58-58: Use centralized preset for Nginx.
Replacing the localresources.presetinclude withcozy-lib.resources.presetkeeps preset logic consistent across charts.packages/apps/kafka/templates/kafka.yaml (4)
12-12: Centralize Kafka resource sanitization.
Replacing direct YAML serialization withcozy-lib.resources.sanitizestandardizes 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 tocozy-lib.resources.presetensures DRY preset logic across components.
74-74: Centralize Zookeeper resource sanitization.
Applyingcozy-lib.resources.sanitizefor Zookeeper keeps behavior consistent with Kafka.
76-76: Use centralized preset for Zookeeper.
Updating tocozy-lib.resources.presetfor Zookeeper aligns with the unified resource management approach.packages/apps/postgres/templates/db.yaml (2)
9-9: Centralize PostgreSQL resource sanitization.
Delegating tocozy-lib.resources.sanitizeconsolidates 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 tocozy-lib.resources.presetkeeps preset handling DRY and maintainable.packages/apps/rabbitmq/templates/rabbitmq.yaml (2)
15-15: Resource sanitization helper usage validated.
Usingcozy-lib.resources.sanitizewithlist .Values.resources $and| nindent 4correctly replaces the previoustoYamlapproach.
17-17: Resource preset helper usage validated.
The conditional fallback tocozy-lib.resources.presetfor 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.resourcesand.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 globalresourcesandresourcesPresetvalues. 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 withcozy-lib.resources.sanitizeandcozy-lib.resources.presetaligns this template with the standardized pattern. The conditional logic and| nindent 4maintain previous indentation.packages/apps/http-cache/templates/haproxy/deployment.yaml (1)
37-40: Helm resource helpers for HAProxy container are correctly applied.
The includes forcozy-lib.resources.sanitizeandcozy-lib.resources.presetuse.Values.haproxy.resourcesand.Values.haproxy.resourcesPresetwith| nindent 10, matching the priortoYamlindentation level.
Summary by CodeRabbit
New Features
Refactor
Chores