Bound operator CronJob names

Share a suffix-preserving 52-character name helper between the deletion drain and storage accounting CronJobs while retaining their existing short names.

Co-authored-by: Codex <noreply@openai.com>
Signed-off-by: tornquist <tornquist@squareup.com>
This commit is contained in:
tornquist
2026-09-28 13:25:36 +00:00
parent e6714ec408
commit 10372630dc
6 changed files with 54 additions and 4 deletions

View File

@@ -17,6 +17,13 @@
{{- end -}}
{{- end -}}
{{/* Kubernetes CronJob names are limited to 52 characters. */}}
{{- define "buzz.cronJobName" -}}
{{- $maxBaseLength := sub 51 (len .suffix) | int -}}
{{- $base := include "buzz.fullname" .root | trunc $maxBaseLength | trimSuffix "-" -}}
{{- printf "%s-%s" $base .suffix -}}
{{- end -}}
{{- define "buzz.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

View File

@@ -12,7 +12,7 @@
apiVersion: batch/v1
kind: CronJob
metadata:
name: {{ include "buzz.fullname" $root }}-deletion-drain
name: {{ include "buzz.cronJobName" (dict "root" $root "suffix" "deletion-drain") }}
labels:
{{- include "buzz.labels" $root | nindent 4 }}
app.kubernetes.io/component: deletion-drain

View File

@@ -2,7 +2,7 @@
apiVersion: batch/v1
kind: CronJob
metadata:
name: {{ include "buzz.fullname" . }}-storage-accounting
name: {{ include "buzz.cronJobName" (dict "root" . "suffix" "storage-accounting") }}
labels:
{{- include "buzz.labels" . | nindent 4 }}
app.kubernetes.io/component: storage-accounting

View File

@@ -307,3 +307,22 @@ tests:
asserts:
- failedTemplate:
errorPattern: "operatorJobs.deletionDrain requires Redis"
- it: preserves the deletion suffix while bounding a long release and name override
release:
name: very-long-release-name-for-operator-jobs
set:
nameOverride: custom-buzz-name
relayUrl: wss://buzz.example.com
ownerPubkey: "0000000000000000000000000000000000000000000000000000000000000000"
externalPostgresql.url: postgres://u:p@h:5432/d
externalRedis.url: redis://h:6379
s3.endpoint: https://s3.example.com
s3.bucket: buzz-media-example
s3.accessKey: test
s3.secretKey: test
operatorJobs.deletionDrain.enabled: true
asserts:
- equal:
path: metadata.name
value: very-long-release-name-for-operator-j-deletion-drain

View File

@@ -53,6 +53,10 @@ tests:
path: kind
value: CronJob
template: templates/storage-accounting-cronjob.yaml
- equal:
path: metadata.name
value: RELEASE-NAME-buzz-storage-accounting
template: templates/storage-accounting-cronjob.yaml
- equal:
path: spec.concurrencyPolicy
value: Forbid
@@ -143,3 +147,21 @@ tests:
content:
name: BUZZ_GIT_HOOK_HMAC_SECRET
template: templates/storage-accounting-cronjob.yaml
- it: preserves the storage suffix without a trailing separator after truncation
set:
fullnameOverride: storage-accounting-fullname-that-needs-truncation-at-the-separator
relayUrl: wss://buzz.example.com
ownerPubkey: "0000000000000000000000000000000000000000000000000000000000000000"
externalPostgresql.url: postgres://u:p@h:5432/d
externalRedis.url: redis://h:6379
s3.endpoint: https://s3.example.com
s3.bucket: buzz-media-example
s3.accessKey: test
s3.secretKey: test
storageAccounting.enabled: true
asserts:
- equal:
path: metadata.name
value: storage-accounting-fullname-that-storage-accounting
template: templates/storage-accounting-cronjob.yaml

View File

@@ -82,8 +82,10 @@ reports their objects with the `null` version id.
-l app.kubernetes.io/component=deletion-drain,app.kubernetes.io/instance=<release>
```
The name is `<fullname>-deletion-drain`. `buzz.fullname` collapses to the
release name when the release name already contains the chart name, so
The name is `<bounded-fullname>-deletion-drain`. The chart truncates only the
fullname portion when needed so the suffix remains stable within Kubernetes'
52-character CronJob name limit. `buzz.fullname` collapses to the release
name when the release name already contains the chart name, so
`helm install buzz ...` renders `buzz-deletion-drain`, not
`buzz-buzz-deletion-drain`.
5. Start one staffed manual run with