From c7bf5506ee8b1e0c6e8a4de26a8d80c1e0e00dbf Mon Sep 17 00:00:00 2001 From: xiongzhongliang Date: Mon, 1 Mar 2021 20:14:13 +0800 Subject: [PATCH] cleanup: wrap the apiserver identity validation --- cmd/kube-apiserver/app/options/validation.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/cmd/kube-apiserver/app/options/validation.go b/cmd/kube-apiserver/app/options/validation.go index 0730aa05f104..e1cf2988e397 100644 --- a/cmd/kube-apiserver/app/options/validation.go +++ b/cmd/kube-apiserver/app/options/validation.go @@ -150,6 +150,17 @@ func validateAPIPriorityAndFairness(options *ServerRunOptions) []error { return nil } +func validateAPIServerIdentity(options *ServerRunOptions) []error { + var errs []error + if options.IdentityLeaseDurationSeconds <= 0 { + errs = append(errs, fmt.Errorf("--identity-lease-duration-seconds should be a positive number, but value '%d' provided", options.IdentityLeaseDurationSeconds)) + } + if options.IdentityLeaseRenewIntervalSeconds <= 0 { + errs = append(errs, fmt.Errorf("--identity-lease-renew-interval-seconds should be a positive number, but value '%d' provided", options.IdentityLeaseRenewIntervalSeconds)) + } + return errs +} + // Validate checks ServerRunOptions and return a slice of found errs. func (s *ServerRunOptions) Validate() []error { var errs []error @@ -169,12 +180,7 @@ func (s *ServerRunOptions) Validate() []error { errs = append(errs, validateTokenRequest(s)...) errs = append(errs, s.Metrics.Validate()...) errs = append(errs, s.Logs.Validate()...) - if s.IdentityLeaseDurationSeconds <= 0 { - errs = append(errs, fmt.Errorf("--identity-lease-duration-seconds should be a positive number, but value '%d' provided", s.IdentityLeaseDurationSeconds)) - } - if s.IdentityLeaseRenewIntervalSeconds <= 0 { - errs = append(errs, fmt.Errorf("--identity-lease-renew-interval-seconds should be a positive number, but value '%d' provided", s.IdentityLeaseRenewIntervalSeconds)) - } + errs = append(errs, validateAPIServerIdentity(s)...) return errs }