Skip to content

Commit 850727f

Browse files
Merge pull request #120592 from AxeZhan/validation_sets
Use generic set in package "/pkg/apis/core/validation" Kubernetes-commit: 418e9d08a496964f9973ac7ce76f2db687192370
2 parents 92fa50e + 092c2b3 commit 850727f

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

pkg/api/errors/errors_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func TestNewInvalid(t *testing.T) {
164164
`Kind "name" is invalid: field[0].name: Not found: "bar"`,
165165
},
166166
{
167-
field.NotSupported(field.NewPath("field[0].name"), "bar", nil),
167+
field.NotSupported[string](field.NewPath("field[0].name"), "bar", nil),
168168
&metav1.StatusDetails{
169169
Kind: "Kind",
170170
Name: "name",

pkg/util/validation/field/errors.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,12 @@ func Invalid(field *Path, value interface{}, detail string) *Error {
200200
// NotSupported returns a *Error indicating "unsupported value".
201201
// This is used to report unknown values for enumerated fields (e.g. a list of
202202
// valid values).
203-
func NotSupported(field *Path, value interface{}, validValues []string) *Error {
203+
func NotSupported[T ~string](field *Path, value interface{}, validValues []T) *Error {
204204
detail := ""
205205
if len(validValues) > 0 {
206206
quotedValues := make([]string, len(validValues))
207207
for i, v := range validValues {
208-
quotedValues[i] = strconv.Quote(v)
208+
quotedValues[i] = strconv.Quote(fmt.Sprint(v))
209209
}
210210
detail = "supported values: " + strings.Join(quotedValues, ", ")
211211
}

pkg/util/validation/field/errors_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestMakeFuncs(t *testing.T) {
3232
ErrorTypeInvalid,
3333
},
3434
{
35-
func() *Error { return NotSupported(NewPath("f"), "v", nil) },
35+
func() *Error { return NotSupported[string](NewPath("f"), "v", nil) },
3636
ErrorTypeNotSupported,
3737
},
3838
{

0 commit comments

Comments
 (0)