Skip to content

Commit 5105892

Browse files
fix(chart): derive storage-accounting Datadog version from image identity
The storage-accounting CronJob passed `storageAccounting.podLabels` through verbatim, so `tags.datadoghq.com/version` was an operator-maintained identity while the Pod's image and `BUZZ_STORAGE_SNAPSHOT_CODE_SHA` both derived from `image.digest`/`image.tag`. A wrapper that pinned the label independently drifted: Datadog reported one version for a snapshot whose `code_sha` column recorded another. The chart now owns that one key and derives it from `buzz.imageRevision`, the same source as the env var, via a new `buzz.imageVersionLabel` helper that renders a Kubernetes-label-safe form (digests lose the `sha256:` prefix and are bounded to 63 characters). Every other `podLabels` entry — including `tags.datadoghq.com/env` and `tags.datadoghq.com/service`, which describe the deployment rather than the image — still passes through unchanged. What got simpler: one identity instead of two. Wrappers delete their version pin rather than keeping it in sync, and no new value, flag, or abstraction was added to make that possible. Co-Authored-By: Claude Opus 5 <[email protected]> Signed-off-by: tornquist <[email protected]>
1 parent 8f6b66f commit 5105892

8 files changed

Lines changed: 193 additions & 8 deletions

File tree

‎deploy/charts/buzz/Chart.yaml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description: |
77
PostgreSQL and Redis. Configurable for single-node evaluation
88
(subcharts on) and HA production (external services, existingSecret).
99
type: application
10-
version: 0.1.9
10+
version: 0.1.10
1111
appVersion: "0.1.0"
1212
home: https://github.com/block/buzz
1313
sources:
@@ -23,8 +23,8 @@ maintainers:
2323
url: https://github.com/block
2424
annotations:
2525
artifacthub.io/changes: |
26-
- kind: added
27-
description: Optional isolated storage-accounting CronJob with durable relay snapshots.
26+
- kind: changed
27+
description: Storage-accounting Pods derive tags.datadoghq.com/version from the deployed image identity instead of an operator-supplied label.
2828
artifacthub.io/license: Apache-2.0
2929

3030
# Optional eval-only subcharts. Production deploys disable both and point

‎deploy/charts/buzz/README.md‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,45 @@ volumes, and each init container must define an appropriate security context
311311
and resources. Empty `relay.command` and `relay.args` arrays preserve the image
312312
defaults; non-empty values override its entrypoint and arguments respectively.
313313

314+
## Storage accounting worker
315+
316+
`storageAccounting.enabled=true` adds a CronJob that runs
317+
`buzz-admin storage-snapshot` against the relay's S3 bucket and writes a
318+
durable snapshot row, keeping the expensive object walk off the relay Pods.
319+
320+
### Snapshot identity contract
321+
322+
Every snapshot row records the code that produced it in `code_sha`, taken from
323+
the `BUZZ_STORAGE_SNAPSHOT_CODE_SHA` environment variable the chart derives
324+
from the deployed image identity (`image.digest` when set, otherwise
325+
`image.tag`, otherwise `Chart.AppVersion`).
326+
327+
The Pod's Datadog version tag is derived from that **same** image identity, so
328+
the version a snapshot reports to telemetry can never disagree with the version
329+
recorded in the database:
330+
331+
```yaml
332+
storageAccounting:
333+
enabled: true
334+
podLabels:
335+
tags.datadoghq.com/env: production
336+
tags.datadoghq.com/service: buzz-storage-accounting
337+
# tags.datadoghq.com/version: NOT set here — the chart owns it.
338+
```
339+
340+
Precedence is explicit: `tags.datadoghq.com/version` is chart-owned and always
341+
renders from the image identity, so a value supplied under
342+
`storageAccounting.podLabels` for that one key is ignored. Every other label —
343+
including `tags.datadoghq.com/env` and `tags.datadoghq.com/service`, which
344+
describe the deployment rather than the image — passes through unchanged.
345+
Remove any wrapper-maintained `tags.datadoghq.com/version` pin when upgrading;
346+
leaving it in place is harmless but dead.
347+
348+
Because a label value may not contain `:` and is capped at 63 characters, a
349+
digest pin renders as the digest hex without its `sha256:` prefix, truncated to
350+
63 characters — a unique prefix of the full digest that the same Pod reports in
351+
`BUZZ_STORAGE_SNAPSHOT_CODE_SHA`. See `docs/deployment-identity.md`.
352+
314353
## Device pairing relay
315354

316355
The chart can run Buzz's stateless pairing WebSocket relay as an independent

‎deploy/charts/buzz/templates/_helpers.tpl‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,21 @@ app.kubernetes.io/component: relay
6969
{{- end -}}
7070
{{- end -}}
7171

72+
{{/*
73+
Kubernetes-label-safe rendering of "buzz.imageRevision", used for Datadog
74+
unified-service-tagging's version tag on chart-managed Pods.
75+
76+
The revision is either an image tag or a "sha256:<64 hex>" digest. A label
77+
value may not contain ":" and is capped at 63 characters, so the digest
78+
algorithm prefix is stripped and the result bounded. The label is therefore a
79+
prefix-comparable form of the exact revision the same Pod reports in
80+
BUZZ_STORAGE_SNAPSHOT_CODE_SHA — one identity, derived twice, never a second
81+
value an operator has to keep in sync.
82+
*/}}
83+
{{- define "buzz.imageVersionLabel" -}}
84+
{{- include "buzz.imageRevision" . | trimPrefix "sha256:" | trunc 63 | trimSuffix "-" | trimSuffix "." | trimSuffix "_" -}}
85+
{{- end -}}
86+
7287
{{/*
7388
Name of the chart-managed Secret holding relay-identity material and any
7489
chart-composed connection strings.

‎deploy/charts/buzz/templates/storage-accounting-cronjob.yaml‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ spec:
2020
labels:
2121
{{- include "buzz.selectorLabels" . | nindent 12 }}
2222
app.kubernetes.io/component: storage-accounting
23-
{{- with .Values.storageAccounting.podLabels }}
24-
{{- toYaml . | nindent 12 }}
25-
{{- end }}
23+
{{- /* The Datadog version tag names the binary that wrote the
24+
snapshot rows, so the chart derives it from the same image
25+
identity as BUZZ_STORAGE_SNAPSHOT_CODE_SHA below rather than
26+
letting an operator pin a second value that silently drifts.
27+
Chart-owned key wins; every other podLabels entry (env,
28+
service, operator labels) passes through untouched. */}}
29+
{{- $labels := merge (dict "tags.datadoghq.com/version" (include "buzz.imageVersionLabel" .)) .Values.storageAccounting.podLabels }}
30+
{{- toYaml $labels | nindent 12 }}
2631
annotations:
2732
{{- toYaml .Values.storageAccounting.podAnnotations | nindent 12 }}
2833
spec:

‎deploy/charts/buzz/tests/storage_accounting_test.yaml‎

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ tests:
4444
podLabels:
4545
tags.datadoghq.com/env: production
4646
tags.datadoghq.com/service: buzz-storage-accounting
47+
# Stale operator pin: the chart owns this key and overrides it.
4748
tags.datadoghq.com/version: test-sha
4849
asserts:
4950
- hasDocuments:
@@ -89,9 +90,11 @@ tests:
8990
path: spec.jobTemplate.spec.template.metadata.labels["tags.datadoghq.com/env"]
9091
value: production
9192
template: templates/storage-accounting-cronjob.yaml
93+
# Image identity wins over the operator-supplied pin; default image.tag
94+
# falls back to Chart.AppVersion, the same value as the env var below.
9295
- equal:
9396
path: spec.jobTemplate.spec.template.metadata.labels["tags.datadoghq.com/version"]
94-
value: test-sha
97+
value: 0.1.0
9598
template: templates/storage-accounting-cronjob.yaml
9699
- equal:
97100
path: spec.jobTemplate.spec.template.spec.containers[0].args
@@ -143,3 +146,102 @@ tests:
143146
content:
144147
name: BUZZ_GIT_HOOK_HMAC_SECRET
145148
template: templates/storage-accounting-cronjob.yaml
149+
# ── Datadog version tag is chart-owned, derived from image identity ────────
150+
# Regression: a wrapper chart pinned tags.datadoghq.com/version independently
151+
# of image.tag/image.digest, so the storage-accounting Pod reported one
152+
# version to Datadog while BUZZ_STORAGE_SNAPSHOT_CODE_SHA recorded another.
153+
- it: overrides a stale operator-pinned Datadog version label with the image tag
154+
set:
155+
relayUrl: wss://buzz.example.com
156+
ownerPubkey: "0000000000000000000000000000000000000000000000000000000000000000"
157+
externalPostgresql.url: postgres://u:p@h:5432/d
158+
externalRedis.url: redis://h:6379
159+
s3.endpoint: https://s3.example.com
160+
s3.accessKey: test
161+
s3.secretKey: test
162+
image.tag: 1.2.3-rc.4
163+
storageAccounting:
164+
enabled: true
165+
podLabels:
166+
tags.datadoghq.com/env: staging
167+
tags.datadoghq.com/service: buzz-storage-accounting
168+
tags.datadoghq.com/version: stale-operator-sha
169+
team: platform
170+
asserts:
171+
- equal:
172+
path: spec.jobTemplate.spec.template.metadata.labels["tags.datadoghq.com/version"]
173+
value: 1.2.3-rc.4
174+
template: templates/storage-accounting-cronjob.yaml
175+
# The telemetry tag and the recorded snapshot identity cannot disagree.
176+
- contains:
177+
path: spec.jobTemplate.spec.template.spec.containers[0].env
178+
content:
179+
name: BUZZ_STORAGE_SNAPSHOT_CODE_SHA
180+
value: 1.2.3-rc.4
181+
template: templates/storage-accounting-cronjob.yaml
182+
# Every other operator label still passes through.
183+
- equal:
184+
path: spec.jobTemplate.spec.template.metadata.labels["tags.datadoghq.com/env"]
185+
value: staging
186+
template: templates/storage-accounting-cronjob.yaml
187+
- equal:
188+
path: spec.jobTemplate.spec.template.metadata.labels["tags.datadoghq.com/service"]
189+
value: buzz-storage-accounting
190+
template: templates/storage-accounting-cronjob.yaml
191+
- equal:
192+
path: spec.jobTemplate.spec.template.metadata.labels["team"]
193+
value: platform
194+
template: templates/storage-accounting-cronjob.yaml
195+
- equal:
196+
path: spec.jobTemplate.spec.template.metadata.labels["app.kubernetes.io/component"]
197+
value: storage-accounting
198+
template: templates/storage-accounting-cronjob.yaml
199+
- it: stamps the version label with no operator podLabels at all
200+
set:
201+
relayUrl: wss://buzz.example.com
202+
ownerPubkey: "0000000000000000000000000000000000000000000000000000000000000000"
203+
externalPostgresql.url: postgres://u:p@h:5432/d
204+
externalRedis.url: redis://h:6379
205+
s3.endpoint: https://s3.example.com
206+
s3.accessKey: test
207+
s3.secretKey: test
208+
image.tag: 2.0.0
209+
storageAccounting:
210+
enabled: true
211+
asserts:
212+
- equal:
213+
path: spec.jobTemplate.spec.template.metadata.labels["tags.datadoghq.com/version"]
214+
value: 2.0.0
215+
template: templates/storage-accounting-cronjob.yaml
216+
- it: renders a label-safe version from a pinned image digest
217+
set:
218+
relayUrl: wss://buzz.example.com
219+
ownerPubkey: "0000000000000000000000000000000000000000000000000000000000000000"
220+
externalPostgresql.url: postgres://u:p@h:5432/d
221+
externalRedis.url: redis://h:6379
222+
s3.endpoint: https://s3.example.com
223+
s3.accessKey: test
224+
s3.secretKey: test
225+
image.tag: ignored-when-digest-set
226+
image.digest: sha256:1111111111111111111111111111111111111111111111111111111111111111
227+
storageAccounting:
228+
enabled: true
229+
podLabels:
230+
tags.datadoghq.com/version: stale-operator-sha
231+
asserts:
232+
# 63 chars, no "sha256:" prefix — a label value the API server accepts,
233+
# still a unique prefix of the digest recorded in the env var below.
234+
- equal:
235+
path: spec.jobTemplate.spec.template.metadata.labels["tags.datadoghq.com/version"]
236+
value: "111111111111111111111111111111111111111111111111111111111111111"
237+
template: templates/storage-accounting-cronjob.yaml
238+
- matchRegex:
239+
path: spec.jobTemplate.spec.template.metadata.labels["tags.datadoghq.com/version"]
240+
pattern: ^[a-z0-9A-Z]([-_.a-zA-Z0-9]{0,61}[a-zA-Z0-9])?$
241+
template: templates/storage-accounting-cronjob.yaml
242+
- contains:
243+
path: spec.jobTemplate.spec.template.spec.containers[0].env
244+
content:
245+
name: BUZZ_STORAGE_SNAPSHOT_CODE_SHA
246+
value: sha256:1111111111111111111111111111111111111111111111111111111111111111
247+
template: templates/storage-accounting-cronjob.yaml

‎deploy/charts/buzz/values.schema.json‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,10 @@
229229
"failedJobsHistoryLimit": { "type": "integer", "minimum": 0 },
230230
"relayMode": { "type": "string", "enum": ["inline", "external", "off"] },
231231
"serviceAccountName": { "type": "string" },
232-
"podLabels": { "type": "object" },
232+
"podLabels": {
233+
"type": "object",
234+
"description": "Extra Pod labels. The chart owns tags.datadoghq.com/version and derives it from the deployed image identity, so a value supplied here for that one key is ignored."
235+
},
233236
"podAnnotations": { "type": "object" },
234237
"resources": { "type": "object" }
235238
}

‎deploy/charts/buzz/values.yaml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,11 @@ storageAccounting:
380380
failedJobsHistoryLimit: 3
381381
relayMode: external # external | off; inline is a legacy alias
382382
serviceAccountName: "" # defaults to the main Buzz service account
383+
# Extra Pod labels, e.g. Datadog unified service tagging. The chart owns
384+
# `tags.datadoghq.com/version` and derives it from image.digest/image.tag so
385+
# the telemetry version always names the binary that wrote the snapshot rows
386+
# (the same identity as BUZZ_STORAGE_SNAPSHOT_CODE_SHA). A value supplied
387+
# here for that one key is ignored; every other key passes through.
383388
podLabels: {}
384389
podAnnotations:
385390
sidecar.istio.io/inject: "false"

‎docs/deployment-identity.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,19 @@ image:
6666
6767
When `image.digest` is set, the chart renders `repository@digest` and ignores
6868
`image.tag`. Existing tag-only values remain backwards compatible.
69+
70+
## Derived deployment labels
71+
72+
The storage-accounting CronJob has no runtime `/_status` surface to interrogate,
73+
so the chart stamps its Pods with the deployed image identity instead of asking
74+
an operator to restate it. `BUZZ_STORAGE_SNAPSHOT_CODE_SHA` (persisted as
75+
`code_sha` on every snapshot row) and the Pod's `tags.datadoghq.com/version`
76+
label are both derived from `image.digest` — or `image.tag`, or
77+
`Chart.AppVersion` — so a snapshot's telemetry version and its recorded version
78+
cannot drift apart.
79+
80+
Kubernetes label values may not contain `:` and are capped at 63 characters, so
81+
the label carries the digest hex without its `sha256:` prefix, truncated to 63
82+
characters. The environment variable keeps the exact revision. Any
83+
`tags.datadoghq.com/version` supplied through `storageAccounting.podLabels` is
84+
ignored; see the chart README's "Storage accounting worker" section.

0 commit comments

Comments
 (0)