mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-23 10:26:22 +00:00
Add +k8s:listType, +k8s:listMapKey, and +k8s:maxItems validation tags
This commit is contained in:
@@ -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)...)
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user