Address feedback: simpliy errormatcher instantiation

This commit is contained in:
yongruilin
2025-10-06 16:41:10 +00:00
parent 6138a68f4e
commit 6965075ebd
2 changed files with 2 additions and 12 deletions

View File

@@ -235,12 +235,7 @@ func verifyValidationEquivalence(t *testing.T, expectedErrs field.ErrorList, run
var imperativeErrs field.ErrorList
// The errOutputMatcher is used to verify the output matches the expected errors in test cases.
errOutputMatcher := field.ErrorMatcher{}.ByType().ByOrigin()
if len(opt.NormalizationRules) > 0 {
errOutputMatcher = errOutputMatcher.ByFieldNormalized(opt.NormalizationRules)
} else {
errOutputMatcher = errOutputMatcher.ByField()
}
errOutputMatcher := field.ErrorMatcher{}.ByType().ByOrigin().ByFieldNormalized(opt.NormalizationRules)
// We only need to test both gate enabled and disabled together, because
// 1) the DeclarativeValidationTakeover won't take effect if DeclarativeValidation is disabled.

View File

@@ -179,12 +179,7 @@ func gatherDeclarativeValidationMismatches(imperativeErrs, declarativeErrs field
if takeover {
recommendation = "Consider disabling the DeclarativeValidationTakeover feature gate to keep data persisted in etcd consistent with prior versions of Kubernetes."
}
fuzzyMatcher := field.ErrorMatcher{}.ByType().ByOrigin().RequireOriginWhenInvalid()
if len(normalizationRules) > 0 {
fuzzyMatcher = fuzzyMatcher.ByFieldNormalized(normalizationRules)
} else {
fuzzyMatcher = fuzzyMatcher.ByField()
}
fuzzyMatcher := field.ErrorMatcher{}.ByType().ByOrigin().RequireOriginWhenInvalid().ByFieldNormalized(normalizationRules)
exactMatcher := field.ErrorMatcher{}.Exactly()
// Dedupe imperative errors of exact error matches as they are