fix(apps): keep Job and CronJob names within the Kubernetes limits (#4945)

## What this PR does

The apps API admits release names of up to 53 characters, the release
prefix included (less for Kafka and Kubernetes, which cap their own
names). Kubernetes copies a Job name into the `job-name` label of its
pods, and a label value takes at most 63 characters, so the apiserver
refuses a Job with a longer name. A CronJob name is refused over 52
characters, because the controller names each Job it starts
`<cronjob>-<timestamp>`. I rendered every Job and CronJob in
`packages/apps` and `packages/extra` with the longest release name each
application admits, and eight of them go over.

| Application | Object | Name | Longest on main | After |
| --- | --- | --- | --- | --- |
| bucket | post-delete Job | `<release>-cleanup-acme` | 66 | 63 |
| qdrant | post-delete Job | `<release>-qdrant-cleanup` | 68 | 63 |
| kafka | pre-install and pre-upgrade Job | `<release>-kafka-migration`
| 66 (release capped at 50) | 63 |
| vm-disk | resize Job, rendered when the disk grows |
`<release>-volume-resize-hook` | 72 | 63 |
| vm-instance | update Job and the `app` label of its pod |
`<release>-update-hook` | 65 | 63 |
| mariadb | backup CronJob | `<release>-backup` | 60 | 52 |
| clickhouse | legacy backup CronJob | `<release>-backup` | 60 | 52 |
| tenant | pre-delete Job in `cozy-system` | `<tenant
namespace>-cleanup` | 71 (nested namespace of 63) | 63 |

Counted in characters of the application name, a Kafka of 42 to 44
cannot be installed today, a VMDisk of 37 or more cannot grow, and a
VMInstance of 40 or 41 cannot take an instance type, profile or external
change. Deleting a Bucket of 44 or more or a Qdrant of 42 or more fails
in the post-delete hook. With the backup CronJob enabled, a MariaDB of
38 or more and a ClickHouse of 35 or more fail the whole release. A
nested tenant whose namespace is longer than 55 characters cannot be
deleted.

The Jobs of bucket, qdrant, kafka, vm-disk and vm-instance are now named
`printf "%s-<suffix>" .Release.Name | trunc 63 | trimSuffix "-"`, and
vm-instance uses the same value for the pod label. A release name is
never longer than 53, so only the fixed suffix is cut, and a brute-force
check over every pair of release name lengths found no two release names
that render the same Job name.

A plain cut to 52 would reach into the release name of a CronJob, and
two 53-character names that differ in the last character would share
one. So a CronJob name that does not fit becomes the release name cut to
38 characters, the first six hex characters of its sha256 and `-backup`,
the shape #4133 gave the ClickHouse Keeper name. The tenant cleanup Job
takes the same form with the namespace cut to 48, because it runs in
`cozy-system` next to the cleanup Job of every other tenant. There a
plain cut gives a parent and a child named `clea` the same name, and the
child's `before-hook-creation` would delete the parent's Job while it
runs.

Names that fit render exactly as before. The hook documents rendered
from main and from this branch with the short release names the tests
use are identical in all eight charts. A name that did not fit never
produced an object, so nothing is renamed on upgrade. The
ServiceAccounts, Roles and RoleBindings of these hooks keep their names,
since they have no such limit, so the ones a pre-install hook left
behind are replaced rather than orphaned. Helm runs the delete hooks
stored with a release, so an existing Bucket, Qdrant or tenant picks up
the fix with its next upgrade.

Every other Job and CronJob fits at the longest name. The cleanup Jobs
of clickhouse, harbor, mariadb and opensearch and the Kafka pre-delete
Job reach 61, the Postgres init Job 62, and the Kubernetes and
KubernetesNodes Jobs either stay under 63 or already cut their names.
The etcd and monitoring modules require their chart name as the release
name, and the gateway and seaweedfs cleanup Jobs reach 61.

Each of the eight charts gets a new helm-unittest suite. It pins a short
name, a name that lands exactly on the limit and the longest admitted
name, a cut that would end in a dash wherever one can happen, and for
the hooks the unchanged ServiceAccount and RBAC names. The CronJob
suites also pin two 53-character names that differ in the last
character, and the tenant suite pins the parent and child pair. Against
the templates on main, 18 of the 41 new cases fail, every one with a
name over the limit. With the hash forms replaced by a plain cut, the
tenant parent and child both render
`tenant-abcdefghijklmnopqrstuvwxyz-0123456789abcdefghijklmn-clea` and
the two MariaDB names both render
`mariadb-abcdefghijklmnopqrstuvwxyz0123456789abcdefgh`.
`hack/helm-unit-tests.sh` passes over all 106 packages with tests. The
Bats files that exercise these hooks and charts
(`app-cleanup-hooks_test`, `kafka-migration-hook`,
`kafka-pre-delete-hook`, `tenant-pre-delete-hook`,
`check-hook-request-timeout`, `pod-label-census_test`,
`mariadb-first-boot-waits`, `check-render-matrix`) give 96 ok on main
and on this branch. `make generate` with cozyvalues-gen v1.7.0 in the
eight packages changes nothing. A local kube-apiserver v1.35.0 refuses
the longest name each chart renders on main, with `must be no more than
63 bytes` on the job-name label or `must be no more than 52 characters`
on the CronJob, and creates the name from this branch. For vm-disk and
vm-instance, whose hooks render only after a live lookup, that check
used a Job with the same name and labels.

This is related to #4875 but does not depend on it. #4875 adds a
cozy-lib cleanup Job and cuts its name to 63 the same way, while this PR
covers the Jobs already on main. Neither needs the other, and the two
merge cleanly.

### Screenshots

Not a UI change.

### Downstream repositories

Templates and tests only. No values, schema, README, defaults,
`ApplicationDefinition`, Secret or Service name changes, and none of the
changed Job or CronJob names appears in the website, the Terraform
provider, the Ansible collection or the other repositories on the list.

- [x] No downstream repository is affected by this change
- [ ] [cozystack/website](https://github.com/cozystack/website) -
follow-up:
- [ ]
[cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack)
- follow-up:
- [ ]
[cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack)
- follow-up:
- [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up:
- [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up:
- [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) -
follow-up:
- [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) -
follow-up:
- [ ]
[cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server)
- follow-up:
- [ ]
[cozystack/external-apps-example](https://github.com/cozystack/external-apps-example)
- follow-up:
- [ ] [cozystack/examples](https://github.com/cozystack/examples) -
follow-up:
- [ ] [cozystack/community](https://github.com/cozystack/community) -
follow-up:

### Release note

```release-note
fix(apps): Job and CronJob names now fit the Kubernetes limits for the longest application names. A Kafka with a name of 42 to 44 characters can now be installed, long VMDisk and VMInstance names no longer fail a resize or an instance type change, long Bucket and Qdrant names and long nested tenant namespaces no longer fail deletion, and long MariaDB and ClickHouse names no longer fail the release with the backup CronJob enabled.
```


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Cleanup, migration, resize, and update Jobs now use names that fit
Kubernetes naming limits, including for long release or tenant names.
* ClickHouse and MariaDB backup CronJobs now use names within
Kubernetes’ length limit. Longer names are shortened with a hash suffix
to help distinguish them.
* Short names and names at the supported limit retain their existing
naming format.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Aleksei Sviridkin authored and GitHub committed 2026-11-13 18:18:40 +03:00
commit ea4968cf46
16 files changed
+795 -10

No files matched your search

@@ -2,7 +2,7 @@
apiVersion: batch/v1
kind: Job
metadata:
name: {{ .Release.Name }}-cleanup-acme
name: {{ printf "%s-cleanup-acme" .Release.Name | trunc 63 | trimSuffix "-" }}
labels:
app.kubernetes.io/instance: {{ .Release.Name }}
annotations:
@@ -0,0 +1,80 @@
suite: bucket cleanup Job name budget
# The API server copies a Job's name into the job-name label of its pods, and a
# label value takes 63 characters at most, while a release name may take 53.
# The ServiceAccount, Role and RoleBinding have no such limit and keep the full
# name, so a hook that ran before keeps the same objects.
templates:
- templates/hooks/cleanup-acme.yaml
set:
_namespace:
host: example.org
tests:
- it: keeps <release>-cleanup-acme for a short release name
release:
name: my-bucket
namespace: tenant-root
documentSelector:
path: kind
value: Job
asserts:
- equal:
path: metadata.name
value: my-bucket-cleanup-acme
- it: keeps the name when it lands exactly on 63 characters
release:
name: bucket-abcdefghijklmnopqrstuvwxyz0123456789abcdefg
namespace: tenant-root
documentSelector:
path: kind
value: Job
asserts:
- equal:
path: metadata.name
value: bucket-abcdefghijklmnopqrstuvwxyz0123456789abcdefg-cleanup-acme
- it: cuts the name to 63 characters for a 53-character release name
release:
name: bucket-abcdefghijklmnopqrstuvwxyz0123456789abcdefghij
namespace: tenant-root
documentSelector:
path: kind
value: Job
asserts:
- equal:
path: metadata.name
value: bucket-abcdefghijklmnopqrstuvwxyz0123456789abcdefghij-cleanup-a
- matchRegex:
path: metadata.name
pattern: ^[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?$
- equal:
path: spec.template.spec.serviceAccountName
value: bucket-abcdefghijklmnopqrstuvwxyz0123456789abcdefghij-cleanup-acme
- it: leaves the RBAC objects on the full name for a 53-character release name
release:
name: bucket-abcdefghijklmnopqrstuvwxyz0123456789abcdefghij
namespace: tenant-root
asserts:
- equal:
path: metadata.name
value: bucket-abcdefghijklmnopqrstuvwxyz0123456789abcdefghij-cleanup-acme
documentSelector:
path: kind
value: ServiceAccount
- equal:
path: roleRef.name
value: bucket-abcdefghijklmnopqrstuvwxyz0123456789abcdefghij-cleanup-acme
documentSelector:
path: kind
value: RoleBinding
- equal:
path: subjects[0].name
value: bucket-abcdefghijklmnopqrstuvwxyz0123456789abcdefghij-cleanup-acme
documentSelector:
path: kind
value: RoleBinding
@@ -18,11 +18,19 @@
*/}}
{{- if and .Values.backup.enabled .Values.backup.schedule (not .Values.backup.useSystemBucket) }}
{{ $image := .Files.Get "images/backup.json" | fromJson }}
{{- /* The CronJob controller starts each Job as <name>-<timestamp>, so the API
refuses a CronJob name over 52 characters. Cutting the release name to
fit could give two releases one CronJob, so a name that does not fit
keeps a hash of the full release name instead. */}}
{{- $cronJobName := printf "%s-backup" .Release.Name }}
{{- if gt (len $cronJobName) 52 }}
{{- $cronJobName = printf "%s-%s-backup" (.Release.Name | trunc 38 | trimSuffix "-") (.Release.Name | sha256sum | trunc 6) }}
{{- end }}
apiVersion: batch/v1
kind: CronJob
metadata:
name: {{ .Release.Name }}-backup
name: {{ $cronJobName }}
spec:
schedule: "{{ .Values.backup.schedule }}"
concurrencyPolicy: Forbid
@@ -0,0 +1,94 @@
suite: clickhouse legacy backup CronJob name budget
# The API refuses a CronJob name over 52 characters, because the controller
# names each Job it starts <name>-<timestamp>, while a release name may take 53.
# Cutting the release name alone would give two long names one CronJob, so a
# name that does not fit is the release name cut to 38 characters, a hash of
# the full release name and -backup.
templates:
- templates/backup-cronjob.yaml
- templates/backup-script.yaml
- templates/backup-secret.yaml
set:
_cluster: {}
backup:
enabled: true
schedule: "0 2 * * *"
tests:
- it: keeps <release>-backup for a short release name
release:
name: ch-test
namespace: tenant-test
documentSelector:
path: kind
value: CronJob
asserts:
- equal:
path: metadata.name
value: ch-test-backup
- it: keeps the name when it lands exactly on 52 characters
release:
name: clickhouse-abcdefghijklmnopqrstuvwxyz01234567
namespace: tenant-test
documentSelector:
path: kind
value: CronJob
asserts:
- equal:
path: metadata.name
value: clickhouse-abcdefghijklmnopqrstuvwxyz01234567-backup
- it: shortens the name one character past the budget
release:
name: clickhouse-abcdefghijklmnopqrstuvwxyz012345678
namespace: tenant-test
documentSelector:
path: kind
value: CronJob
asserts:
- equal:
path: metadata.name
value: clickhouse-abcdefghijklmnopqrstuvwxyz0-bec95e-backup
- it: fits a 53-character release name into 52 characters
release:
name: clickhouse-abcdefghijklmnopqrstuvwxyz0123456789abcdef
namespace: tenant-test
documentSelector:
path: kind
value: CronJob
asserts:
- equal:
path: metadata.name
value: clickhouse-abcdefghijklmnopqrstuvwxyz0-3e8cf9-backup
- matchRegex:
path: metadata.name
pattern: ^[a-z0-9]([-a-z0-9]{0,50}[a-z0-9])?$
- it: gives a release name differing only in its last character another CronJob
release:
name: clickhouse-abcdefghijklmnopqrstuvwxyz0123456789abcdex
namespace: tenant-test
documentSelector:
path: kind
value: CronJob
asserts:
- equal:
path: metadata.name
value: clickhouse-abcdefghijklmnopqrstuvwxyz0-bd3283-backup
- it: does not end the cut release name with a dash
release:
name: clickhouse-abcdefghijklmnopqrstuvwxyz-0123456789
namespace: tenant-test
documentSelector:
path: kind
value: CronJob
asserts:
- equal:
path: metadata.name
value: clickhouse-abcdefghijklmnopqrstuvwxyz-07ba9e-backup
@@ -79,7 +79,7 @@ subjects:
apiVersion: batch/v1
kind: Job
metadata:
name: {{ .Release.Name }}-kafka-migration
name: {{ printf "%s-kafka-migration" .Release.Name | trunc 63 | trimSuffix "-" }}
annotations:
helm.sh/hook: pre-install,pre-upgrade
helm.sh/hook-weight: "2"
@@ -0,0 +1,66 @@
suite: kafka migration Job name budget
# The API server copies a Job's name into the job-name label of its pods, and a
# label value takes 63 characters at most. The Kafka name cap leaves a release
# name of up to 50 characters, and the migration hook runs on install, so an
# overlong Job name would fail every install of the longest names. The
# ServiceAccount, Role and RoleBinding have no such limit and keep the full
# name, so the ones an earlier attempt left behind are replaced, not orphaned.
templates:
- templates/migration-hook.yaml
tests:
- it: keeps <release>-kafka-migration for a short release name
release:
name: test-kafka
namespace: tenant-test
documentSelector:
path: kind
value: Job
asserts:
- equal:
path: metadata.name
value: test-kafka-kafka-migration
- it: keeps the name when it lands exactly on 63 characters
release:
name: kafka-abcdefghijklmnopqrstuvwxyz0123456789abcde
namespace: tenant-test
documentSelector:
path: kind
value: Job
asserts:
- equal:
path: metadata.name
value: kafka-abcdefghijklmnopqrstuvwxyz0123456789abcde-kafka-migration
- it: cuts the name to 63 characters for the longest release name the cap admits
release:
name: kafka-abcdefghijklmnopqrstuvwxyz0123456789abcdefgh
namespace: tenant-test
documentSelector:
path: kind
value: Job
asserts:
- equal:
path: metadata.name
value: kafka-abcdefghijklmnopqrstuvwxyz0123456789abcdefgh-kafka-migrat
- matchRegex:
path: metadata.name
pattern: ^[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?$
- equal:
path: spec.template.spec.serviceAccountName
value: kafka-abcdefghijklmnopqrstuvwxyz0123456789abcdefgh-kafka-migration
- it: leaves the ServiceAccount on the full name for the longest release name
release:
name: kafka-abcdefghijklmnopqrstuvwxyz0123456789abcdefgh
namespace: tenant-test
documentSelector:
path: kind
value: ServiceAccount
asserts:
- equal:
path: metadata.name
value: kafka-abcdefghijklmnopqrstuvwxyz0123456789abcdefgh-kafka-migration
@@ -1,10 +1,18 @@
{{- if .Values.backup.enabled }}
{{ $image := .Files.Get "images/backup.json" | fromJson }}
{{- /* The CronJob controller starts each Job as <name>-<timestamp>, so the API
refuses a CronJob name over 52 characters. Cutting the release name to
fit could give two releases one CronJob, so a name that does not fit
keeps a hash of the full release name instead. */}}
{{- $cronJobName := printf "%s-backup" .Release.Name }}
{{- if gt (len $cronJobName) 52 }}
{{- $cronJobName = printf "%s-%s-backup" (.Release.Name | trunc 38 | trimSuffix "-") (.Release.Name | sha256sum | trunc 6) }}
{{- end }}
apiVersion: batch/v1
kind: CronJob
metadata:
name: {{ .Release.Name }}-backup
name: {{ $cronJobName }}
spec:
schedule: "{{ .Values.backup.schedule }}"
concurrencyPolicy: Forbid
@@ -0,0 +1,92 @@
suite: mariadb backup CronJob name budget
# The API refuses a CronJob name over 52 characters, because the controller
# names each Job it starts <name>-<timestamp>, while a release name may take 53.
# Cutting the release name alone would give two long names one CronJob, so a
# name that does not fit is the release name cut to 38 characters, a hash of
# the full release name and -backup.
templates:
- templates/backup-cronjob.yaml
- templates/backup-script.yaml
- templates/backup-secret.yaml
set:
backup:
enabled: true
tests:
- it: keeps <release>-backup for a short release name
release:
name: mariadb-test
namespace: tenant-test
documentSelector:
path: kind
value: CronJob
asserts:
- equal:
path: metadata.name
value: mariadb-test-backup
- it: keeps the name when it lands exactly on 52 characters
release:
name: mariadb-abcdefghijklmnopqrstuvwxyz0123456789a
namespace: tenant-test
documentSelector:
path: kind
value: CronJob
asserts:
- equal:
path: metadata.name
value: mariadb-abcdefghijklmnopqrstuvwxyz0123456789a-backup
- it: shortens the name one character past the budget
release:
name: mariadb-abcdefghijklmnopqrstuvwxyz0123456789ab
namespace: tenant-test
documentSelector:
path: kind
value: CronJob
asserts:
- equal:
path: metadata.name
value: mariadb-abcdefghijklmnopqrstuvwxyz0123-57a159-backup
- it: fits a 53-character release name into 52 characters
release:
name: mariadb-abcdefghijklmnopqrstuvwxyz0123456789abcdefghi
namespace: tenant-test
documentSelector:
path: kind
value: CronJob
asserts:
- equal:
path: metadata.name
value: mariadb-abcdefghijklmnopqrstuvwxyz0123-b5132c-backup
- matchRegex:
path: metadata.name
pattern: ^[a-z0-9]([-a-z0-9]{0,50}[a-z0-9])?$
- it: gives a release name differing only in its last character another CronJob
release:
name: mariadb-abcdefghijklmnopqrstuvwxyz0123456789abcdefghx
namespace: tenant-test
documentSelector:
path: kind
value: CronJob
asserts:
- equal:
path: metadata.name
value: mariadb-abcdefghijklmnopqrstuvwxyz0123-a49389-backup
- it: does not end the cut release name with a dash
release:
name: mariadb-abcdefghijklmnopqrstuvwxyz012-3456789abc
namespace: tenant-test
documentSelector:
path: kind
value: CronJob
asserts:
- equal:
path: metadata.name
value: mariadb-abcdefghijklmnopqrstuvwxyz012-2985e6-backup
@@ -2,7 +2,7 @@
apiVersion: batch/v1
kind: Job
metadata:
name: {{ .Release.Name }}-qdrant-cleanup
name: {{ printf "%s-qdrant-cleanup" .Release.Name | trunc 63 | trimSuffix "-" }}
labels:
app.kubernetes.io/instance: {{ .Release.Name }}
annotations:
@@ -0,0 +1,64 @@
suite: qdrant cleanup Job name budget
# The API server copies a Job's name into the job-name label of its pods, and a
# label value takes 63 characters at most, while a release name may take 53.
# The ServiceAccount, Role and RoleBinding have no such limit and keep the full
# name.
templates:
- templates/hooks/cleanup-pvc.yaml
tests:
- it: keeps <release>-qdrant-cleanup for a short release name
release:
name: qdrant-test
namespace: tenant-test
documentSelector:
path: kind
value: Job
asserts:
- equal:
path: metadata.name
value: qdrant-test-qdrant-cleanup
- it: keeps the name when it lands exactly on 63 characters
release:
name: qdrant-abcdefghijklmnopqrstuvwxyz0123456789abcde
namespace: tenant-test
documentSelector:
path: kind
value: Job
asserts:
- equal:
path: metadata.name
value: qdrant-abcdefghijklmnopqrstuvwxyz0123456789abcde-qdrant-cleanup
- it: cuts the name to 63 characters for a 53-character release name
release:
name: qdrant-abcdefghijklmnopqrstuvwxyz0123456789abcdefghij
namespace: tenant-test
documentSelector:
path: kind
value: Job
asserts:
- equal:
path: metadata.name
value: qdrant-abcdefghijklmnopqrstuvwxyz0123456789abcdefghij-qdrant-cl
- matchRegex:
path: metadata.name
pattern: ^[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?$
- equal:
path: spec.template.spec.serviceAccountName
value: qdrant-abcdefghijklmnopqrstuvwxyz0123456789abcdefghij-qdrant-cleanup
- it: leaves the ServiceAccount on the full name for a 53-character release name
release:
name: qdrant-abcdefghijklmnopqrstuvwxyz0123456789abcdefghij
namespace: tenant-test
documentSelector:
path: kind
value: ServiceAccount
asserts:
- equal:
path: metadata.name
value: qdrant-abcdefghijklmnopqrstuvwxyz0123456789abcdefghij-qdrant-cleanup
@@ -40,11 +40,22 @@ subjects:
- kind: ServiceAccount
name: {{ include "tenant.name" . }}-cleanup
namespace: cozy-system
{{- /* The Job name becomes the job-name label of its pod, which takes 63
characters at most, and a nested tenant namespace can use all 63 by
itself. Cutting the name to fit would let a parent and one of its
children land on the same Job in cozy-system, where the child's
before-hook-creation would delete the parent's running cleanup, so a
name that does not fit keeps a hash of the whole namespace instead. */}}
{{- $tenantName := include "tenant.name" . }}
{{- $jobName := printf "%s-cleanup" $tenantName }}
{{- if gt (len $jobName) 63 }}
{{- $jobName = printf "%s-%s-cleanup" ($tenantName | trunc 48 | trimSuffix "-") ($tenantName | sha256sum | trunc 6) }}
{{- end }}
---
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "tenant.name" . }}-cleanup
name: {{ $jobName }}
namespace: cozy-system
annotations:
helm.sh/hook: pre-delete
@@ -98,7 +109,7 @@ spec:
ttlSecondsAfterFinished: 300
template:
metadata:
name: {{ include "tenant.name" . }}-cleanup
name: {{ $jobName }}
labels:
policy.cozystack.io/allow-to-apiserver: "true"
spec:
@@ -0,0 +1,127 @@
suite: tenant cleanup Job name budget
# The API server copies a Job's name into the job-name label of its pods, and a
# label value takes 63 characters at most, while a nested tenant namespace may
# take all 63 by itself. Every tenant's cleanup Job runs in cozy-system, where
# cutting the namespace alone could give a parent and its child one Job, and the
# child's before-hook-creation would delete the parent's while it runs. So a
# name that does not fit is the namespace cut to 48 characters, a hash of the
# whole namespace and -cleanup. The ServiceAccount, Role and RoleBinding have no
# such limit and keep the full name.
templates:
- templates/cleanup-job.yaml
tests:
- it: keeps <namespace>-cleanup for a tenant under tenant-root
release:
name: tenant-test
namespace: tenant-root
documentSelector:
path: kind
value: Job
asserts:
- equal:
path: metadata.name
value: tenant-test-cleanup
- it: keeps <namespace>-cleanup for a short nested tenant
release:
name: tenant-child
namespace: tenant-test
documentSelector:
path: kind
value: Job
asserts:
- equal:
path: metadata.name
value: tenant-test-child-cleanup
- it: keeps the name when it lands exactly on 63 characters
release:
name: tenant-0123456789abcdefghijk
namespace: tenant-abcdefghijklmnopqrstuvwxyz
documentSelector:
path: kind
value: Job
asserts:
- equal:
path: metadata.name
value: tenant-abcdefghijklmnopqrstuvwxyz-0123456789abcdefghijk-cleanup
- it: shortens the name for a 63-character namespace
release:
name: tenant-0123456789abcdefghijklmnopqrs
namespace: tenant-abcdefghijklmnopqrstuvwxyz
documentSelector:
path: kind
value: Job
asserts:
- equal:
path: metadata.name
value: tenant-abcdefghijklmnopqrstuvwxyz-0123456789abcd-7b3e3e-cleanup
- matchRegex:
path: metadata.name
pattern: ^[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?$
- equal:
path: spec.template.metadata.name
value: tenant-abcdefghijklmnopqrstuvwxyz-0123456789abcd-7b3e3e-cleanup
- equal:
path: spec.template.spec.serviceAccountName
value: tenant-abcdefghijklmnopqrstuvwxyz-0123456789abcdefghijklmnopqrs-cleanup
# Cut to 63 characters, the parent below and its child named clea would both
# be tenant-abcdefghijklmnopqrstuvwxyz-0123456789abcdefghijklmn-clea.
- it: gives a parent its own Job name
release:
name: tenant-0123456789abcdefghijklmn
namespace: tenant-abcdefghijklmnopqrstuvwxyz
documentSelector:
path: kind
value: Job
asserts:
- equal:
path: metadata.name
value: tenant-abcdefghijklmnopqrstuvwxyz-0123456789abcd-571020-cleanup
- it: gives the child that would collide with that parent another Job name
release:
name: tenant-clea
namespace: tenant-abcdefghijklmnopqrstuvwxyz-0123456789abcdefghijklmn
documentSelector:
path: kind
value: Job
asserts:
- equal:
path: metadata.name
value: tenant-abcdefghijklmnopqrstuvwxyz-0123456789abcd-ec5e9b-cleanup
- it: does not end the cut namespace with a dash
release:
name: tenant-abcdefghijklmno
namespace: tenant-abcdefghijklmnopqrstuvwxyz0123456789abcd
documentSelector:
path: kind
value: Job
asserts:
- equal:
path: metadata.name
value: tenant-abcdefghijklmnopqrstuvwxyz0123456789abcd-477f49-cleanup
- it: leaves the RBAC objects on the full name for a 63-character namespace
release:
name: tenant-0123456789abcdefghijklmnopqrs
namespace: tenant-abcdefghijklmnopqrstuvwxyz
asserts:
- equal:
path: metadata.name
value: tenant-abcdefghijklmnopqrstuvwxyz-0123456789abcdefghijklmnopqrs-cleanup
documentSelector:
path: kind
value: ServiceAccount
- equal:
path: subjects[0].name
value: tenant-abcdefghijklmnopqrstuvwxyz-0123456789abcdefghijklmnopqrs-cleanup
documentSelector:
path: kind
value: RoleBinding
@@ -15,7 +15,7 @@
apiVersion: batch/v1
kind: Job
metadata:
name: "{{ .Release.Name }}-volume-resize-hook"
name: {{ printf "%s-volume-resize-hook" .Release.Name | trunc 63 | trimSuffix "-" | quote }}
annotations:
helm.sh/hook: pre-install,pre-upgrade
helm.sh/hook-weight: "0"
@@ -0,0 +1,127 @@
suite: vm-disk resize Job name budget
# The API server copies a Job's name into the job-name label of its pods, and a
# label value takes 63 characters at most, while a release name may take 53.
# The hook renders only when an existing PVC grows, so each release below gets
# a smaller PVC to look up. The ServiceAccount, Role and RoleBinding have no
# such limit and keep the full name, so the ones an earlier resize left behind
# are replaced, not orphaned.
templates:
- templates/pvc-resize-hook.yaml
set:
storage: 2Gi
kubernetesProvider:
scheme:
"v1/PersistentVolumeClaim":
gvr:
group: ""
version: "v1"
resource: "persistentvolumeclaims"
namespaced: true
objects:
- kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: test-vm-disk
namespace: tenant-test
spec:
resources:
requests:
storage: 1Gi
- kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: vm-disk-abcdefghijklmnopqrstuvwxyz0123456789
namespace: tenant-test
spec:
resources:
requests:
storage: 1Gi
- kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: vm-disk-abcdefghijklmnopqrstuvwxyz0123456789abcd
namespace: tenant-test
spec:
resources:
requests:
storage: 1Gi
- kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: vm-disk-abcdefghijklmnopqrstuvwxyz0123456789abcdefghi
namespace: tenant-test
spec:
resources:
requests:
storage: 1Gi
tests:
- it: keeps <release>-volume-resize-hook for a short release name
release:
name: test-vm-disk
namespace: tenant-test
documentSelector:
path: kind
value: Job
asserts:
- equal:
path: metadata.name
value: test-vm-disk-volume-resize-hook
- it: keeps the name when it lands exactly on 63 characters
release:
name: vm-disk-abcdefghijklmnopqrstuvwxyz0123456789
namespace: tenant-test
documentSelector:
path: kind
value: Job
asserts:
- equal:
path: metadata.name
value: vm-disk-abcdefghijklmnopqrstuvwxyz0123456789-volume-resize-hook
- it: does not end the cut name with a dash
release:
name: vm-disk-abcdefghijklmnopqrstuvwxyz0123456789abcd
namespace: tenant-test
documentSelector:
path: kind
value: Job
asserts:
- equal:
path: metadata.name
value: vm-disk-abcdefghijklmnopqrstuvwxyz0123456789abcd-volume-resize
- it: cuts the name to 63 characters for a 53-character release name
release:
name: vm-disk-abcdefghijklmnopqrstuvwxyz0123456789abcdefghi
namespace: tenant-test
documentSelector:
path: kind
value: Job
asserts:
- equal:
path: metadata.name
value: vm-disk-abcdefghijklmnopqrstuvwxyz0123456789abcdefghi-volume-re
- matchRegex:
path: metadata.name
pattern: ^[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?$
- equal:
path: spec.template.spec.serviceAccountName
value: vm-disk-abcdefghijklmnopqrstuvwxyz0123456789abcdefghi-volume-resize-hook
- it: leaves the ServiceAccount on the full name for a 53-character release name
release:
name: vm-disk-abcdefghijklmnopqrstuvwxyz0123456789abcdefghi
namespace: tenant-test
documentSelector:
path: kind
value: ServiceAccount
asserts:
- equal:
path: metadata.name
value: vm-disk-abcdefghijklmnopqrstuvwxyz0123456789abcdefghi-volume-resize-hook
@@ -1,5 +1,6 @@
{{- $vmName := include "virtual-machine.fullname" . -}}
{{- $namespace := .Release.Namespace -}}
{{- $jobName := printf "%s-update-hook" .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- $existingVM := lookup "kubevirt.io/v1" "VirtualMachine" $namespace $vmName -}}
{{- $existingService := lookup "v1" "Service" $namespace $vmName -}}
@@ -48,7 +49,7 @@
apiVersion: batch/v1
kind: Job
metadata:
name: "{{ $.Release.Name }}-update-hook"
name: "{{ $jobName }}"
annotations:
helm.sh/hook: pre-install,pre-upgrade
helm.sh/hook-weight: "0"
@@ -57,7 +58,7 @@ spec:
template:
metadata:
labels:
app: "{{ $.Release.Name }}-update-hook"
app: "{{ $jobName }}"
policy.cozystack.io/allow-to-apiserver: "true"
spec:
serviceAccountName: {{ $.Release.Name }}-update-hook
@@ -0,0 +1,107 @@
suite: vm-instance update Job name budget
# The API server copies a Job's name into the job-name label of its pods, and a
# label value takes 63 characters at most, while a release name may take 53.
# The pod's own app label carries the same name and is held to the same limit.
# The hook renders only when an existing VM or Service needs reconciling, so
# each release below gets a Service of the wrong type to look up. The
# ServiceAccount, Role and RoleBinding have no such limit and keep the full
# name, so the ones an earlier update left behind are replaced, not orphaned.
templates:
- templates/vm-update-hook.yaml
set:
external: false
kubernetesProvider:
scheme:
"v1/Service":
gvr:
group: ""
version: "v1"
resource: "services"
namespaced: true
objects:
- kind: Service
apiVersion: v1
metadata:
name: vm-instance-test
namespace: tenant-test
spec:
type: LoadBalancer
- kind: Service
apiVersion: v1
metadata:
name: vm-instance-abcdefghijklmnopqrstuvwxyz0123456789abc
namespace: tenant-test
spec:
type: LoadBalancer
- kind: Service
apiVersion: v1
metadata:
name: vm-instance-abcdefghijklmnopqrstuvwxyz0123456789abcde
namespace: tenant-test
spec:
type: LoadBalancer
tests:
- it: keeps <release>-update-hook for a short release name
release:
name: vm-instance-test
namespace: tenant-test
documentSelector:
path: kind
value: Job
asserts:
- equal:
path: metadata.name
value: vm-instance-test-update-hook
- equal:
path: spec.template.metadata.labels.app
value: vm-instance-test-update-hook
- it: keeps the name when it lands exactly on 63 characters
release:
name: vm-instance-abcdefghijklmnopqrstuvwxyz0123456789abc
namespace: tenant-test
documentSelector:
path: kind
value: Job
asserts:
- equal:
path: metadata.name
value: vm-instance-abcdefghijklmnopqrstuvwxyz0123456789abc-update-hook
- it: cuts the Job name and the app label to 63 characters for a 53-character release name
release:
name: vm-instance-abcdefghijklmnopqrstuvwxyz0123456789abcde
namespace: tenant-test
documentSelector:
path: kind
value: Job
asserts:
- equal:
path: metadata.name
value: vm-instance-abcdefghijklmnopqrstuvwxyz0123456789abcde-update-ho
- matchRegex:
path: metadata.name
pattern: ^[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?$
- equal:
path: spec.template.metadata.labels.app
value: vm-instance-abcdefghijklmnopqrstuvwxyz0123456789abcde-update-ho
- equal:
path: spec.template.spec.serviceAccountName
value: vm-instance-abcdefghijklmnopqrstuvwxyz0123456789abcde-update-hook
- it: leaves the ServiceAccount on the full name for a 53-character release name
release:
name: vm-instance-abcdefghijklmnopqrstuvwxyz0123456789abcde
namespace: tenant-test
documentSelector:
path: kind
value: ServiceAccount
asserts:
- equal:
path: metadata.name
value: vm-instance-abcdefghijklmnopqrstuvwxyz0123456789abcde-update-hook