mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-21 12:13:55 +09:00
fix(apps): keep Job and CronJob names within the Kubernetes limits
The apps API admits release names of up to 53 characters, and several charts name a Job <release>-<suffix>. 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 refused these Jobs for the longest names. A Kafka whose name has 42 to 44 characters could not be installed, a VMDisk of 37 or more could not grow, a VMInstance of 40 or 41 could not take an instance type, profile or external change, and a Bucket of 44 or more or a Qdrant of 42 or more failed its post-delete hook. Those Job names, and the pod label vm-instance copies from one, are now cut to 63 characters. A release name is never longer than 53, so only the fixed suffix is cut and two releases still get two Jobs. A CronJob name is refused over 52 characters, because the controller names each Job it starts <cronjob>-<timestamp>. With the backup CronJob on, a MariaDB whose name has 38 characters or more and a ClickHouse of 35 or more failed the whole release. A cut there reaches into the release name and could give two releases one CronJob, so a name that does not fit becomes the release name cut to 38 characters, a hash of the full release name and -backup, the way the ClickHouse Keeper name is already shortened. The tenant cleanup Job is named after the tenant namespace, which a nested tenant can fill to 63 characters by itself. The Job runs in cozy-system next to that of every other tenant, where a plain cut could give a parent and its child one name and let the child's before-hook-creation delete the parent's Job while it runs, so it is shortened with a hash of the namespace the same way. Names that fit render exactly as before, and a name that did not fit never produced an object, so nothing is renamed on upgrade. The hook ServiceAccounts, Roles and RoleBindings have no such limit and keep their names. Assisted-by: LLM Signed-off-by: Yan Bondarenko <202671653+yankawai@users.noreply.github.com>
This commit is contained in:
1 parent
aed7fa896e
commit
a2c9c07a16
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
|
||||
Reference in new issue
Block a user