cocoon-webhook

Validation rules

CocoonSet

The CRD ships with +kubebuilder enum / required / default markers, but the webhook adds the cross-field business rules that OpenAPI schema validation cannot express:

Derived name budget

Managed VM names are limited to 46 characters so that appending -hibernate-import still fits the engine’s 63-character snapshot name limit. A macOS agent or toolbox never hibernates or forks, so its VM name gets the whole 63 characters. This also leaves room for the shorter fork- snapshot prefix. Validation uses the naming functions from cocoon-common:

For example, in namespace default, a 26-character CocoonSet name fits with slots 0 through 9. A 27-character name is rejected even with zero sub-agents; scaling the 26-character name to 10 sub-agents is also rejected. Shorten the CocoonSet or toolbox name, or use a shorter namespace. Names are not truncated or rewritten, and this check does not rename existing resources.

Admission operations

These rules run on CocoonSet CREATE, and on UPDATE only when the spec changed — a spec-unchanged UPDATE (a finalizer or metadata patch) is skipped, so an invalid CR that predates stricter validation stays deletable. They run behind the POST /validate-cocoonset endpoint — see Overview for where that fits among the webhook’s other endpoints.

CocoonHibernation

POST /validate-cocoonhibernation gates CREATE only (an UPDATE is skipped — retargeting spec.podRef is already blocked by the CRD’s CEL rule):