Merge pull request #132138 from yongruilin/master_vg_mapofslice

Remove unsupported map of slice validation for non-byte elements in validation-gen
This commit is contained in:
Kubernetes Prow Robot
2025-06-10 22:30:55 -07:00
committed by GitHub

View File

@@ -287,10 +287,6 @@ func (td *typeDiscoverer) discoverType(t *types.Type, fldPath *field.Path) (*typ
switch elem.Kind {
case types.Pointer:
return nil, fmt.Errorf("field %s (%s): maps of pointers are not supported", fldPath.String(), t)
case types.Slice:
if unalias(elem.Elem) != types.Byte {
return nil, fmt.Errorf("field %s (%s): maps of lists are not supported", fldPath.String(), t)
}
case types.Map:
return nil, fmt.Errorf("field %s (%s): maps of maps are not supported", fldPath.String(), t)
}
@@ -416,6 +412,13 @@ func (td *typeDiscoverer) discoverType(t *types.Type, fldPath *field.Path) (*typ
} else if validations.Empty() {
klog.V(6).InfoS("no type-attached validations", "type", t)
} else {
// TODO: This check is placed here to allow map-of-slices fields to exist in the type
// system, while preventing validation on them since that functionality is not yet
// implemented. Once validation support for map-of-slices is added, this check should
// be removed.
if unalias(t).Kind == types.Map && unalias(t).Elem.Kind == types.Slice {
return nil, fmt.Errorf("field %s: validation for map of slices is not supported", fldPath)
}
klog.V(5).InfoS("found type-attached validations", "n", validations.Len(), "type", t)
thisNode.typeValidations.Add(validations)
}
@@ -588,6 +591,13 @@ func (td *typeDiscoverer) discoverStruct(thisNode *typeNode, fldPath *field.Path
klog.V(6).InfoS("no field-attached validations", "field", childPath)
} else {
klog.V(5).InfoS("found field-attached validations", "n", validations.Len(), "field", childPath)
// TODO: This check is placed here to allow map-of-slices fields to exist in the type
// system, while preventing validation on them since that functionality is not yet
// implemented. Once validation support for map-of-slices is added, this check should
// be removed.
if unalias(childType).Kind == types.Map && unalias(childType).Elem.Kind == types.Slice {
return fmt.Errorf("field %s: validation for map of slices is not supported", childPath)
}
child.fieldValidations.Add(validations)
if len(validations.Variables) > 0 {
return fmt.Errorf("%v: variable generation is not supported for field validations", childPath)