Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
9dfdb6a2
Commit
9dfdb6a2
authored
Feb 06, 2019
by
Chao Xu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding a limit on the maximum bytes accepted to be decoded in a resource write request.
parent
bf758470
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
109 additions
and
9 deletions
+109
-9
options_test.go
cmd/kube-apiserver/app/options/options_test.go
+1
-0
errors.go
staging/src/k8s.io/apimachinery/pkg/api/errors/errors.go
+24
-0
types.go
staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/types.go
+4
-0
groupversion.go
staging/src/k8s.io/apiserver/pkg/endpoints/groupversion.go
+4
-0
create.go
...ing/src/k8s.io/apiserver/pkg/endpoints/handlers/create.go
+1
-1
delete.go
...ing/src/k8s.io/apiserver/pkg/endpoints/handlers/delete.go
+2
-2
patch.go
staging/src/k8s.io/apiserver/pkg/endpoints/handlers/patch.go
+1
-1
rest.go
staging/src/k8s.io/apiserver/pkg/endpoints/handlers/rest.go
+19
-2
update.go
...ing/src/k8s.io/apiserver/pkg/endpoints/handlers/update.go
+1
-1
installer.go
staging/src/k8s.io/apiserver/pkg/endpoints/installer.go
+2
-0
config.go
staging/src/k8s.io/apiserver/pkg/server/config.go
+11
-1
genericapiserver.go
staging/src/k8s.io/apiserver/pkg/server/genericapiserver.go
+5
-0
server_run_options.go
...k8s.io/apiserver/pkg/server/options/server_run_options.go
+12
-1
server_run_options_test.go
...o/apiserver/pkg/server/options/server_run_options_test.go
+22
-0
No files found.
cmd/kube-apiserver/app/options/options_test.go
View file @
9dfdb6a2
...
@@ -130,6 +130,7 @@ func TestAddFlags(t *testing.T) {
...
@@ -130,6 +130,7 @@ func TestAddFlags(t *testing.T) {
RequestTimeout
:
time
.
Duration
(
2
)
*
time
.
Minute
,
RequestTimeout
:
time
.
Duration
(
2
)
*
time
.
Minute
,
MinRequestTimeout
:
1800
,
MinRequestTimeout
:
1800
,
JSONPatchMaxCopyBytes
:
int64
(
10
*
1024
*
1024
),
JSONPatchMaxCopyBytes
:
int64
(
10
*
1024
*
1024
),
MaxRequestBodyBytes
:
int64
(
10
*
1024
*
1024
),
},
},
Admission
:
&
kubeoptions
.
AdmissionOptions
{
Admission
:
&
kubeoptions
.
AdmissionOptions
{
GenericAdmission
:
&
apiserveroptions
.
AdmissionOptions
{
GenericAdmission
:
&
apiserveroptions
.
AdmissionOptions
{
...
...
staging/src/k8s.io/apimachinery/pkg/api/errors/errors.go
View file @
9dfdb6a2
...
@@ -341,6 +341,17 @@ func NewTooManyRequestsError(message string) *StatusError {
...
@@ -341,6 +341,17 @@ func NewTooManyRequestsError(message string) *StatusError {
}}
}}
}
}
// NewRequestEntityTooLargeError returns an error indicating that the request
// entity was too large.
func
NewRequestEntityTooLargeError
(
message
string
)
*
StatusError
{
return
&
StatusError
{
metav1
.
Status
{
Status
:
metav1
.
StatusFailure
,
Code
:
http
.
StatusRequestEntityTooLarge
,
Reason
:
metav1
.
StatusReasonRequestEntityTooLarge
,
Message
:
fmt
.
Sprintf
(
"Request entity too large: %s"
,
message
),
}}
}
// NewGenericServerResponse returns a new error for server responses that are not in a recognizable form.
// NewGenericServerResponse returns a new error for server responses that are not in a recognizable form.
func
NewGenericServerResponse
(
code
int
,
verb
string
,
qualifiedResource
schema
.
GroupResource
,
name
,
serverMessage
string
,
retryAfterSeconds
int
,
isUnexpectedResponse
bool
)
*
StatusError
{
func
NewGenericServerResponse
(
code
int
,
verb
string
,
qualifiedResource
schema
.
GroupResource
,
name
,
serverMessage
string
,
retryAfterSeconds
int
,
isUnexpectedResponse
bool
)
*
StatusError
{
reason
:=
metav1
.
StatusReasonUnknown
reason
:=
metav1
.
StatusReasonUnknown
...
@@ -527,6 +538,19 @@ func IsTooManyRequests(err error) bool {
...
@@ -527,6 +538,19 @@ func IsTooManyRequests(err error) bool {
return
false
return
false
}
}
// IsRequestEntityTooLargeError determines if err is an error which indicates
// the request entity is too large.
func
IsRequestEntityTooLargeError
(
err
error
)
bool
{
if
ReasonForError
(
err
)
==
metav1
.
StatusReasonRequestEntityTooLarge
{
return
true
}
switch
t
:=
err
.
(
type
)
{
case
APIStatus
:
return
t
.
Status
()
.
Code
==
http
.
StatusRequestEntityTooLarge
}
return
false
}
// IsUnexpectedServerError returns true if the server response was not in the expected API format,
// IsUnexpectedServerError returns true if the server response was not in the expected API format,
// and may be the result of another HTTP actor.
// and may be the result of another HTTP actor.
func
IsUnexpectedServerError
(
err
error
)
bool
{
func
IsUnexpectedServerError
(
err
error
)
bool
{
...
...
staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/types.go
View file @
9dfdb6a2
...
@@ -713,6 +713,10 @@ const (
...
@@ -713,6 +713,10 @@ const (
// Status code 406
// Status code 406
StatusReasonNotAcceptable
StatusReason
=
"NotAcceptable"
StatusReasonNotAcceptable
StatusReason
=
"NotAcceptable"
// StatusReasonRequestEntityTooLarge means that the request entity is too large.
// Status code 413
StatusReasonRequestEntityTooLarge
StatusReason
=
"RequestEntityTooLarge"
// StatusReasonUnsupportedMediaType means that the content type sent by the client is not acceptable
// StatusReasonUnsupportedMediaType means that the content type sent by the client is not acceptable
// to the server - for instance, attempting to send protobuf for a resource that supports only json and yaml.
// to the server - for instance, attempting to send protobuf for a resource that supports only json and yaml.
// API calls that return UnsupportedMediaType can never succeed.
// API calls that return UnsupportedMediaType can never succeed.
...
...
staging/src/k8s.io/apiserver/pkg/endpoints/groupversion.go
View file @
9dfdb6a2
...
@@ -87,6 +87,10 @@ type APIGroupVersion struct {
...
@@ -87,6 +87,10 @@ type APIGroupVersion struct {
// OpenAPIModels exposes the OpenAPI models to each individual handler.
// OpenAPIModels exposes the OpenAPI models to each individual handler.
OpenAPIModels
openapiproto
.
Models
OpenAPIModels
openapiproto
.
Models
// The limit on the request body size that would be accepted and decoded in a write request.
// 0 means no limit.
MaxRequestBodyBytes
int64
}
}
// InstallREST registers the REST handlers (storage, watch, proxy and redirect) into a restful Container.
// InstallREST registers the REST handlers (storage, watch, proxy and redirect) into a restful Container.
...
...
staging/src/k8s.io/apiserver/pkg/endpoints/handlers/create.go
View file @
9dfdb6a2
...
@@ -79,7 +79,7 @@ func createHandler(r rest.NamedCreater, scope RequestScope, admit admission.Inte
...
@@ -79,7 +79,7 @@ func createHandler(r rest.NamedCreater, scope RequestScope, admit admission.Inte
}
}
decoder
:=
scope
.
Serializer
.
DecoderToVersion
(
s
.
Serializer
,
scope
.
HubGroupVersion
)
decoder
:=
scope
.
Serializer
.
DecoderToVersion
(
s
.
Serializer
,
scope
.
HubGroupVersion
)
body
,
err
:=
readBody
(
req
)
body
,
err
:=
limitedReadBody
(
req
,
scope
.
MaxRequestBodyBytes
)
if
err
!=
nil
{
if
err
!=
nil
{
scope
.
err
(
err
,
w
,
req
)
scope
.
err
(
err
,
w
,
req
)
return
return
...
...
staging/src/k8s.io/apiserver/pkg/endpoints/handlers/delete.go
View file @
9dfdb6a2
...
@@ -66,7 +66,7 @@ func DeleteResource(r rest.GracefulDeleter, allowsOptions bool, scope RequestSco
...
@@ -66,7 +66,7 @@ func DeleteResource(r rest.GracefulDeleter, allowsOptions bool, scope RequestSco
options
:=
&
metav1
.
DeleteOptions
{}
options
:=
&
metav1
.
DeleteOptions
{}
if
allowsOptions
{
if
allowsOptions
{
body
,
err
:=
readBody
(
req
)
body
,
err
:=
limitedReadBody
(
req
,
scope
.
MaxRequestBodyBytes
)
if
err
!=
nil
{
if
err
!=
nil
{
scope
.
err
(
err
,
w
,
req
)
scope
.
err
(
err
,
w
,
req
)
return
return
...
@@ -227,7 +227,7 @@ func DeleteCollection(r rest.CollectionDeleter, checkBody bool, scope RequestSco
...
@@ -227,7 +227,7 @@ func DeleteCollection(r rest.CollectionDeleter, checkBody bool, scope RequestSco
options
:=
&
metav1
.
DeleteOptions
{}
options
:=
&
metav1
.
DeleteOptions
{}
if
checkBody
{
if
checkBody
{
body
,
err
:=
readBody
(
req
)
body
,
err
:=
limitedReadBody
(
req
,
scope
.
MaxRequestBodyBytes
)
if
err
!=
nil
{
if
err
!=
nil
{
scope
.
err
(
err
,
w
,
req
)
scope
.
err
(
err
,
w
,
req
)
return
return
...
...
staging/src/k8s.io/apiserver/pkg/endpoints/handlers/patch.go
View file @
9dfdb6a2
...
@@ -88,7 +88,7 @@ func PatchResource(r rest.Patcher, scope RequestScope, admit admission.Interface
...
@@ -88,7 +88,7 @@ func PatchResource(r rest.Patcher, scope RequestScope, admit admission.Interface
ctx
:=
req
.
Context
()
ctx
:=
req
.
Context
()
ctx
=
request
.
WithNamespace
(
ctx
,
namespace
)
ctx
=
request
.
WithNamespace
(
ctx
,
namespace
)
patchJS
,
err
:=
readBody
(
req
)
patchJS
,
err
:=
limitedReadBody
(
req
,
scope
.
MaxRequestBodyBytes
)
if
err
!=
nil
{
if
err
!=
nil
{
scope
.
err
(
err
,
w
,
req
)
scope
.
err
(
err
,
w
,
req
)
return
return
...
...
staging/src/k8s.io/apiserver/pkg/endpoints/handlers/rest.go
View file @
9dfdb6a2
...
@@ -20,6 +20,7 @@ import (
...
@@ -20,6 +20,7 @@ import (
"context"
"context"
"encoding/hex"
"encoding/hex"
"fmt"
"fmt"
"io"
"io/ioutil"
"io/ioutil"
"net/http"
"net/http"
"net/url"
"net/url"
...
@@ -71,6 +72,8 @@ type RequestScope struct {
...
@@ -71,6 +72,8 @@ type RequestScope struct {
// HubGroupVersion indicates what version objects read from etcd or incoming requests should be converted to for in-memory handling.
// HubGroupVersion indicates what version objects read from etcd or incoming requests should be converted to for in-memory handling.
HubGroupVersion
schema
.
GroupVersion
HubGroupVersion
schema
.
GroupVersion
MaxRequestBodyBytes
int64
}
}
func
(
scope
*
RequestScope
)
err
(
err
error
,
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
func
(
scope
*
RequestScope
)
err
(
err
error
,
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
...
@@ -324,9 +327,23 @@ func summarizeData(data []byte, maxLength int) string {
...
@@ -324,9 +327,23 @@ func summarizeData(data []byte, maxLength int) string {
}
}
}
}
func
readBody
(
req
*
http
.
Request
)
([]
byte
,
error
)
{
func
limitedReadBody
(
req
*
http
.
Request
,
limit
int64
)
([]
byte
,
error
)
{
defer
req
.
Body
.
Close
()
defer
req
.
Body
.
Close
()
return
ioutil
.
ReadAll
(
req
.
Body
)
if
limit
<=
0
{
return
ioutil
.
ReadAll
(
req
.
Body
)
}
lr
:=
&
io
.
LimitedReader
{
R
:
req
.
Body
,
N
:
limit
+
1
,
}
data
,
err
:=
ioutil
.
ReadAll
(
lr
)
if
err
!=
nil
{
return
nil
,
err
}
if
lr
.
N
<=
0
{
return
nil
,
errors
.
NewRequestEntityTooLargeError
(
fmt
.
Sprintf
(
"limit is %d"
,
limit
))
}
return
data
,
nil
}
}
func
parseTimeout
(
str
string
)
time
.
Duration
{
func
parseTimeout
(
str
string
)
time
.
Duration
{
...
...
staging/src/k8s.io/apiserver/pkg/endpoints/handlers/update.go
View file @
9dfdb6a2
...
@@ -64,7 +64,7 @@ func UpdateResource(r rest.Updater, scope RequestScope, admit admission.Interfac
...
@@ -64,7 +64,7 @@ func UpdateResource(r rest.Updater, scope RequestScope, admit admission.Interfac
ctx
:=
req
.
Context
()
ctx
:=
req
.
Context
()
ctx
=
request
.
WithNamespace
(
ctx
,
namespace
)
ctx
=
request
.
WithNamespace
(
ctx
,
namespace
)
body
,
err
:=
readBody
(
req
)
body
,
err
:=
limitedReadBody
(
req
,
scope
.
MaxRequestBodyBytes
)
if
err
!=
nil
{
if
err
!=
nil
{
scope
.
err
(
err
,
w
,
req
)
scope
.
err
(
err
,
w
,
req
)
return
return
...
...
staging/src/k8s.io/apiserver/pkg/endpoints/installer.go
View file @
9dfdb6a2
...
@@ -505,6 +505,8 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
...
@@ -505,6 +505,8 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
HubGroupVersion
:
schema
.
GroupVersion
{
Group
:
fqKindToRegister
.
Group
,
Version
:
runtime
.
APIVersionInternal
},
HubGroupVersion
:
schema
.
GroupVersion
{
Group
:
fqKindToRegister
.
Group
,
Version
:
runtime
.
APIVersionInternal
},
MetaGroupVersion
:
metav1
.
SchemeGroupVersion
,
MetaGroupVersion
:
metav1
.
SchemeGroupVersion
,
MaxRequestBodyBytes
:
a
.
group
.
MaxRequestBodyBytes
,
}
}
if
a
.
group
.
MetaGroupVersion
!=
nil
{
if
a
.
group
.
MetaGroupVersion
!=
nil
{
reqScope
.
MetaGroupVersion
=
*
a
.
group
.
MetaGroupVersion
reqScope
.
MetaGroupVersion
=
*
a
.
group
.
MetaGroupVersion
...
...
staging/src/k8s.io/apiserver/pkg/server/config.go
View file @
9dfdb6a2
...
@@ -163,6 +163,9 @@ type Config struct {
...
@@ -163,6 +163,9 @@ type Config struct {
// patch may cause.
// patch may cause.
// This affects all places that applies json patch in the binary.
// This affects all places that applies json patch in the binary.
JSONPatchMaxCopyBytes
int64
JSONPatchMaxCopyBytes
int64
// The limit on the request body size that would be accepted and decoded in a write request.
// 0 means no limit.
MaxRequestBodyBytes
int64
// MaxRequestsInFlight is the maximum number of parallel non-long-running requests. Every further
// MaxRequestsInFlight is the maximum number of parallel non-long-running requests. Every further
// request has to wait. Applies only to non-mutating requests.
// request has to wait. Applies only to non-mutating requests.
MaxRequestsInFlight
int
MaxRequestsInFlight
int
...
@@ -272,7 +275,13 @@ func NewConfig(codecs serializer.CodecFactory) *Config {
...
@@ -272,7 +275,13 @@ func NewConfig(codecs serializer.CodecFactory) *Config {
// on the size increase the "copy" operations in a json patch
// on the size increase the "copy" operations in a json patch
// can cause. See
// can cause. See
// https://github.com/etcd-io/etcd/blob/release-3.3/etcdserver/server.go#L90.
// https://github.com/etcd-io/etcd/blob/release-3.3/etcdserver/server.go#L90.
JSONPatchMaxCopyBytes
:
int64
(
10
*
1024
*
1024
),
JSONPatchMaxCopyBytes
:
int64
(
10
*
1024
*
1024
),
// 10MB is the recommended maximum client request size in bytes
// the etcd server should accept. Thus, we set it as the
// maximum bytes accepted to be decoded in a resource write
// request. See
// https://github.com/etcd-io/etcd/blob/release-3.3/etcdserver/server.go#L90.
MaxRequestBodyBytes
:
int64
(
10
*
1024
*
1024
),
EnableAPIResponseCompression
:
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
APIResponseCompression
),
EnableAPIResponseCompression
:
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
APIResponseCompression
),
// Default to treating watch as a long-running operation
// Default to treating watch as a long-running operation
...
@@ -490,6 +499,7 @@ func (c completedConfig) New(name string, delegationTarget DelegationTarget) (*G
...
@@ -490,6 +499,7 @@ func (c completedConfig) New(name string, delegationTarget DelegationTarget) (*G
DiscoveryGroupManager
:
discovery
.
NewRootAPIsHandler
(
c
.
DiscoveryAddresses
,
c
.
Serializer
),
DiscoveryGroupManager
:
discovery
.
NewRootAPIsHandler
(
c
.
DiscoveryAddresses
,
c
.
Serializer
),
enableAPIResponseCompression
:
c
.
EnableAPIResponseCompression
,
enableAPIResponseCompression
:
c
.
EnableAPIResponseCompression
,
maxRequestBodyBytes
:
c
.
MaxRequestBodyBytes
,
}
}
for
{
for
{
...
...
staging/src/k8s.io/apiserver/pkg/server/genericapiserver.go
View file @
9dfdb6a2
...
@@ -158,6 +158,10 @@ type GenericAPIServer struct {
...
@@ -158,6 +158,10 @@ type GenericAPIServer struct {
// HandlerChainWaitGroup allows you to wait for all chain handlers finish after the server shutdown.
// HandlerChainWaitGroup allows you to wait for all chain handlers finish after the server shutdown.
HandlerChainWaitGroup
*
utilwaitgroup
.
SafeWaitGroup
HandlerChainWaitGroup
*
utilwaitgroup
.
SafeWaitGroup
// The limit on the request body size that would be accepted and decoded in a write request.
// 0 means no limit.
maxRequestBodyBytes
int64
}
}
// DelegationTarget is an interface which allows for composition of API servers with top level handling that works
// DelegationTarget is an interface which allows for composition of API servers with top level handling that works
...
@@ -340,6 +344,7 @@ func (s *GenericAPIServer) installAPIResources(apiPrefix string, apiGroupInfo *A
...
@@ -340,6 +344,7 @@ func (s *GenericAPIServer) installAPIResources(apiPrefix string, apiGroupInfo *A
apiGroupVersion
.
OptionsExternalVersion
=
apiGroupInfo
.
OptionsExternalVersion
apiGroupVersion
.
OptionsExternalVersion
=
apiGroupInfo
.
OptionsExternalVersion
}
}
apiGroupVersion
.
OpenAPIModels
=
openAPIGroupModels
apiGroupVersion
.
OpenAPIModels
=
openAPIGroupModels
apiGroupVersion
.
MaxRequestBodyBytes
=
s
.
maxRequestBodyBytes
if
err
:=
apiGroupVersion
.
InstallREST
(
s
.
Handler
.
GoRestfulContainer
);
err
!=
nil
{
if
err
:=
apiGroupVersion
.
InstallREST
(
s
.
Handler
.
GoRestfulContainer
);
err
!=
nil
{
return
fmt
.
Errorf
(
"unable to setup API %v: %v"
,
apiGroupInfo
,
err
)
return
fmt
.
Errorf
(
"unable to setup API %v: %v"
,
apiGroupInfo
,
err
)
...
...
staging/src/k8s.io/apiserver/pkg/server/options/server_run_options.go
View file @
9dfdb6a2
...
@@ -45,7 +45,12 @@ type ServerRunOptions struct {
...
@@ -45,7 +45,12 @@ type ServerRunOptions struct {
// We intentionally did not add a flag for this option. Users of the
// We intentionally did not add a flag for this option. Users of the
// apiserver library can wire it to a flag.
// apiserver library can wire it to a flag.
JSONPatchMaxCopyBytes
int64
JSONPatchMaxCopyBytes
int64
TargetRAMMB
int
// The limit on the request body size that would be accepted and
// decoded in a write request. 0 means no limit.
// We intentionally did not add a flag for this option. Users of the
// apiserver library can wire it to a flag.
MaxRequestBodyBytes
int64
TargetRAMMB
int
}
}
func
NewServerRunOptions
()
*
ServerRunOptions
{
func
NewServerRunOptions
()
*
ServerRunOptions
{
...
@@ -56,6 +61,7 @@ func NewServerRunOptions() *ServerRunOptions {
...
@@ -56,6 +61,7 @@ func NewServerRunOptions() *ServerRunOptions {
RequestTimeout
:
defaults
.
RequestTimeout
,
RequestTimeout
:
defaults
.
RequestTimeout
,
MinRequestTimeout
:
defaults
.
MinRequestTimeout
,
MinRequestTimeout
:
defaults
.
MinRequestTimeout
,
JSONPatchMaxCopyBytes
:
defaults
.
JSONPatchMaxCopyBytes
,
JSONPatchMaxCopyBytes
:
defaults
.
JSONPatchMaxCopyBytes
,
MaxRequestBodyBytes
:
defaults
.
MaxRequestBodyBytes
,
}
}
}
}
...
@@ -68,6 +74,7 @@ func (s *ServerRunOptions) ApplyTo(c *server.Config) error {
...
@@ -68,6 +74,7 @@ func (s *ServerRunOptions) ApplyTo(c *server.Config) error {
c
.
RequestTimeout
=
s
.
RequestTimeout
c
.
RequestTimeout
=
s
.
RequestTimeout
c
.
MinRequestTimeout
=
s
.
MinRequestTimeout
c
.
MinRequestTimeout
=
s
.
MinRequestTimeout
c
.
JSONPatchMaxCopyBytes
=
s
.
JSONPatchMaxCopyBytes
c
.
JSONPatchMaxCopyBytes
=
s
.
JSONPatchMaxCopyBytes
c
.
MaxRequestBodyBytes
=
s
.
MaxRequestBodyBytes
c
.
PublicAddress
=
s
.
AdvertiseAddress
c
.
PublicAddress
=
s
.
AdvertiseAddress
return
nil
return
nil
...
@@ -116,6 +123,10 @@ func (s *ServerRunOptions) Validate() []error {
...
@@ -116,6 +123,10 @@ func (s *ServerRunOptions) Validate() []error {
errors
=
append
(
errors
,
fmt
.
Errorf
(
"--json-patch-max-copy-bytes can not be negative value"
))
errors
=
append
(
errors
,
fmt
.
Errorf
(
"--json-patch-max-copy-bytes can not be negative value"
))
}
}
if
s
.
MaxRequestBodyBytes
<
0
{
errors
=
append
(
errors
,
fmt
.
Errorf
(
"--max-resource-write-bytes can not be negative value"
))
}
return
errors
return
errors
}
}
...
...
staging/src/k8s.io/apiserver/pkg/server/options/server_run_options_test.go
View file @
9dfdb6a2
...
@@ -41,6 +41,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
...
@@ -41,6 +41,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
RequestTimeout
:
time
.
Duration
(
2
)
*
time
.
Minute
,
RequestTimeout
:
time
.
Duration
(
2
)
*
time
.
Minute
,
MinRequestTimeout
:
1800
,
MinRequestTimeout
:
1800
,
JSONPatchMaxCopyBytes
:
10
*
1024
*
1024
,
JSONPatchMaxCopyBytes
:
10
*
1024
*
1024
,
MaxRequestBodyBytes
:
10
*
1024
*
1024
,
TargetRAMMB
:
-
65536
,
TargetRAMMB
:
-
65536
,
},
},
expectErr
:
"--target-ram-mb can not be negative value"
,
expectErr
:
"--target-ram-mb can not be negative value"
,
...
@@ -55,6 +56,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
...
@@ -55,6 +56,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
RequestTimeout
:
time
.
Duration
(
2
)
*
time
.
Minute
,
RequestTimeout
:
time
.
Duration
(
2
)
*
time
.
Minute
,
MinRequestTimeout
:
1800
,
MinRequestTimeout
:
1800
,
JSONPatchMaxCopyBytes
:
10
*
1024
*
1024
,
JSONPatchMaxCopyBytes
:
10
*
1024
*
1024
,
MaxRequestBodyBytes
:
10
*
1024
*
1024
,
TargetRAMMB
:
65536
,
TargetRAMMB
:
65536
,
},
},
expectErr
:
"--max-requests-inflight can not be negative value"
,
expectErr
:
"--max-requests-inflight can not be negative value"
,
...
@@ -69,6 +71,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
...
@@ -69,6 +71,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
RequestTimeout
:
time
.
Duration
(
2
)
*
time
.
Minute
,
RequestTimeout
:
time
.
Duration
(
2
)
*
time
.
Minute
,
MinRequestTimeout
:
1800
,
MinRequestTimeout
:
1800
,
JSONPatchMaxCopyBytes
:
10
*
1024
*
1024
,
JSONPatchMaxCopyBytes
:
10
*
1024
*
1024
,
MaxRequestBodyBytes
:
10
*
1024
*
1024
,
TargetRAMMB
:
65536
,
TargetRAMMB
:
65536
,
},
},
expectErr
:
"--max-mutating-requests-inflight can not be negative value"
,
expectErr
:
"--max-mutating-requests-inflight can not be negative value"
,
...
@@ -83,6 +86,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
...
@@ -83,6 +86,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
RequestTimeout
:
-
time
.
Duration
(
2
)
*
time
.
Minute
,
RequestTimeout
:
-
time
.
Duration
(
2
)
*
time
.
Minute
,
MinRequestTimeout
:
1800
,
MinRequestTimeout
:
1800
,
JSONPatchMaxCopyBytes
:
10
*
1024
*
1024
,
JSONPatchMaxCopyBytes
:
10
*
1024
*
1024
,
MaxRequestBodyBytes
:
10
*
1024
*
1024
,
TargetRAMMB
:
65536
,
TargetRAMMB
:
65536
,
},
},
expectErr
:
"--request-timeout can not be negative value"
,
expectErr
:
"--request-timeout can not be negative value"
,
...
@@ -97,6 +101,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
...
@@ -97,6 +101,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
RequestTimeout
:
time
.
Duration
(
2
)
*
time
.
Minute
,
RequestTimeout
:
time
.
Duration
(
2
)
*
time
.
Minute
,
MinRequestTimeout
:
-
1800
,
MinRequestTimeout
:
-
1800
,
JSONPatchMaxCopyBytes
:
10
*
1024
*
1024
,
JSONPatchMaxCopyBytes
:
10
*
1024
*
1024
,
MaxRequestBodyBytes
:
10
*
1024
*
1024
,
TargetRAMMB
:
65536
,
TargetRAMMB
:
65536
,
},
},
expectErr
:
"--min-request-timeout can not be negative value"
,
expectErr
:
"--min-request-timeout can not be negative value"
,
...
@@ -111,11 +116,27 @@ func TestServerRunOptionsValidate(t *testing.T) {
...
@@ -111,11 +116,27 @@ func TestServerRunOptionsValidate(t *testing.T) {
RequestTimeout
:
time
.
Duration
(
2
)
*
time
.
Minute
,
RequestTimeout
:
time
.
Duration
(
2
)
*
time
.
Minute
,
MinRequestTimeout
:
1800
,
MinRequestTimeout
:
1800
,
JSONPatchMaxCopyBytes
:
-
10
*
1024
*
1024
,
JSONPatchMaxCopyBytes
:
-
10
*
1024
*
1024
,
MaxRequestBodyBytes
:
10
*
1024
*
1024
,
TargetRAMMB
:
65536
,
TargetRAMMB
:
65536
,
},
},
expectErr
:
"--json-patch-max-copy-bytes can not be negative value"
,
expectErr
:
"--json-patch-max-copy-bytes can not be negative value"
,
},
},
{
{
name
:
"Test when MaxRequestBodyBytes is negative value"
,
testOptions
:
&
ServerRunOptions
{
AdvertiseAddress
:
net
.
ParseIP
(
"192.168.10.10"
),
CorsAllowedOriginList
:
[]
string
{
"10.10.10.100"
,
"10.10.10.200"
},
MaxRequestsInFlight
:
400
,
MaxMutatingRequestsInFlight
:
200
,
RequestTimeout
:
time
.
Duration
(
2
)
*
time
.
Minute
,
MinRequestTimeout
:
1800
,
JSONPatchMaxCopyBytes
:
10
*
1024
*
1024
,
MaxRequestBodyBytes
:
-
10
*
1024
*
1024
,
TargetRAMMB
:
65536
,
},
expectErr
:
"--max-resource-write-bytes can not be negative value"
,
},
{
name
:
"Test when ServerRunOptions is valid"
,
name
:
"Test when ServerRunOptions is valid"
,
testOptions
:
&
ServerRunOptions
{
testOptions
:
&
ServerRunOptions
{
AdvertiseAddress
:
net
.
ParseIP
(
"192.168.10.10"
),
AdvertiseAddress
:
net
.
ParseIP
(
"192.168.10.10"
),
...
@@ -125,6 +146,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
...
@@ -125,6 +146,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
RequestTimeout
:
time
.
Duration
(
2
)
*
time
.
Minute
,
RequestTimeout
:
time
.
Duration
(
2
)
*
time
.
Minute
,
MinRequestTimeout
:
1800
,
MinRequestTimeout
:
1800
,
JSONPatchMaxCopyBytes
:
10
*
1024
*
1024
,
JSONPatchMaxCopyBytes
:
10
*
1024
*
1024
,
MaxRequestBodyBytes
:
10
*
1024
*
1024
,
TargetRAMMB
:
65536
,
TargetRAMMB
:
65536
,
},
},
},
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment