Add +k8s:listType, +k8s:listMapKey, and +k8s:maxItems validation tags

This commit is contained in:
helayoty
2025-11-27 00:55:24 +00:00
committed by Heba Elayoty
parent 36ddf6c471
commit ac7b776537
3 changed files with 13 additions and 1 deletions

View File

@@ -306,6 +306,10 @@ func Validate_WorkloadSpec(ctx context.Context, op operation.Operation, fldPath
}
// call field-attached validations
earlyReturn := false
if e := validate.MaxItems(ctx, op, fldPath, obj, oldObj, 8); len(e) != 0 {
errs = append(errs, e...)
earlyReturn = true
}
if e := validate.RequiredSlice(ctx, op, fldPath, obj, oldObj); len(e) != 0 {
errs = append(errs, e...)
earlyReturn = true
@@ -313,8 +317,10 @@ func Validate_WorkloadSpec(ctx context.Context, op operation.Operation, fldPath
if earlyReturn {
return // do not proceed
}
// lists with map semantics require unique keys
errs = append(errs, validate.Unique(ctx, op, fldPath, obj, oldObj, func(a schedulingv1alpha1.PodGroup, b schedulingv1alpha1.PodGroup) bool { return a.Name == b.Name })...)
// iterate the list and call the type's validation function
errs = append(errs, validate.EachSliceVal(ctx, op, fldPath, obj, oldObj, nil, nil, Validate_PodGroup)...)
errs = append(errs, validate.EachSliceVal(ctx, op, fldPath, obj, oldObj, func(a schedulingv1alpha1.PodGroup, b schedulingv1alpha1.PodGroup) bool { return a.Name == b.Name }, validate.SemanticDeepEqual, Validate_PodGroup)...)
return
}(fldPath.Child("podGroups"), obj.PodGroups, safe.Field(oldObj, func(oldObj *schedulingv1alpha1.WorkloadSpec) []schedulingv1alpha1.PodGroup { return oldObj.PodGroups }), oldObj != nil)...)

View File

@@ -194,6 +194,9 @@ message WorkloadSpec {
// +k8s:required
// +listType=map
// +listMapKey=name
// +k8s:listType=map
// +k8s:listMapKey=name
// +k8s:maxItems=8
repeated PodGroup podGroups = 2;
}

View File

@@ -128,6 +128,9 @@ type WorkloadSpec struct {
// +k8s:required
// +listType=map
// +listMapKey=name
// +k8s:listType=map
// +k8s:listMapKey=name
// +k8s:maxItems=8
PodGroups []PodGroup `json:"podGroups" protobuf:"bytes,2,rep,name=podGroups"`
}