drop Enabled() checks for ServerSideFieldValidation feature gate
Kubernetes-commit: 2d5ceb9b15347b8bb5af360470b6346370157042
This commit is contained in:
parent
3e03fc3433
commit
c40024ba00
|
|
@ -72,10 +72,7 @@ import (
|
|||
"k8s.io/apiserver/pkg/endpoints/handlers/responsewriters"
|
||||
"k8s.io/apiserver/pkg/endpoints/request"
|
||||
genericapitesting "k8s.io/apiserver/pkg/endpoints/testing"
|
||||
"k8s.io/apiserver/pkg/features"
|
||||
"k8s.io/apiserver/pkg/registry/rest"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
featuregatetesting "k8s.io/component-base/featuregate/testing"
|
||||
)
|
||||
|
||||
type alwaysMutatingDeny struct{}
|
||||
|
|
@ -4041,7 +4038,6 @@ var (
|
|||
|
||||
// TestFieldValidation tests the create, update, and patch handlers for correctness when faced with field validation errors.
|
||||
func TestFieldValidation(t *testing.T) {
|
||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ServerSideFieldValidation, true)()
|
||||
var (
|
||||
strictDecodingErr = `strict decoding error: duplicate field \"other\", unknown field \"unknown\"`
|
||||
strictDecodingWarns = []string{`duplicate field "other"`, `unknown field "unknown"`}
|
||||
|
|
@ -4180,7 +4176,6 @@ unknown: baz`)
|
|||
// BenchmarkFieldValidation benchmarks the create, update, and patch handlers for performance distinctions between
|
||||
// strict, warn, and ignore field validation handling.
|
||||
func BenchmarkFieldValidation(b *testing.B) {
|
||||
defer featuregatetesting.SetFeatureGateDuringTest(b, utilfeature.DefaultFeatureGate, features.ServerSideFieldValidation, true)()
|
||||
var (
|
||||
validJSONDataPost = []byte(`{"kind":"Simple", "apiVersion":"test.group/version", "metadata":{"creationTimestamp":null}, "other":"foo"}`)
|
||||
validYAMLDataPost = []byte(`apiVersion: test.group/version
|
||||
|
|
|
|||
|
|
@ -45,9 +45,7 @@ import (
|
|||
"k8s.io/apiserver/pkg/endpoints/handlers/responsewriters"
|
||||
"k8s.io/apiserver/pkg/endpoints/metrics"
|
||||
"k8s.io/apiserver/pkg/endpoints/request"
|
||||
"k8s.io/apiserver/pkg/features"
|
||||
"k8s.io/apiserver/pkg/registry/rest"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
"k8s.io/apiserver/pkg/warning"
|
||||
)
|
||||
|
||||
|
|
@ -406,13 +404,10 @@ func isDryRun(url *url.URL) bool {
|
|||
|
||||
// fieldValidation checks that the field validation feature is enabled
|
||||
// and returns a valid directive of either
|
||||
// - Ignore (default when feature is disabled)
|
||||
// - Warn (default when feature is enabled)
|
||||
// - Ignore
|
||||
// - Warn (default)
|
||||
// - Strict
|
||||
func fieldValidation(directive string) string {
|
||||
if !utilfeature.DefaultFeatureGate.Enabled(features.ServerSideFieldValidation) {
|
||||
return metav1.FieldValidationIgnore
|
||||
}
|
||||
if directive == "" {
|
||||
return metav1.FieldValidationWarn
|
||||
}
|
||||
|
|
|
|||
|
|
@ -622,11 +622,6 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
|
|||
}
|
||||
}
|
||||
|
||||
var disabledParams []string
|
||||
if !utilfeature.DefaultFeatureGate.Enabled(features.ServerSideFieldValidation) {
|
||||
disabledParams = []string{"fieldValidation"}
|
||||
}
|
||||
|
||||
// Create Routes for the actions.
|
||||
// TODO: Add status documentation using Returns()
|
||||
// Errors (see api/errors/errors.go as well as go-restful router):
|
||||
|
|
@ -857,7 +852,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
|
|||
Returns(http.StatusCreated, "Created", producedObject).
|
||||
Reads(defaultVersionedObject).
|
||||
Writes(producedObject)
|
||||
if err := AddObjectParams(ws, route, versionedUpdateOptions, disabledParams...); err != nil {
|
||||
if err := AddObjectParams(ws, route, versionedUpdateOptions); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
addParams(route, action.Params)
|
||||
|
|
@ -886,7 +881,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
|
|||
Returns(http.StatusCreated, "Created", producedObject).
|
||||
Reads(metav1.Patch{}).
|
||||
Writes(producedObject)
|
||||
if err := AddObjectParams(ws, route, versionedPatchOptions, disabledParams...); err != nil {
|
||||
if err := AddObjectParams(ws, route, versionedPatchOptions); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
addParams(route, action.Params)
|
||||
|
|
@ -917,7 +912,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
|
|||
Returns(http.StatusAccepted, "Accepted", producedObject).
|
||||
Reads(defaultVersionedObject).
|
||||
Writes(producedObject)
|
||||
if err := AddObjectParams(ws, route, versionedCreateOptions, disabledParams...); err != nil {
|
||||
if err := AddObjectParams(ws, route, versionedCreateOptions); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
addParams(route, action.Params)
|
||||
|
|
|
|||
|
|
@ -33,8 +33,6 @@ import (
|
|||
"k8s.io/apiserver/pkg/authentication/user"
|
||||
"k8s.io/apiserver/pkg/endpoints/request"
|
||||
"k8s.io/apiserver/pkg/endpoints/responsewriter"
|
||||
"k8s.io/apiserver/pkg/features"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
compbasemetrics "k8s.io/component-base/metrics"
|
||||
"k8s.io/component-base/metrics/legacyregistry"
|
||||
)
|
||||
|
|
@ -136,7 +134,7 @@ var (
|
|||
fieldValidationRequestLatencies = compbasemetrics.NewHistogramVec(
|
||||
&compbasemetrics.HistogramOpts{
|
||||
Name: "field_validation_request_duration_seconds",
|
||||
Help: "Response latency distribution in seconds for each field validation value and whether field validation is enabled or not",
|
||||
Help: "Response latency distribution in seconds for each field validation value",
|
||||
// This metric is supplementary to the requestLatencies metric.
|
||||
// It measures request durations for the various field validation
|
||||
// values.
|
||||
|
|
@ -144,7 +142,7 @@ var (
|
|||
4, 5, 6, 8, 10, 15, 20, 30, 45, 60},
|
||||
StabilityLevel: compbasemetrics.ALPHA,
|
||||
},
|
||||
[]string{"field_validation", "enabled"},
|
||||
[]string{"field_validation"},
|
||||
)
|
||||
responseSizes = compbasemetrics.NewHistogramVec(
|
||||
&compbasemetrics.HistogramOpts{
|
||||
|
|
@ -543,8 +541,7 @@ func MonitorRequest(req *http.Request, verb, group, version, resource, subresour
|
|||
}
|
||||
requestLatencies.WithContext(req.Context()).WithLabelValues(reportedVerb, dryRun, group, version, resource, subresource, scope, component).Observe(elapsedSeconds)
|
||||
fieldValidation := cleanFieldValidation(req.URL)
|
||||
fieldValidationEnabled := strconv.FormatBool(utilfeature.DefaultFeatureGate.Enabled(features.ServerSideFieldValidation))
|
||||
fieldValidationRequestLatencies.WithContext(req.Context()).WithLabelValues(fieldValidation, fieldValidationEnabled)
|
||||
fieldValidationRequestLatencies.WithContext(req.Context()).WithLabelValues(fieldValidation)
|
||||
|
||||
if wd, ok := request.LatencyTrackersFrom(req.Context()); ok {
|
||||
sliLatency := elapsedSeconds - (wd.MutatingWebhookTracker.GetLatency() + wd.ValidatingWebhookTracker.GetLatency()).Seconds()
|
||||
|
|
|
|||
Loading…
Reference in New Issue