From 1876c5445117ad074fb7e02b3004df33aab71d77 Mon Sep 17 00:00:00 2001 From: yongruilin Date: Thu, 5 Jun 2025 22:44:31 +0000 Subject: [PATCH 1/2] Remove unsupported map of slice validation for non-byte elements in validation-gen --- .../k8s.io/code-generator/cmd/validation-gen/validation.go | 4 ---- 1 file changed, 4 deletions(-) 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 49ac177a927..579a98fc5a7 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 @@ -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) } From 07151bb0f4cf2431afb99fbfdebdf9db5435f1f1 Mon Sep 17 00:00:00 2001 From: yongruilin Date: Mon, 9 Jun 2025 19:03:11 +0000 Subject: [PATCH 2/2] chore: Add validation error for unsupported map of slices in validation-gen This update introduces error handling for cases where a map of slices is encountered during validation. The validation process now explicitly returns an error message indicating that this type of validation is not supported, enhancing the robustness of the validation-gen tool. --- .../cmd/validation-gen/validation.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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)