Skip to content

Commit 930fd29

Browse files
TheSentinel454Elrondclaude
authored
deploy: run buzz-acceptance from the relay image as a chart CronJob (#9771)
## Summary Builds on #9767 (the `buzz-acceptance` binary, now merged). Based on main. - **Image:** the relay image now carries `buzz-acceptance` next to `buzz-admin` and `buzz-pair-relay`, so no new image or workflow is needed. - **Chart:** `acceptance.enabled=true` adds a CronJob that runs the probe from the relay image. - Requires `image.tag` or `image.digest`. The chart fails to render without one, because the default `Chart.AppVersion` image has no probe. - Every 5 minutes by default, `concurrencyPolicy: Forbid`, `backoffLimit: 0` (a retry would hide a failure), `activeDeadlineSeconds: 240`. - Runs with `acceptance.serviceAccountName` or the namespace default, never the relay's service account. No token mount, no service links. - `acceptance.relayUrl` (defaults to `relayUrl`), `acceptance.stageTimeoutSeconds`. - `acceptance.privateKeySecret.name` is required. Without a key the probe would sign with a new key each run: a members-only relay refuses it, and an open relay joins each new key to every auto-join channel. - `acceptance.statsdAddr` sends DogStatsD metrics. `$(HOST_IP)` expands to the node IP, for a node-local agent. - Every series carries `probe_revision`, the probe's own image (`image.digest`, else `image.tag`), plus `acceptance.tags`. It does not identify the relay build a run reached: during a rollout, or with `acceptance.relayUrl` set, the probe can reach another build. `acceptance.tags` keys must be canonical (lowercase `[a-z0-9_./-]`, starting with a letter, not ending in `_`), so the probe-owned and repeated-key checks see the key Datadog stores. - NIP-FI: minting an assertion is deployment-specific, so the chart takes it as a file. `acceptance.extraInitContainers`, `extraVolumes` and `extraVolumeMounts` let an init container write it, and `acceptance.assertionFile` points the probe at it. These follow the existing relay Pod extension points. - **README:** a new "Acceptance probe" section with an example. The example gives the minter init container the key Secret, keeps credentials in a memory `emptyDir`, and says how to size `activeDeadlineSeconds` against `stageTimeoutSeconds`. - **Chart version:** bumped once at the top of the stack, in #9773 ## What got simpler The chart no longer has a "no key" mode, so there is one way to give the probe its identity. The probe reuses the relay image and the chart's existing CronJob, image-identity, label-guard and extension patterns, so it adds no new image, no new publish workflow, and no new extension concept. ## Testing - `tests/acceptance_test.yaml` (helm-unittest): off by default; the default render (relay image, `relayUrl`, no key, no metrics, no extra volumes); a full render with a key Secret, metrics, tags, a digest-pinned image, and an init-container-minted assertion; the chart-owned Datadog version label; the required image tag or digest; `probe_revision` from the probe's image even with another `relayUrl`; no service account inheritance or token mount; and rejection of a missing probe key (also with an assertion file), a tag without a key, an uppercase tag key, a tag key with a space or a trailing `_`, a probe-owned tag key, a repeated tag key, and a chart-owned pod label. The init-container test pins the full `initContainers`, `volumes` and `volumeMounts`. - CI builds the relay image from the changed `Dockerfile`. - A kind run installed the chart and ran one Job against the in-cluster relay: exit 0, all checks passed, no service account token. That run had no key, no assertion and no statsd, so the key and assertion wiring is covered by the render tests above only. ## Follow-ups (not in this PR) - Relay build attribution: the relay does not expose its build id on a public surface yet, so a run can't name the relay build it reached. A deploy gate on these metrics stays report-only until it can. - A canary run against the Rollout's canary Service needs a dial override that keeps the canonical Host (see #9767). 🤖 Generated with [Claude Code](https://claude.com/claude-code) buzz-review-completed --------- Signed-off-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz> Co-authored-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent af8287d commit 930fd29

7 files changed

Lines changed: 711 additions & 2 deletions

File tree

‎Dockerfile‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,20 @@ ARG BUZZ_BUILD_URL=unknown
7676
ENV BUZZ_SOURCE_SHA=${BUZZ_SOURCE_SHA} \
7777
BUZZ_BUILD_ID=${BUZZ_BUILD_ID} \
7878
BUZZ_BUILD_URL=${BUZZ_BUILD_URL}
79+
# buzz-acceptance ships in the relay image, so a deployment can run the probe
80+
# without a second image. The probe can still reach a relay of another build.
7981
RUN cargo build --release --locked -p buzz-relay --bin buzz-relay \
8082
-p buzz-admin --bin buzz-admin \
81-
-p buzz-pair-relay --bin buzz-pair-relay
83+
-p buzz-pair-relay --bin buzz-pair-relay \
84+
-p buzz-test-client --bin buzz-acceptance
8285

8386
# Derive the normal release binaries from the same optimized ELF files as the
8487
# debug image so the two variants cannot drift at code-generation time.
8588
FROM builder AS stripped-binaries
8689
RUN strip target/release/buzz-relay \
8790
&& strip target/release/buzz-admin \
88-
&& strip target/release/buzz-pair-relay
91+
&& strip target/release/buzz-pair-relay \
92+
&& strip target/release/buzz-acceptance
8993

9094
# ─── Stage 4: web bundle (pnpm + vite) ──────────────────────────────────────
9195
# Independent of the Rust layers so a CSS change doesn't bust Rust cache and
@@ -179,10 +183,12 @@ FROM runtime-base AS runtime-debug
179183
COPY --from=builder /build/target/release/buzz-relay /usr/local/bin/buzz-relay
180184
COPY --from=builder /build/target/release/buzz-admin /usr/local/bin/buzz-admin
181185
COPY --from=builder /build/target/release/buzz-pair-relay /usr/local/bin/buzz-pair-relay
186+
COPY --from=builder /build/target/release/buzz-acceptance /usr/local/bin/buzz-acceptance
182187

183188
# Keep the stripped runtime as the final/default Dockerfile target so existing
184189
# `docker build .` callers and release tags retain their current behavior.
185190
FROM runtime-base AS runtime
186191
COPY --from=stripped-binaries /build/target/release/buzz-relay /usr/local/bin/buzz-relay
187192
COPY --from=stripped-binaries /build/target/release/buzz-admin /usr/local/bin/buzz-admin
188193
COPY --from=stripped-binaries /build/target/release/buzz-pair-relay /usr/local/bin/buzz-pair-relay
194+
COPY --from=stripped-binaries /build/target/release/buzz-acceptance /usr/local/bin/buzz-acceptance

‎deploy/charts/buzz/README.md‎

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,103 @@ from the deployed image identity (`image.digest` when set, otherwise
514514
`image.tag`, otherwise `Chart.AppVersion`). The value is never hashed or
515515
sanitized.
516516

517+
## Acceptance probe
518+
519+
`acceptance.enabled=true` adds a CronJob that runs `buzz-acceptance` from the
520+
relay image. Each run checks the relay's core jobs once (NIP-11, connect and
521+
NIP-42 auth, channel create, publish, fan-out, history, access control and
522+
cleanup), prints a JSON report and exits: 0 when every check passed, 1 when
523+
one failed, 2 when the probe could not run or report. The probe ships in the
524+
relay image, so it needs an explicit `image.tag` or `image.digest`: the chart
525+
fails to render when both are empty, because the default `Chart.AppVersion`
526+
image predates the probe.
527+
528+
- The probe connects to `acceptance.relayUrl`, or to `relayUrl` when that is
529+
empty. Each run creates one private channel with a 1 h TTL and deletes it.
530+
- `acceptance.privateKeySecret.name` names a Secret with the probe's key
531+
(hex or nsec). It is required: the chart fails to render without it. A new
532+
key per run would fail on a members-only relay, and an open relay would
533+
join each new key to every auto-join channel. On a members-only relay, make
534+
the key a relay member first.
535+
- `acceptance.statsdAddr` sends DogStatsD metrics under
536+
`acceptance.metricPrefix` (`<prefix>.runs`, `<prefix>.run.seconds`,
537+
`<prefix>.check.runs`, `<prefix>.check.seconds`, `<prefix>.stage.seconds`).
538+
`$(HOST_IP)` expands to the node IP, for example `$(HOST_IP):8125` for a
539+
node-local agent. Every series carries `probe_revision`, the relay's NIP-11
540+
`relay_version`, and each `acceptance.tags` entry. `probe_revision` names the
541+
probe's own image (`image.digest`, else `image.tag`), not the relay build the
542+
run reached: during a rollout, or with `acceptance.relayUrl` set, the probe
543+
can reach pods of another build. `acceptance.tags` keys must be lowercase
544+
(`a-z`, `0-9`, `_`, `.`, `/`, `-`, starting with a letter, with no `__` and
545+
no trailing `_`), because Datadog lowercases keys, collapses `__` and trims
546+
`_`. They can't reuse the
547+
probe-owned keys `probe_revision`, `relay_version`, `check`, `stage` or
548+
`result`, and each key may appear once.
549+
- The Pod runs with `acceptance.serviceAccountName`, or the namespace default
550+
service account when that is empty. It never inherits the relay's service
551+
account and never mounts its token.
552+
- `concurrencyPolicy` is `Forbid` and `backoffLimit` is 0: a retry would
553+
hide a failed run. `acceptance.activeDeadlineSeconds` bounds the whole run,
554+
including image pull and init containers. The probe sends metrics only when
555+
the run ends, so a run killed at the deadline sends none. A run has 13
556+
serial stage timeouts, each `acceptance.stageTimeoutSeconds`, plus about
557+
30 s to close and send metrics. Keep the deadline above 13 ×
558+
`stageTimeoutSeconds` + 30 s plus pull and init time.
559+
560+
On a relay that enforces NIP-FI, the probe needs a fresh assertion for its
561+
key. Minting one is deployment-specific, so the chart takes it as a file: an
562+
init container writes it to a shared volume and `acceptance.assertionFile`
563+
points the probe at it. The probe re-reads the file before every connection.
564+
The assertion must name the probe's key, so the init container needs the same
565+
key Secret. Keep the Pod's `runAsUser` in the init container, so the probe can
566+
read files the minter writes with mode 0600.
567+
568+
```yaml
569+
image:
570+
tag: 1.2.3 # a relay build that includes buzz-acceptance
571+
acceptance:
572+
enabled: true
573+
privateKeySecret:
574+
name: buzz-acceptance-key
575+
statsdAddr: "$(HOST_IP):8125"
576+
tags: ["env:staging"]
577+
assertionFile: /var/run/assertion/token
578+
extraInitContainers:
579+
- name: mint-assertion
580+
image: example.com/assertion-minter:v1
581+
args: [--out, /var/run/assertion/token]
582+
env:
583+
- name: BUZZ_PRIVATE_KEY # the assertion must name the probe's key
584+
valueFrom:
585+
secretKeyRef:
586+
name: buzz-acceptance-key
587+
key: BUZZ_PRIVATE_KEY
588+
securityContext:
589+
runAsNonRoot: true
590+
allowPrivilegeEscalation: false
591+
readOnlyRootFilesystem: true
592+
capabilities:
593+
drop: [ALL]
594+
resources:
595+
limits:
596+
cpu: 100m
597+
memory: 64Mi
598+
volumeMounts:
599+
- name: assertion
600+
mountPath: /var/run/assertion
601+
extraVolumes:
602+
- name: assertion
603+
emptyDir:
604+
medium: Memory # holds a credential
605+
extraVolumeMounts:
606+
- name: assertion
607+
mountPath: /var/run/assertion
608+
readOnly: true
609+
```
610+
611+
The extension values follow the same rules as the relay Pod extensions above.
612+
Keep the assertion's lifetime longer than `acceptance.activeDeadlineSeconds`.
613+
517614
## Datadog version label
518615

519616
Every Pod the chart renders — relay, pairing relay, storage accounting, and the

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,32 @@ surface at template time regardless of which manifest helm renders first.
2525
{{- end -}}
2626
{{- end -}}
2727

28+
{{/* The acceptance probe ships only in relay images that include it, so the
29+
chart's default appVersion image can't run it. The probe needs a key the
30+
relay admits, so the chart never lets it fall back to a new key per run.
31+
acceptance.tags keys are canonical (see values.schema.json) and can't
32+
override probe-owned metric tag keys or repeat a key, so one run never
33+
lands in two populations of the same tag. */}}
34+
{{- if .Values.acceptance.enabled -}}
35+
{{- if not (or .Values.image.tag .Values.image.digest) -}}
36+
{{- fail "acceptance.enabled requires image.tag or image.digest: the probe binary is not in the chart's default appVersion image." -}}
37+
{{- end -}}
38+
{{- if not .Values.acceptance.privateKeySecret.name -}}
39+
{{- fail "acceptance.enabled requires acceptance.privateKeySecret.name: without a key the probe signs with a new key each run, which a members-only relay refuses and an open relay joins to every auto-join channel." -}}
40+
{{- end -}}
41+
{{- $seen := dict -}}
42+
{{- range .Values.acceptance.tags -}}
43+
{{- $key := splitList ":" . | first -}}
44+
{{- if has $key (list "probe_revision" "relay_version" "check" "stage" "result") -}}
45+
{{- fail (printf "acceptance.tags: %q uses the probe-owned tag key %q." . $key) -}}
46+
{{- end -}}
47+
{{- if hasKey $seen $key -}}
48+
{{- fail (printf "acceptance.tags: tag key %q appears more than once." $key) -}}
49+
{{- end -}}
50+
{{- $_ := set $seen $key true -}}
51+
{{- end -}}
52+
{{- end -}}
53+
2854
{{/* Multiple replicas do NOT require ReadWriteMany git storage.
2955
3056
Git ref/object state is object-store-backed: every read and write hydrates
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
{{- include "buzz.validate" . -}}
2+
{{- if .Values.acceptance.enabled }}
3+
{{- $a := .Values.acceptance }}
4+
{{- range $label := list "app.kubernetes.io/name" "app.kubernetes.io/instance" "app.kubernetes.io/component" }}
5+
{{- if hasKey ($a.podLabels | default dict) $label }}
6+
{{- fail (printf "acceptance.podLabels may not set chart-owned label %q" $label) }}
7+
{{- end }}
8+
{{- end }}
9+
apiVersion: batch/v1
10+
kind: CronJob
11+
metadata:
12+
name: {{ include "buzz.cronJobName" (dict "root" . "suffix" "acceptance") }}
13+
labels:
14+
{{- include "buzz.labels" . | nindent 4 }}
15+
app.kubernetes.io/component: acceptance
16+
spec:
17+
schedule: {{ $a.schedule | quote }}
18+
concurrencyPolicy: Forbid
19+
successfulJobsHistoryLimit: {{ $a.successfulJobsHistoryLimit }}
20+
failedJobsHistoryLimit: {{ $a.failedJobsHistoryLimit }}
21+
jobTemplate:
22+
spec:
23+
activeDeadlineSeconds: {{ $a.activeDeadlineSeconds }}
24+
backoffLimit: 0
25+
template:
26+
metadata:
27+
labels:
28+
{{- include "buzz.selectorLabels" . | nindent 12 }}
29+
app.kubernetes.io/component: acceptance
30+
{{- include "buzz.podLabelsWithVersion" (dict "root" . "labels" $a.podLabels) | nindent 12 }}
31+
{{- with $a.podAnnotations }}
32+
annotations:
33+
{{- toYaml . | nindent 12 }}
34+
{{- end }}
35+
spec:
36+
restartPolicy: Never
37+
{{- /* The probe needs no Kubernetes or cloud access, so it does not
38+
inherit the relay's service account or its token. */}}
39+
{{- with $a.serviceAccountName }}
40+
serviceAccountName: {{ . }}
41+
{{- end }}
42+
automountServiceAccountToken: false
43+
enableServiceLinks: false
44+
securityContext:
45+
{{- toYaml .Values.relay.securityContext | nindent 12 }}
46+
{{- with .Values.image.pullSecrets }}
47+
imagePullSecrets:
48+
{{- toYaml . | nindent 12 }}
49+
{{- end }}
50+
{{- with $a.extraInitContainers }}
51+
initContainers:
52+
{{- toYaml . | nindent 12 }}
53+
{{- end }}
54+
containers:
55+
- name: acceptance
56+
image: {{ include "buzz.image" . }}
57+
imagePullPolicy: {{ .Values.image.pullPolicy }}
58+
securityContext:
59+
{{- omit .Values.relay.containerSecurityContext "readOnlyRootFilesystem" | toYaml | nindent 16 }}
60+
readOnlyRootFilesystem: true
61+
command: ["/usr/local/bin/buzz-acceptance"]
62+
args:
63+
- --stage-timeout-secs
64+
- {{ $a.stageTimeoutSeconds | int64 | quote }}
65+
- --metric-prefix
66+
- {{ $a.metricPrefix | quote }}
67+
- --tag
68+
- {{ printf "probe_revision:%s" (include "buzz.imageRevision" .) | quote }}
69+
{{- range $a.tags }}
70+
- --tag
71+
- {{ . | quote }}
72+
{{- end }}
73+
env:
74+
# Listed first so later values can use $(HOST_IP).
75+
- name: HOST_IP
76+
valueFrom:
77+
fieldRef:
78+
fieldPath: status.hostIP
79+
- { name: BUZZ_RELAY_URL, value: {{ default .Values.relayUrl $a.relayUrl | quote }} }
80+
{{- with $a.statsdAddr }}
81+
- { name: BUZZ_ACCEPTANCE_STATSD_ADDR, value: {{ . | quote }} }
82+
{{- end }}
83+
{{- with $a.assertionFile }}
84+
- { name: BUZZ_ACCEPTANCE_ASSERTION_FILE, value: {{ . | quote }} }
85+
{{- end }}
86+
{{- if $a.privateKeySecret.name }}
87+
- name: BUZZ_PRIVATE_KEY
88+
valueFrom:
89+
secretKeyRef:
90+
name: {{ $a.privateKeySecret.name | quote }}
91+
key: {{ $a.privateKeySecret.key | quote }}
92+
{{- end }}
93+
{{- with $a.extraVolumeMounts }}
94+
volumeMounts:
95+
{{- toYaml . | nindent 16 }}
96+
{{- end }}
97+
resources:
98+
{{- toYaml $a.resources | nindent 16 }}
99+
{{- with $a.extraVolumes }}
100+
volumes:
101+
{{- toYaml . | nindent 12 }}
102+
{{- end }}
103+
{{- end }}

0 commit comments

Comments
 (0)