Skip to content

Commit

Permalink
Use statusReason for reason under x-kubernetes-validations (#119544)
Browse files Browse the repository at this point in the history
* Change reason field format

* Auto update

* Address comments

* Auto update

* Update the test

Kubernetes-commit: 7e0a9a7f4e70e4cc6f5dd49917d18101a8e1a25c
  • Loading branch information
cici37 authored and k8s-publishing-bot committed Jul 27, 2023
1 parent 124026f commit b69767a
Show file tree
Hide file tree
Showing 20 changed files with 518 additions and 445 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.0.0-20230722025728-8a20f1bdac2d
k8s.io/apimachinery v0.0.0-20230718054246-5cb236977966
k8s.io/apiserver v0.0.0-20230722032938-62fa4fb0fe34
k8s.io/apiserver v0.0.0-20230722011324-09a47412b537
k8s.io/client-go v0.0.0-20230722030743-c5b1c13ccbed
k8s.io/code-generator v0.0.0-20230718053611-fee1cc937e21
k8s.io/component-base v0.0.0-20230718060631-a69210f80f53
Expand Down Expand Up @@ -129,7 +129,7 @@ require (
replace (
k8s.io/api => k8s.io/api v0.0.0-20230722025728-8a20f1bdac2d
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20230718054246-5cb236977966
k8s.io/apiserver => k8s.io/apiserver v0.0.0-20230722032938-62fa4fb0fe34
k8s.io/apiserver => k8s.io/apiserver v0.0.0-20230722011324-09a47412b537
k8s.io/client-go => k8s.io/client-go v0.0.0-20230722030743-c5b1c13ccbed
k8s.io/code-generator => k8s.io/code-generator v0.0.0-20230718053611-fee1cc937e21
k8s.io/component-base => k8s.io/component-base v0.0.0-20230718060631-a69210f80f53
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,8 @@ k8s.io/api v0.0.0-20230722025728-8a20f1bdac2d h1:6w7WlduDfmaXehZfmcJ3wzMw8P+2pGU
k8s.io/api v0.0.0-20230722025728-8a20f1bdac2d/go.mod h1:DlNtgYu2BX/uM/IkiPaFRqDBVazxK5ggJs19ERbMLZ4=
k8s.io/apimachinery v0.0.0-20230718054246-5cb236977966 h1:IYMQQBHbPi6jyorsuYWXB3+kJFH/MxVyLvKJH4nITrg=
k8s.io/apimachinery v0.0.0-20230718054246-5cb236977966/go.mod h1:xhQIsaL3hXneGluH+0pzF7kr+VYuLS/VcYJxF1xQf+g=
k8s.io/apiserver v0.0.0-20230722032938-62fa4fb0fe34 h1:UVX7xYPxlklUKX4I7YiMBJ7PEettc8WrzDiowak7CwA=
k8s.io/apiserver v0.0.0-20230722032938-62fa4fb0fe34/go.mod h1:9x4ACEzTJf64I3QU+MY0T7GNbOprafpdr1TM7TX3owM=
k8s.io/apiserver v0.0.0-20230722011324-09a47412b537 h1:cBKLoUlp8YuNv4PJ6ONtuQZzFBMhn9s958OKNnNV5h8=
k8s.io/apiserver v0.0.0-20230722011324-09a47412b537/go.mod h1:9x4ACEzTJf64I3QU+MY0T7GNbOprafpdr1TM7TX3owM=
k8s.io/client-go v0.0.0-20230722030743-c5b1c13ccbed h1:sZMrNhva65Tyz12Hh7r2Ky57c0CEIczpXYWUaMuTCk4=
k8s.io/client-go v0.0.0-20230722030743-c5b1c13ccbed/go.mod h1:SjV5OnUi9BbnV7fAidyJ5z6SYsJULrhITK+Wfkov6oA=
k8s.io/code-generator v0.0.0-20230718053611-fee1cc937e21 h1:PhPSo4E8juKStjMkSQsXti/5AUuElsDI8e/okOYgRg4=
Expand Down
24 changes: 20 additions & 4 deletions pkg/apis/apiextensions/types_jsonschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,24 @@ limitations under the License.

package apiextensions

import (
"k8s.io/apimachinery/pkg/util/validation/field"
// FieldValueErrorReason is a machine-readable value providing more detail about why a field failed the validation.
// +enum
type FieldValueErrorReason string

const (
// FieldValueRequired is used to report required values that are not
// provided (e.g. empty strings, null values, or empty arrays).
FieldValueRequired FieldValueErrorReason = "FieldValueRequired"
// FieldValueDuplicate is used to report collisions of values that must be
// unique (e.g. unique IDs).
FieldValueDuplicate FieldValueErrorReason = "FieldValueDuplicate"
// FieldValueInvalid is used to report malformed values (e.g. failed regex
// match, too long, out of bounds).
FieldValueInvalid FieldValueErrorReason = "FieldValueInvalid"
// FieldValueForbidden is used to report valid (as per formatting rules)
// values which would be accepted under some conditions, but which are not
// permitted by the current conditions (such as security policy).
FieldValueForbidden FieldValueErrorReason = "FieldValueForbidden"
)

// JSONSchemaProps is a JSON-Schema following Specification Draft 4 (http://json-schema.org/).
Expand Down Expand Up @@ -216,9 +232,9 @@ type ValidationRule struct {
// The HTTP status code returned to the caller will match the reason of the reason of the first failed validation rule.
// The currently supported reasons are: "FieldValueInvalid", "FieldValueForbidden", "FieldValueRequired", "FieldValueDuplicate".
// If not set, default to use "FieldValueInvalid".
// All future added reasons must be accepted by clients when reading this value.
// All future added reasons must be accepted by clients when reading this value and unknown reasons should be treated as FieldValueInvalid.
// +optional
Reason *field.ErrorType
Reason *FieldValueErrorReason
// fieldPath represents the field path returned when the validation fails.
// It must be a relative JSON path (i.e. with array notation) scoped to the location of this x-kubernetes-validations extension in the schema and refer to an existing field.
// e.g. when validation checks if a specific attribute `foo` under a map `testMap`, the fieldPath could be set to `.testMap.foo`
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/apiextensions/v1/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,8 @@ func assertEqualTypes(t *testing.T, path []string, a, b reflect.Type) {
aElemType := a.Elem()
bElemType := b.Elem()
assertEqualTypes(t, path, aElemType, bElemType)
case reflect.String:
// string types are equal

default:
fatalTypeError(t, path, a, b, "unhandled kind")
Expand Down
Loading

0 comments on commit b69767a

Please sign in to comment.