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