Files
cozystack/packages/apps/vm-disk
Aleksei Sviridkin ea4968cf46 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 -->
2026-11-13 18:18:40 +03:00
..
2025-09-18 16:27:38 +02:00
2024-10-16 18:35:30 +02:00
2025-09-24 12:32:37 +02:00

Virtual Machine Disk

A Virtual Machine Disk

storageClass and source are annotated as immutable in the chart schema — see storageClass immutability for the contract and which consumers enforce it. DataVolume.spec is immutable in CDI, so the chart also fails the release on an attempted storageClass/source edit of an existing disk rather than silently reusing the old spec; delete and recreate the disk to change either field.

Whether CDI has finished populating the disk shows up in the WorkloadsReady condition, not in Ready, which follows the Helm release and does not wait on the DataVolume: WorkloadsReady stays False while an import, clone or upload is in flight and when the DataVolume fails. Its message names the DataVolume and the phase it is in, followed by the error CDI reports for the pod populating the disk when there is one, such as a 404 or an unresolvable host on an HTTP source: CDI keeps retrying such an import, so its phase stays ImportInProgress, and the error is shown between retries rather than while a retry is running. kubectl get vmdisks shows the condition in the WORKLOADS column, and the console badge reads DataVolumeNotReady until it is True. A disk created before this behaviour was introduced keeps its old release settings, under which Ready may wait on the DataVolume, until its application is next updated. A source.upload disk reads False from the moment it is created until virtctl image-upload completes, because CDI reports waiting for the upload and receiving it as one phase. A disk counts as ready while it waits for its consumer with bindImmediately off on a WaitForFirstConsumer class, because that is a state such a disk is supposed to rest in.

bindImmediately is on by default, so a disk's volume is provisioned when the disk is created rather than deferred to the first consumer. That default exists because a VMDisk is a standalone object with a lifecycle of its own: on a WaitForFirstConsumer StorageClass a disk that no VM has attached yet would otherwise never populate at all. It costs something on a node-pinned class such as local, where the CDI worker pod becomes the first consumer and the volume lands where that pod was scheduled rather than where the VM will run, so a VM whose placement is constrained (a nodeSelector, a resource request only one node satisfies, or the Windows affinity applied by _cluster.scheduling.dedicatedNodesForWindowsVMs) can stay unschedulable against a node-affinity conflict, and storageClass is immutable so the only exit is deleting and recreating the disk. Turn bindImmediately off for a disk a VMInstance will consume on such a class: KubeVirt then renders a temporary launcher pod carrying the VM's own affinity and node selector, and the volume binds where the VM can actually run. The chart default replicated binds Immediate regardless, so neither setting changes anything there.

A disk created from source.image should use the StorageClass its golden image lives in, replicated in the default layout. When CDI clones with the csi-clone strategy, the platform default, into a different StorageClass of the same CSI driver with the same volume mode and room to expand, it does not fall back to a host-assisted copy and leaves the clone to the driver. The snapshot strategy does the same when it gets a VolumeSnapshotClass of that driver: the class both StorageProfiles name, or, when they do not name the same one, any class of the driver. LINSTOR creates that clone next to the source data, so on a target class that does not allow remote volume access from every node, such as a node-local class, the clone may never bind. The chart refuses such a new disk when the golden's driver and the target class's provisioner are both LINSTOR and the target's allowRemoteVolumeAccess is not a value linstor-csi reads as true (1, t or true, in any of the cases Go's strconv.ParseBool accepts); any other value is a list of rules, and the chart counts it as access from anywhere only when one rule names no fromSame label. Without that parameter it reads the target's layer list the way linstor-csi does, which allows remote access when it has a DRBD or NVMe layer, and a class that sets no layer list has DRBD. Under snapshot, it also refuses a disk whose golden and target StorageProfiles name the same VolumeSnapshotClass when that class does not exist and the golden's driver is the target class's provisioner, whatever the driver: CDI then fails to plan the clone instead of falling back. Both refusals compare only what they can look up: without the golden image's PVC, the cdi resource or the target's StorageClass nothing is compared. The remote access refusal also needs the target's StorageProfile with a claim property set and the golden's driver, taken from its bound PV or else from its StorageClass; when any of them is missing, the disk renders. Neither applies to a disk whose DataVolume or PVC already exists. Use the golden image's StorageClass instead, or ask the platform administrator to set cloneStrategyOverride: copy in the kubevirt-cdi package, which clones through a host-assisted copy in every case. The remote access refusal leaves alone a target class that allows remote volume access, a driver other than LINSTOR, a target class of another driver, a different volume mode, a class without volume expansion, snapshot that gets no VolumeSnapshotClass of the driver, and the copy strategy. An empty storageClass is compared as the class CDI would pick for it: the class annotated storageclass.kubevirt.io/is-default-virt-class, otherwise the class annotated storageclass.kubernetes.io/is-default-class; when several classes carry the annotation that decides, nothing is compared.

Parameters

Common parameters

Name Description Type Value
source The source image location used to create a disk. object {}
source.image Use image by name from default collection. *object null
source.image.name Name of the image to use. string ""
source.upload Upload local image. *object null
source.http Download image from an HTTP source. *object null
source.http.url URL to download the image. string ""
source.disk Clone an existing vm-disk. *object null
source.disk.name Name of the vm-disk to clone. string ""
optical Defines if disk should be considered optical. bool false
storage The size of the disk allocated for the virtual machine. quantity 5Gi
storageClass StorageClass used to store the data. string replicated
bindImmediately Provision the volume at disk creation instead of waiting for a consumer. bool true