diff --git a/staging/src/k8s.io/code-generator/cmd/validation-gen/validation.go b/staging/src/k8s.io/code-generator/cmd/validation-gen/validation.go index 579a98fc5a7..6c5de32f659 100644 --- a/staging/src/k8s.io/code-generator/cmd/validation-gen/validation.go +++ b/staging/src/k8s.io/code-generator/cmd/validation-gen/validation.go @@ -408,6 +408,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) } @@ -575,6 +582,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)