You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(vmop): add validation rules for clone naming (#1522)
Summary
This PR enhances the VirtualMachineOperation CRD by adding validation rules to ensure safe and valid resource naming during clone operations.
Changes
- Added x-kubernetes-validations to the clone.customization section:
- namePrefix and nameSuffix, if set, must be 1–59 characters long.
- Added validation for nameReplacement:
- Each to field must be 1–59 characters long.
- Enforced that at least one renaming mechanism is specified:
- Either customization.namePrefix, customization.nameSuffix, or at least one entry in nameReplacement must be provided.
Signed-off-by: Dmitry Lopatin <[email protected]>
// +kubebuilder:validation:XValidation:rule="(has(self.customization) && ((has(self.customization.namePrefix) && size(self.customization.namePrefix) > 0) || (has(self.customization.nameSuffix) && size(self.customization.nameSuffix) > 0))) || (has(self.nameReplacement) && size(self.nameReplacement) > 0)",message="At least one of customization.namePrefix, customization.nameSuffix, or nameReplacement must be set"
72
73
// VirtualMachineOperationCloneSpec defines the clone operation.
73
74
typeVirtualMachineOperationCloneSpecstruct {
74
75
ModeVMOPRestoreMode`json:"mode"`
75
76
// NameReplacement defines rules for renaming resources during cloning.
77
+
// +kubebuilder:validation:XValidation:rule="self.all(nr, has(nr.to) && size(nr.to) >= 1 && size(nr.to) <= 59)",message="Each nameReplacement.to must be between 1 and 59 characters"
// +kubebuilder:validation:XValidation:rule="!has(self.namePrefix) || (size(self.namePrefix) >= 1 && size(self.namePrefix) <= 59)",message="namePrefix length must be between 1 and 59 characters if set"
84
+
// +kubebuilder:validation:XValidation:rule="!has(self.nameSuffix) || (size(self.nameSuffix) >= 1 && size(self.nameSuffix) <= 59)",message="nameSuffix length must be between 1 and 59 characters if set"
81
85
// VirtualMachineOperationCloneCustomization defines customization options for cloning.
0 commit comments