From 4c9af15a65e1f0613908cdc9009f4ca48b66f6cb Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 13 Feb 2026 18:16:58 +0000 Subject: [PATCH] Revert DV native error matcher --- .../util/validation/field/error_matcher.go | 15 ------ .../validation/field/error_matcher_test.go | 50 ------------------- .../pkg/util/validation/field/errors.go | 18 ------- 3 files changed, 83 deletions(-) diff --git a/staging/src/k8s.io/apimachinery/pkg/util/validation/field/error_matcher.go b/staging/src/k8s.io/apimachinery/pkg/util/validation/field/error_matcher.go index b874b76f1e5..4437776be69 100644 --- a/staging/src/k8s.io/apimachinery/pkg/util/validation/field/error_matcher.go +++ b/staging/src/k8s.io/apimachinery/pkg/util/validation/field/error_matcher.go @@ -44,7 +44,6 @@ type ErrorMatcher struct { matchOrigin bool matchDetail func(want, got string) bool requireOriginWhenInvalid bool - matchDeclarativeNative bool matchValidationStabilityLevel bool // normalizationRules holds the pre-compiled regex patterns for path normalization. normalizationRules []NormalizationRule @@ -88,9 +87,6 @@ func (m ErrorMatcher) Matches(want, got *Error) bool { if m.matchDetail != nil && !m.matchDetail(want.Detail, got.Detail) { return false } - if m.matchDeclarativeNative && want.DeclarativeNative != got.DeclarativeNative { - return false - } if m.matchValidationStabilityLevel && want.ValidationStabilityLevel != got.ValidationStabilityLevel { return false } @@ -157,10 +153,6 @@ func (m ErrorMatcher) Render(e *Error) string { comma() buf.WriteString(fmt.Sprintf("Detail=%q", e.Detail)) } - if m.matchDeclarativeNative { - comma() - buf.WriteString(fmt.Sprintf("DeclarativeNative=%t", e.DeclarativeNative)) - } if m.matchValidationStabilityLevel { comma() buf.WriteString(fmt.Sprintf("ValidationStabilityLevel=%s", e.ValidationStabilityLevel)) @@ -241,13 +233,6 @@ func (m ErrorMatcher) RequireOriginWhenInvalid() ErrorMatcher { return m } -// ByDeclarativeNative returns a derived ErrorMatcher which also matches by the DeclarativeNative -// value of field errors. -func (m ErrorMatcher) ByDeclarativeNative() ErrorMatcher { - m.matchDeclarativeNative = true - return m -} - // ByValidationStabilityLevel returns a derived ErrorMatcher which also matches by the validation stability level // value of field errors. func (m ErrorMatcher) ByValidationStabilityLevel() ErrorMatcher { diff --git a/staging/src/k8s.io/apimachinery/pkg/util/validation/field/error_matcher_test.go b/staging/src/k8s.io/apimachinery/pkg/util/validation/field/error_matcher_test.go index 44e51f2556e..a3527067b1f 100644 --- a/staging/src/k8s.io/apimachinery/pkg/util/validation/field/error_matcher_test.go +++ b/staging/src/k8s.io/apimachinery/pkg/util/validation/field/error_matcher_test.go @@ -303,26 +303,6 @@ func TestErrorMatcher_Matches(t *testing.T) { wantedErr: baseErr, actualErr: &Error{Type: ErrorTypeRequired, Field: "field", BadValue: "value", Detail: "detail", Origin: "origin"}, matches: false, - }, { - name: "ByDeclarativeNative: match", - matcher: ErrorMatcher{}.ByDeclarativeNative(), - wantedErr: func() *Error { - e := baseErr() - e.DeclarativeNative = true - return e - }, - actualErr: &Error{DeclarativeNative: true}, - matches: true, - }, { - name: "ByDeclarativeNative: no match", - matcher: ErrorMatcher{}.ByDeclarativeNative(), - wantedErr: func() *Error { - e := baseErr() - e.DeclarativeNative = true - return e - }, - actualErr: &Error{DeclarativeNative: false}, - matches: false, }, { name: "RequireOriginWhenInvalid: match", matcher: ErrorMatcher{}.ByOrigin().RequireOriginWhenInvalid(), @@ -426,17 +406,6 @@ func TestErrorMatcher_Test(t *testing.T) { want: ErrorList{Invalid(NewPath("f").Index(0).Child("x", "a"), nil, "")}, got: ErrorList{Invalid(NewPath("f").Index(1).Child("a"), "v", "d")}, expectedErrors: []string{"expected an error matching:", "unmatched error:"}, - }, { - name: "declarative native: match", - matcher: ErrorMatcher{}.ByDeclarativeNative(), - want: ErrorList{{DeclarativeNative: true}}, - got: ErrorList{{DeclarativeNative: true}}, - }, { - name: "declarative native: no match", - matcher: ErrorMatcher{}.ByDeclarativeNative(), - want: ErrorList{{DeclarativeNative: true}}, - got: ErrorList{{DeclarativeNative: false}}, - expectedErrors: []string{"expected an error matching:", "unmatched error:"}, }, { name: "validation level: match", matcher: ErrorMatcher{}.ByValidationStabilityLevel(), @@ -575,25 +544,6 @@ func TestErrorMatcher_Render(t *testing.T) { expected: `{Field="f[0].x.a"}`, }, { - name: "with covered by declarative", - matcher: ErrorMatcher{}.ByDeclarativeNative(), - err: func() *Error { - e := Invalid(NewPath("field"), "value", "detail") - e.DeclarativeNative = true - return e - }(), - expected: `{DeclarativeNative=true}`, - }, - { - name: "all fields with covered by declarative", - matcher: ErrorMatcher{}.ByType().ByField().ByValue().ByOrigin().ByDetailExact().ByDeclarativeNative(), - err: func() *Error { - e := Invalid(NewPath("field"), "value", "detail").WithOrigin("origin") - e.DeclarativeNative = true - return e - }(), - expected: `{Type="Invalid value", Field="field", Value="value", Origin="origin", Detail="detail", DeclarativeNative=true}`, - }, { name: "requireOriginWhenInvalid with origin", matcher: ErrorMatcher{}.ByOrigin().RequireOriginWhenInvalid(), err: Invalid(NewPath("field"), "value", "detail").WithOrigin("origin"), diff --git a/staging/src/k8s.io/apimachinery/pkg/util/validation/field/errors.go b/staging/src/k8s.io/apimachinery/pkg/util/validation/field/errors.go index d44bb0e6088..d84894a418e 100644 --- a/staging/src/k8s.io/apimachinery/pkg/util/validation/field/errors.go +++ b/staging/src/k8s.io/apimachinery/pkg/util/validation/field/errors.go @@ -56,10 +56,6 @@ type Error struct { // that should also be caught by declarative validation. CoveredByDeclarative bool - // DeclarativeNative is true when this error originates from a declarative-native validation. - // This field is used to distinguish errors that are exclusively declarative and lack an imperative counterpart. - DeclarativeNative bool - // ValidationStabilityLevel denotes the validation stability level of the declarative validation from this error is returned. This should be used in the declarative validations only. ValidationStabilityLevel ValidationStabilityLevel } @@ -484,20 +480,6 @@ func (list ErrorList) ExtractCoveredByDeclarative() ErrorList { return newList } -// MarkDeclarativeNative marks the error as originating from a declarative-native validation. -func (e *Error) MarkDeclarativeNative() *Error { - e.DeclarativeNative = true - return e -} - -// MarkDeclarativeNative marks all errors in the list as originating from declarative-native validations. -func (list ErrorList) MarkDeclarativeNative() ErrorList { - for _, err := range list { - err.DeclarativeNative = true - } - return list -} - // MarkAlpha marks the error as an alpha validation error. func (e *Error) MarkAlpha() *Error { e.ValidationStabilityLevel = stabilityLevelAlpha