Skip to content

fix(chart): allow metadata and additional labels#103

Open
Leundai wants to merge 1 commit intosourcebot-dev:mainfrom
Leundai:codex/allow-global-metadata-additional-labels
Open

fix(chart): allow metadata and additional labels#103
Leundai wants to merge 1 commit intosourcebot-dev:mainfrom
Leundai:codex/allow-global-metadata-additional-labels

Conversation

@Leundai
Copy link
Copy Markdown

@Leundai Leundai commented Apr 28, 2026

Summary

  • Allow global.metadata in the chart values schema.
  • Add root-level additionalLabels to the values schema and documented defaults.
  • Keep label handling compatible with the existing sourcebot.additionalLabels value while also supporting the root-level value that the chart helper already reads.

Why

The chart currently has a strict values schema. That is helpful for catching mistakes, but it also rejects common Helm usage where deployment tooling passes shared metadata through global.metadata.

There is also a mismatch around additionalLabels: values.yaml and the schema expose it under sourcebot.additionalLabels, but the shared label helper reads from root-level additionalLabels. That means the documented value can validate without affecting rendered labels, while the value the templates actually read is rejected by schema validation.

This change keeps the schema strict for known fields while allowing these two intended extension points.

Validation

  • helm dependency update charts/sourcebot/
  • helm lint charts/sourcebot/ -f charts/sourcebot/values.lint.yaml
  • helm unittest charts/sourcebot/ --color
  • /private/tmp/helm-docs charts/sourcebot/
  • helm template test charts/sourcebot/ -f charts/sourcebot/values.lint.yaml --set global.metadata.owner=platform --set additionalLabels.component=sourcebot
  • helm template test charts/sourcebot/ -f charts/sourcebot/values.lint.yaml --set sourcebot.additionalLabels.component=sourcebot

Summary by CodeRabbit

  • New Features

    • Added support for configuring additional labels on Helm chart resources via additionalLabels
    • Added support for deployment tooling metadata configuration via global.metadata
  • Documentation

    • Updated configuration documentation with new label and metadata options
  • Tests

    • Added test coverage for label configuration scenarios

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 28, 2026

Walkthrough

The Helm chart for sourcebot is updated to support additional labels and global metadata configuration. Two new value paths are introduced (additionalLabels and global.metadata), the label helper is updated to merge labels from multiple sources, and corresponding schema validation and test coverage are added.

Changes

Cohort / File(s) Summary
Documentation & Schema
charts/sourcebot/README.md, charts/sourcebot/values.schema.json
Documentation entries added for additionalLabels and global.metadata configuration options; schema updated to accept both as optional top-level object fields.
Configuration Values
charts/sourcebot/values.yaml
Two new optional value keys introduced: global.metadata and additionalLabels, both defaulting to empty objects, with example documentation for additionalLabels.team.
Implementation & Tests
charts/sourcebot/templates/_helpers.tpl, charts/sourcebot/tests/basic_test.yaml
Label helper updated to merge labels from both sourcebot.additionalLabels and additionalLabels paths using mergeOverwrite; two new test cases verify label merging behavior with different configuration sources.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(chart): allow metadata and additional labels' directly describes the main changes: permitting global.metadata and adding additionalLabels support to the Helm chart schema and values.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@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

🧹 Nitpick comments (1)
charts/sourcebot/tests/basic_test.yaml (1)

70-90: Add a collision case to lock label precedence.

These two tests only prove each source works in isolation. Please add a case where additionalLabels.component and sourcebot.additionalLabels.component are both set to different values so regressions in the merge order are caught.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@charts/sourcebot/tests/basic_test.yaml` around lines 70 - 90, Add a new test
case in the same file that sets both additionalLabels.component and
sourcebot.additionalLabels.component to different values to verify merge
precedence; specifically create an "it" entry (e.g., "should prefer
sourcebot.additionalLabels over root additionalLabels") that uses values
../values.lint.yaml, sets additionalLabels.component: rootVal and
sourcebot.additionalLabels.component: sourceVal, and asserts the final value at
metadata.labels.component in template deployment.yaml equals the expected winner
(state which should win in your chart, e.g., sourceVal) so any regression in
merge order is caught.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@charts/sourcebot/templates/_helpers.tpl`:
- Around line 43-46: The helper uses mergeOverwrite with arguments in the order
(dict) (default dict $.Values.sourcebot.additionalLabels) (default dict
$.Values.additionalLabels) so top-level $.Values.additionalLabels currently wins
on key collisions; either reverse the merge order so
$.Values.sourcebot.additionalLabels takes precedence (call mergeOverwrite with
$.Values.additionalLabels first then $.Values.sourcebot.additionalLabels) or add
explicit documentation in the helpers/template and chart README describing that
top-level additionalLabels override sourcebot.additionalLabels, and add a unit
test exercising key collisions between $.Values.sourcebot.additionalLabels and
$.Values.additionalLabels to lock the intended behavior; update references to
mergeOverwrite, $additionalLabels, $.Values.sourcebot.additionalLabels, and
$.Values.additionalLabels accordingly.

In `@charts/sourcebot/values.schema.json`:
- Around line 34-36: The schema entry for additionalLabels currently allows any
value type; update the additionalLabels definition to require string values by
changing it from a bare "type":"object" to an object schema that sets
additionalProperties (or patternProperties) to {"type":"string"} and optionally
add propertyNames pattern validation to match Kubernetes label key rules; target
the additionalLabels schema in values.schema.json (used by the sourcebot.labels
helper in _helpers.tpl) so any label value merged via sourcebot.labels is
guaranteed to be a string.

---

Nitpick comments:
In `@charts/sourcebot/tests/basic_test.yaml`:
- Around line 70-90: Add a new test case in the same file that sets both
additionalLabels.component and sourcebot.additionalLabels.component to different
values to verify merge precedence; specifically create an "it" entry (e.g.,
"should prefer sourcebot.additionalLabels over root additionalLabels") that uses
values ../values.lint.yaml, sets additionalLabels.component: rootVal and
sourcebot.additionalLabels.component: sourceVal, and asserts the final value at
metadata.labels.component in template deployment.yaml equals the expected winner
(state which should win in your chart, e.g., sourceVal) so any regression in
merge order is caught.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7d2ff650-9009-45f1-ba9f-343019f3cd17

📥 Commits

Reviewing files that changed from the base of the PR and between 5fcd99d and 520056e.

📒 Files selected for processing (5)
  • charts/sourcebot/README.md
  • charts/sourcebot/templates/_helpers.tpl
  • charts/sourcebot/tests/basic_test.yaml
  • charts/sourcebot/values.schema.json
  • charts/sourcebot/values.yaml

Comment on lines +43 to 46
{{- $additionalLabels := mergeOverwrite (dict) (default dict $.Values.sourcebot.additionalLabels) (default dict $.Values.additionalLabels) }}
{{- with $additionalLabels }}
{{ toYaml . }}
{{- end }}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
sed -n '36,46p' charts/sourcebot/templates/_helpers.tpl
sed -n '70,90p' charts/sourcebot/tests/basic_test.yaml

Repository: sourcebot-dev/sourcebot-helm-chart

Length of output: 1112


🌐 Web query:

Helm Sprig mergeOverwrite precedence order which map wins

💡 Result:

mergeOverwrite precedence (which map wins) In Helm templates, mergeOverwrite has argument precedence from right to left: later maps (to the right) overwrite earlier maps (to the left). So for: {{- $out := mergeOverwrite $dst $src1 $src2 -}} - For any conflicting key, $src2 wins. - If a key exists in $src2 and $src1, $src2’s value is used. - If a key does not exist in $src2 but exists in $src1, $src1’s value is used. - If a key exists only in $dst, $dst’s value remains. Example from Helm docs (key collisions): - dest: { default: "default", src: overwritten?, key: true } - src1: { key: false, name: value2 } - src2: { overwrite: overwritten, key: false, name: value1? } Helm’s documented result shows the overwriting effect: the merged value uses right-to-left precedence (e.g., default stays "default", key becomes the value from the rightmost map, and overwrite comes from the rightmost map). Note: mergeOverwrite performs a deep merge (nested maps are merged recursively), but it is not a deep copy; merged nested objects share references. Practical rule of thumb - Use mergeOverwrite $base $overrides1 $overrides2 when you want $overrides2 to win over $overrides1 and $base.

Citations:


🏁 Script executed:

#!/bin/bash
# Search for collision test cases in test files
find charts -name "*test*.yaml" -o -name "*test*.yml" | xargs grep -l "additionalLabels" 2>/dev/null | head -5

Repository: sourcebot-dev/sourcebot-helm-chart

Length of output: 117


🏁 Script executed:

#!/bin/bash
# Check full test file to see all label-related tests
cat charts/sourcebot/tests/basic_test.yaml | grep -A 15 "it.*label"

Repository: sourcebot-dev/sourcebot-helm-chart

Length of output: 1279


🏁 Script executed:

#!/bin/bash
# Check for comments or documentation around the merge logic
cat charts/sourcebot/templates/_helpers.tpl | head -60

Repository: sourcebot-dev/sourcebot-helm-chart

Length of output: 1874


🏁 Script executed:

#!/bin/bash
# Search for any documentation or comments about additionalLabels precedence
rg -i "additionalLabels|merge.*order|precedence" charts/ README* CHANGELOG* --type yaml --type md -B 2 -A 2 2>/dev/null | head -50

Repository: sourcebot-dev/sourcebot-helm-chart

Length of output: 2428


🏁 Script executed:

#!/bin/bash
# Check if there are any other test files that might test collision scenarios
find charts -name "*.yaml" -o -name "*.yml" | xargs grep -l "sourcebot.additionalLabels.*additionalLabels\|additionalLabels.*sourcebot.additionalLabels" 2>/dev/null

Repository: sourcebot-dev/sourcebot-helm-chart

Length of output: 62


Verify the merge order for overlapping label keys.

The merge order is confirmed: mergeOverwrite applies arguments left-to-right, so additionalLabels (top-level) wins over sourcebot.additionalLabels on key collisions. However, the documentation describes both paths identically ("Add extra labels to all resources"), implying they should be treated equally. This precedence is undocumented in the code, and there is no test case covering key collisions between the two paths. If the sourcebot.* path should remain authoritative (as a chart-specific override), the merge order should be reversed, or the design intent should be explicitly documented.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@charts/sourcebot/templates/_helpers.tpl` around lines 43 - 46, The helper
uses mergeOverwrite with arguments in the order (dict) (default dict
$.Values.sourcebot.additionalLabels) (default dict $.Values.additionalLabels) so
top-level $.Values.additionalLabels currently wins on key collisions; either
reverse the merge order so $.Values.sourcebot.additionalLabels takes precedence
(call mergeOverwrite with $.Values.additionalLabels first then
$.Values.sourcebot.additionalLabels) or add explicit documentation in the
helpers/template and chart README describing that top-level additionalLabels
override sourcebot.additionalLabels, and add a unit test exercising key
collisions between $.Values.sourcebot.additionalLabels and
$.Values.additionalLabels to lock the intended behavior; update references to
mergeOverwrite, $additionalLabels, $.Values.sourcebot.additionalLabels, and
$.Values.additionalLabels accordingly.

Comment on lines +34 to +36
"additionalLabels": {
"type": "object"
},
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
sed -n '1,80p' charts/sourcebot/values.schema.json
rg -n -C 3 'additionalLabels|metadata.labels|toYaml' charts/sourcebot/templates charts/sourcebot/values.yaml

Repository: sourcebot-dev/sourcebot-helm-chart

Length of output: 13267


Constrain additionalLabels to string values.

The schema for this new top-level object lacks property type validation. Since it's merged into Kubernetes labels via the sourcebot.labels helper (visible in _helpers.tpl line 43), it could pass schema validation with non-string values that would render invalid Kubernetes labels.

Proposed schema tightening
-    "additionalLabels": {
-      "type": "object"
-    },
+    "additionalLabels": {
+      "type": "object",
+      "additionalProperties": { "type": "string" }
+    },
📝 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
"additionalLabels": {
"type": "object"
},
"additionalLabels": {
"type": "object",
"additionalProperties": { "type": "string" }
},
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@charts/sourcebot/values.schema.json` around lines 34 - 36, The schema entry
for additionalLabels currently allows any value type; update the
additionalLabels definition to require string values by changing it from a bare
"type":"object" to an object schema that sets additionalProperties (or
patternProperties) to {"type":"string"} and optionally add propertyNames pattern
validation to match Kubernetes label key rules; target the additionalLabels
schema in values.schema.json (used by the sourcebot.labels helper in
_helpers.tpl) so any label value merged via sourcebot.labels is guaranteed to be
a string.

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.

1 participant