From f2ea31fd925f764f8c684710d9cd345663e88d17 Mon Sep 17 00:00:00 2001 From: m1093782566 Date: Sat, 12 Aug 2017 19:58:29 +0800 Subject: [PATCH] add validation for fed-apiserver --- .../app/options/validation.go | 3 +++ .../pkg/server/options/server_run_options.go | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/federation/cmd/federation-apiserver/app/options/validation.go b/federation/cmd/federation-apiserver/app/options/validation.go index 453372346ea..e1f1f2310f5 100644 --- a/federation/cmd/federation-apiserver/app/options/validation.go +++ b/federation/cmd/federation-apiserver/app/options/validation.go @@ -20,6 +20,9 @@ import "fmt" func (options *ServerRunOptions) Validate() []error { var errors []error + if errs := options.GenericServerRunOptions.Validate(); len(errs) > 0 { + errors = append(errors, errs...) + } if errs := options.Etcd.Validate(); len(errs) > 0 { errors = append(errors, errs...) } diff --git a/staging/src/k8s.io/apiserver/pkg/server/options/server_run_options.go b/staging/src/k8s.io/apiserver/pkg/server/options/server_run_options.go index 0ca9d5973a1..a218f2d5bb8 100644 --- a/staging/src/k8s.io/apiserver/pkg/server/options/server_run_options.go +++ b/staging/src/k8s.io/apiserver/pkg/server/options/server_run_options.go @@ -83,6 +83,22 @@ func (s *ServerRunOptions) DefaultAdvertiseAddress(secure *SecureServingOptions) return nil } +// Validate checks validation of ServerRunOptions +func (s *ServerRunOptions) Validate() []error { + errors := []error{} + if s.TargetRAMMB < 0 { + errors = append(errors, fmt.Errorf("--target-ram-mb can not be negative value")) + } + if s.MaxRequestsInFlight < 0 { + errors = append(errors, fmt.Errorf("--max-requests-inflight can not be negative value")) + } + if s.MaxMutatingRequestsInFlight < 0 { + errors = append(errors, fmt.Errorf("--min-request-timeout can not be negative value")) + } + + return errors +} + // AddFlags adds flags for a specific APIServer to the specified FlagSet func (s *ServerRunOptions) AddUniversalFlags(fs *pflag.FlagSet) { // Note: the weird ""+ in below lines seems to be the only way to get gofmt to