Add comment for the reason behind not checking empty or too-long names

Signed-off-by: Heba Elayoty <heelayot@microsoft.com>
This commit is contained in:
Heba Elayoty
2026-01-13 13:44:59 -08:00
parent 24c161307f
commit 63708d84dc
2 changed files with 4 additions and 2 deletions

View File

@@ -23,7 +23,6 @@ import (
"k8s.io/apimachinery/pkg/api/operation"
"k8s.io/apimachinery/pkg/api/validate/content"
"k8s.io/apimachinery/pkg/api/validation/path"
"k8s.io/apimachinery/pkg/util/validation/field"
)
@@ -145,7 +144,7 @@ func PathSegmentName[T ~string](_ context.Context, op operation.Operation, fldPa
return nil
}
var allErrs field.ErrorList
for _, msg := range path.IsValidPathSegmentName((string)(*value)) {
for _, msg := range content.IsPathSegmentName((string)(*value)) {
allErrs = append(allErrs, field.Invalid(fldPath, *value, msg).WithOrigin("format=k8s-path-segment-name"))
}
return allErrs

View File

@@ -416,6 +416,9 @@ func TestPathSegmentName(t *testing.T) {
ctx := context.Background()
fldPath := field.NewPath("test")
// This format validator does not check for empty strings or max length,
// only checks path-segment-unsafe characters. Those constraints are
// handled by separate validators (Required, maxLength) in the schema.
testCases := []struct {
name string
input string