Skip to content

feat(disks, images): allow names up to the Kubernetes name limit#2548

Open
fl64 wants to merge 8 commits into
mainfrom
feat/api/resource-name-length
Open

feat(disks, images): allow names up to the Kubernetes name limit#2548
fl64 wants to merge 8 commits into
mainfrom
feat/api/resource-name-length

Conversation

@fl64

@fl64 fl64 commented Jun 27, 2026

Copy link
Copy Markdown
Member

Description

VirtualDisk, VirtualImage and ClusterVirtualImage names had to stay short — 60, 49 and 48 characters — even though Kubernetes allows up to 253. The reason was internal: the resource name was used verbatim as the underlying disk/volume identifier, which must be a much shorter DNS-1123 label, so the user-facing name inherited that tight limit.

The underlying identifier is now derived and shortened independently of the user-facing name, so VirtualDisk/VirtualImage/ClusterVirtualImage names may use the full Kubernetes name length. Existing resources are unaffected: any name that already fits keeps the exact same underlying identifier, so running virtual machines are not disrupted and no migration is required. If two resources ever derived the same identifier, the conflict is reported explicitly instead of silently overwriting a disk.

VirtualMachine names stay limited to 63 characters: a VM name still flows into pod names and label values, which is handled separately.

End-to-end coverage is added by reusing the existing lifecycle suites (disk hotplug attach/detach, VirtualDisk snapshot of a running VM, live-migration via eviction) with disk names longer than the former limit.

Why do we need it, and what problem does it solve?

Operators importing or migrating workloads from other systems regularly hit the tight, inconsistent name limits on disks and images and have to rename resources, which breaks tooling and automation that rely on the original names. After this change disks and images accept the standard Kubernetes name length, while existing virtual machines keep working unchanged.

What is the expected result?

  • A VirtualDisk, VirtualImage or ClusterVirtualImage can be created with a name longer than the old limit (up to 253 characters); a virtual machine that uses it starts, hot-plugs, live-migrates, restarts and snapshots normally.
  • Existing virtual machines reconcile with no change to their underlying volumes and without a restart.

Checklist

  • The code is covered by unit tests.
  • e2e tests passed.
  • Documentation updated according to the changes.
  • Changes were tested in the Kubernetes cluster manually.

Changelog entries

section: disks
type: feature
summary: VirtualDisk names may use the full Kubernetes name length instead of being capped at 60 characters.
---
section: images
type: feature
summary: VirtualImage and ClusterVirtualImage names may use the full Kubernetes name length instead of being capped at 49 and 48 characters.

fl64 added 5 commits June 27, 2026 18:22
Introduce shortenDiskName in kvbuilder: names within the per-device budget
that are valid DNS-1123 labels pass through byte-identically (existing volumes
are never renamed), while longer or non-label names are deterministically
shortened to a readable prefix plus an FNV-1a 64-bit hash of the full name,
keeping the derived KubeVirt volume/disk name a valid label within 63 chars.

This is the groundwork for allowing resource names up to the Kubernetes limit:
behaviour is unchanged for every name the current validation already accepts.

Add a Ginkgo suite bootstrap to the kvbuilder package (it had none, so the
existing specs did not run) and golden tests for the new derivation.

Signed-off-by: Pavel Tishkov <pavel.tishkov@flant.com>
…x-strip

Derived volume/disk names will be shortened/hashed for long resource names, so
recovering the user resource from a volume name by stripping the vd-/vi-/cvi-
prefix no longer works. Introduce kvbuilder.VolumeNameResolver, seeded with the
resources a VM references (spec + VMBDA), which matches by forward-generating
each candidate's volume name and falls back to prefix-strip for legacy names.

- vm block-device status and hotplug handler now resolve via the seeded resolver;
- VMBDA and VirtualDiskSnapshot KVVMI watchers forward-map candidates instead of
  reversing the volume name (the vdsnapshot watcher dropped a manual vd- strip);
- extract GenerateVMBDADiskName and reuse it in VMBDA deletion.

Behaviour is unchanged for existing short names.

Signed-off-by: Pavel Tishkov <pavel.tishkov@flant.com>
The internal disk name is derived from the resource name; SetDisk replaces an
existing disk/volume by that name, so if two distinct block devices ever derived
the same internal name one would silently overwrite the other (dropping a disk /
mounting the wrong PVC). The derivation uses a 64-bit hash so a collision is
astronomically unlikely, but detect it at build time and fail with a clear,
user-facing message instead of corrupting the VM.

The error names the two conflicting resources in full and asks to recreate one
with a different name (resource names are immutable, so renaming is not an option).

Signed-off-by: Pavel Tishkov <pavel.tishkov@flant.com>
The tight VirtualDisk/VirtualImage/ClusterVirtualImage name limits (60/49/48)
existed only because the name was used verbatim as the KubeVirt volume/disk name
(a DNS-1123 label). That name is now derived and shortened independently, so the
user-facing name may use the full Kubernetes DNS subdomain length (253).

- raise the create limits to 253 (VirtualMachine stays 63: its name still flows
  into KubeVirt pod names and label values, to be addressed separately);
- drop the per-reference length check in the VM block-device validator: it only
  duplicated limits the referenced resource is already bound by.

Signed-off-by: Pavel Tishkov <pavel.tishkov@flant.com>
The 60/49/48-character limits no longer apply: these names may now use the full
Kubernetes name length. Update the type doc comments and regenerate CRDs (and the
Russian docs).

Signed-off-by: Pavel Tishkov <pavel.tishkov@flant.com>
@fl64 fl64 added this to the v1.10.0 milestone Jun 27, 2026
fl64 added 3 commits June 27, 2026 19:09
Reuse the existing builder-based e2e tests to validate end-to-end that
VirtualDisk names up to the Kubernetes name length work: disk hotplug
attach/detach, snapshotting a running VM's disk, and live-migration via eviction
now use disk names longer than the former 60-character limit. VirtualMachine
names stay short, as that limit is unchanged.

Signed-off-by: Pavel Tishkov <pavel.tishkov@flant.com>
The hash suffix length is taken from the generated value directly, so the
constant was unused and tripped the linter.

Signed-off-by: Pavel Tishkov <pavel.tishkov@flant.com>
…specific name rules

The >253 length check for VirtualDisk/VirtualImage/ClusterVirtualImage only
duplicated the Kubernetes metadata.name limit (the apiserver rejects >253 first),
so it is removed along with the now-unused constants; restore falls back to the
253 default for these kinds. VirtualMachine keeps its DVP-specific 63 limit.

Add unit tests for the rules DVP actually owns (Kubernetes does not enforce them):
VirtualMachine name length (63 ok / 64 rejected) and the dot ban for VirtualDisk.

Signed-off-by: Pavel Tishkov <pavel.tishkov@flant.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant