Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions charts/sourcebot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ Sourcebot is a self-hosted tool that helps you understand your codebase.

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| additionalLabels | object | `{}` | Add extra labels to all resources |
| fullnameOverride | string | `""` | Override the full name of the deployed resources, defaults to a combination of the release name and the name for the selector labels |
| global.imagePullSecrets | list | `[]` | Global Docker registry secret names as an array |
| global.metadata | object | `{}` | Global metadata for deployment tooling |
| global.security.allowInsecureImages | bool | `true` | Allow insecure images to use bitnami legacy repository. Can be set to false if secure images are being used (Paid). |
| nameOverride | string | `""` | Override the name for the selector labels, defaults to the chart name |
| postgresql.auth.args | string | `""` | Additional database connection arguments |
Expand Down
3 changes: 2 additions & 1 deletion charts/sourcebot/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ helm.sh/chart: {{ include "sourcebot.chart" $ }}
app.kubernetes.io/version: {{ $.Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ $.Release.Service }}
{{- with $.Values.additionalLabels }}
{{- $additionalLabels := mergeOverwrite (dict) (default dict $.Values.sourcebot.additionalLabels) (default dict $.Values.additionalLabels) }}
{{- with $additionalLabels }}
{{ toYaml . }}
{{- end }}
Comment on lines +43 to 46
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.

{{- end }}
Expand Down
23 changes: 22 additions & 1 deletion charts/sourcebot/tests/basic_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,28 @@ tests:
value: Helm
template: deployment.yaml

- it: should include root additional labels
values:
- ../values.lint.yaml
set:
additionalLabels.component: sourcebot
asserts:
- equal:
path: metadata.labels.component
value: sourcebot
template: deployment.yaml

- it: should include sourcebot additional labels
values:
- ../values.lint.yaml
set:
sourcebot.additionalLabels.component: sourcebot
asserts:
- equal:
path: metadata.labels.component
value: sourcebot
template: deployment.yaml

- it: should use correct image when tag is specified
values:
- ../values.lint.yaml
Expand Down Expand Up @@ -183,4 +205,3 @@ tests:
- isNotEmpty:
path: data["config.json"]
template: config.yaml

6 changes: 6 additions & 0 deletions charts/sourcebot/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"imagePullSecrets": {
"type": "array",
"items": { "type": "string" }
},
"metadata": {
"type": "object"
}
}
},
Expand All @@ -28,6 +31,9 @@
"fullnameOverride": {
"type": "string"
},
"additionalLabels": {
"type": "object"
},
Comment on lines +34 to +36
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.

"sourcebot": {
"type": "object",
"additionalProperties": false,
Expand Down
7 changes: 7 additions & 0 deletions charts/sourcebot/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ global:
# -- Global Docker registry secret names as an array
imagePullSecrets: []

# -- Global metadata for deployment tooling
metadata: {}

# -- Override the name for the selector labels, defaults to the chart name
nameOverride: ""

# -- Override the full name of the deployed resources, defaults to a combination of the release name and the name for the selector labels
fullnameOverride: ""

# -- Add extra labels to all resources
additionalLabels: {}
# team: sourcebot

# Core Sourcebot Configuration
sourcebot:
# -- Set the number of replicas for the deployment
Expand Down