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: 1 addition & 1 deletion braintrust/templates/virtualservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ kind: VirtualService
metadata:
name: {{ .Values.virtualService.name | default (printf "%s-vs" .Values.api.name) }}
namespace: {{ include "braintrust.namespace" . }}
{{- with (merge .Values.global.labels .Values.virtualService.labels) }}
{{- with (merge (deepCopy (.Values.virtualService.labels | default dict)) .Values.global.labels) }}
labels:
{{- toYaml . | nindent 4 }}
{{- end }}
Expand Down
75 changes: 75 additions & 0 deletions braintrust/tests/labels-merge-isolation_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ templates:
- brainstore-automationwriter-configmap.yaml
- loop-runtime-deployment.yaml
- loop-runtime-configmap.yaml
- virtualservice.yaml
tests:
# This test verifies that labels are isolated between components.
# The bug that was fixed: Helm's merge function mutates the leftmost dict,
Expand Down Expand Up @@ -539,3 +540,77 @@ tests:
pod-specific: pod-only
app: braintrust-loop-runtime
gke-workload-identity/use: "true"

# virtualservice.yaml renders before most other templates (Helm renders
# top-level templates in reverse lexical order), so a merge that mutates
# global.labels there leaks VirtualService labels onto every later resource.
- it: should not leak VirtualService labels onto other components
values:
- __fixtures__/base-values.yaml
set:
virtualService.enabled: true
global.labels.shared: "global-value"
virtualService.labels.vs-specific: "vs-only"
release:
namespace: "braintrust"
template: api-deployment.yaml
asserts:
- equal:
path: metadata.labels.shared
value: global-value
- isNull:
path: metadata.labels["vs-specific"]
- isNull:
path: spec.template.metadata.labels["vs-specific"]

- it: should not leak VirtualService labels onto Brainstore components
values:
- __fixtures__/base-values.yaml
set:
virtualService.enabled: true
global.labels.shared: "global-value"
virtualService.labels.vs-specific: "vs-only"
release:
namespace: "braintrust"
template: brainstore-reader-deployment.yaml
asserts:
- equal:
path: metadata.labels.shared
value: global-value
- isNull:
path: metadata.labels["vs-specific"]

- it: should give VirtualService labels precedence over global labels when keys conflict
values:
- __fixtures__/base-values.yaml
set:
virtualService.enabled: true
global.labels.tier: "global-tier"
global.labels.shared: "global-value"
virtualService.labels.tier: "vs-tier"
release:
namespace: "braintrust"
template: virtualservice.yaml
asserts:
- equal:
path: metadata.labels.tier
value: vs-tier
- equal:
path: metadata.labels.shared
value: global-value

- it: should render VirtualService labels when virtualService.labels is null
values:
- __fixtures__/base-values.yaml
set:
virtualService.enabled: true
virtualService.labels: null
global.labels.shared: "global-value"
release:
namespace: "braintrust"
template: virtualservice.yaml
asserts:
- equal:
path: metadata.labels
value:
shared: global-value
Loading