Fix field paths

This commit is contained in:
Joe Betz 2024-02-28 15:49:44 -05:00
parent 45742d1d9a
commit 61d6026d23
2 changed files with 11 additions and 11 deletions

View File

@ -808,13 +808,13 @@ func ValidateCustomResourceSelectableFields(selectableFields []apiextensions.Sel
continue
}
if path.Root().String() == "metadata" {
allErrs = append(allErrs, field.Invalid(indexFldPath, selectableField.JSONPath, "must not point to fields in metadata"))
allErrs = append(allErrs, field.Invalid(indexFldPath.Child("jsonPath"), selectableField.JSONPath, "must not point to fields in metadata"))
}
if !allowedSelectableFieldSchema(foundSchema) {
allErrs = append(allErrs, field.Invalid(indexFldPath, selectableField.JSONPath, "must point to a field of type string, boolean or integer. Enum string fields and strings with formats are allowed."))
allErrs = append(allErrs, field.Invalid(indexFldPath.Child("jsonPath"), selectableField.JSONPath, "must point to a field of type string, boolean or integer. Enum string fields and strings with formats are allowed."))
}
if uniqueSelectableFields.Has(path.String()) {
allErrs = append(allErrs, field.Duplicate(indexFldPath, selectableField.JSONPath))
allErrs = append(allErrs, field.Duplicate(indexFldPath.Child("jsonPath"), selectableField.JSONPath))
} else {
uniqueSelectableFields.Insert(path.String())
}

View File

@ -4429,9 +4429,9 @@ func TestSelectableFields(t *testing.T) {
},
},
errors: []validationMatch{
invalid("spec", "versions[0]", "selectableFields[1]"),
invalid("spec", "versions[1]", "selectableFields[0]"),
invalid("spec", "versions[1]", "selectableFields[2]"),
invalid("spec", "versions[0]", "selectableFields[1].jsonPath"),
invalid("spec", "versions[1]", "selectableFields[0].jsonPath"),
invalid("spec", "versions[1]", "selectableFields[2].jsonPath"),
},
},
{
@ -4474,7 +4474,7 @@ func TestSelectableFields(t *testing.T) {
},
},
errors: []validationMatch{
invalid("spec", "selectableFields[1]"),
invalid("spec", "selectableFields[1].jsonPath"),
},
},
{
@ -4520,8 +4520,8 @@ func TestSelectableFields(t *testing.T) {
},
},
errors: []validationMatch{
invalid("spec", "versions[0]", "selectableFields[1]"),
invalid("spec", "versions[1]", "selectableFields[0]"),
invalid("spec", "versions[0]", "selectableFields[1].jsonPath"),
invalid("spec", "versions[1]", "selectableFields[0].jsonPath"),
},
},
{
@ -4567,8 +4567,8 @@ func TestSelectableFields(t *testing.T) {
},
},
errors: []validationMatch{
duplicate("spec", "versions[0]", "selectableFields[1]"),
duplicate("spec", "versions[1]", "selectableFields[1]"),
duplicate("spec", "versions[0]", "selectableFields[1].jsonPath"),
duplicate("spec", "versions[1]", "selectableFields[1].jsonPath"),
},
},
{