2016-08-09 11:35:53 +00:00
/ *
2016-12-14 10:11:25 +00:00
Copyright 2014 The Kubernetes Authors .
2016-08-09 11:35:53 +00:00
Licensed under the Apache License , Version 2.0 ( the "License" ) ;
you may not use this file except in compliance with the License .
You may obtain a copy of the License at
http : //www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing , software
distributed under the License is distributed on an "AS IS" BASIS ,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
See the License for the specific language governing permissions and
limitations under the License .
* /
2016-12-06 11:22:49 +00:00
package options
2016-08-09 11:35:53 +00:00
import (
2016-08-26 09:30:39 +00:00
"fmt"
2017-12-21 03:27:20 +00:00
apiextensionsapiserver "k8s.io/apiextensions-apiserver/pkg/apiserver"
2018-01-26 02:32:46 +00:00
aggregatorscheme "k8s.io/kube-aggregator/pkg/apiserver/scheme"
2017-12-21 03:27:20 +00:00
"k8s.io/kubernetes/pkg/api/legacyscheme"
2016-08-09 11:35:53 +00:00
)
// TODO: Longer term we should read this from some config store, rather than a flag.
2016-12-14 09:37:20 +00:00
func validateClusterIPFlags ( options * ServerRunOptions ) [ ] error {
2016-08-26 09:30:39 +00:00
errors := [ ] error { }
2016-08-09 11:35:53 +00:00
if options . ServiceClusterIPRange . IP == nil {
2016-12-14 09:37:20 +00:00
errors = append ( errors , fmt . Errorf ( "no --service-cluster-ip-range specified" ) )
2016-08-09 11:35:53 +00:00
}
var ones , bits = options . ServiceClusterIPRange . Mask . Size ( )
if bits - ones > 20 {
2016-12-14 09:37:20 +00:00
errors = append ( errors , fmt . Errorf ( "specified --service-cluster-ip-range is too large" ) )
2016-08-09 11:35:53 +00:00
}
2016-08-26 09:30:39 +00:00
return errors
2016-08-09 11:35:53 +00:00
}
2016-12-14 09:37:20 +00:00
func validateServiceNodePort ( options * ServerRunOptions ) [ ] error {
2016-08-26 09:30:39 +00:00
errors := [ ] error { }
2016-08-09 11:35:53 +00:00
if options . KubernetesServiceNodePort < 0 || options . KubernetesServiceNodePort > 65535 {
2016-12-14 09:37:20 +00:00
errors = append ( errors , fmt . Errorf ( "--kubernetes-service-node-port %v must be between 0 and 65535, inclusive. If 0, the Kubernetes master service will be of type ClusterIP" , options . KubernetesServiceNodePort ) )
2016-08-09 11:35:53 +00:00
}
if options . KubernetesServiceNodePort > 0 && ! options . ServiceNodePortRange . Contains ( options . KubernetesServiceNodePort ) {
2016-12-14 09:37:20 +00:00
errors = append ( errors , fmt . Errorf ( "kubernetes service port range %v doesn't contain %v" , options . ServiceNodePortRange , ( options . KubernetesServiceNodePort ) ) )
2016-08-09 11:35:53 +00:00
}
2016-08-26 09:30:39 +00:00
return errors
2016-08-09 11:35:53 +00:00
}
2016-12-14 10:11:25 +00:00
// Validate checks ServerRunOptions and return a slice of found errors.
2018-03-02 09:15:02 +00:00
func ( s * ServerRunOptions ) Validate ( ) [ ] error {
2016-12-14 09:37:20 +00:00
var errors [ ] error
2018-03-02 09:15:02 +00:00
if errs := s . Etcd . Validate ( ) ; len ( errs ) > 0 {
2016-12-14 09:37:20 +00:00
errors = append ( errors , errs ... )
}
2018-03-02 09:15:02 +00:00
if errs := validateClusterIPFlags ( s ) ; len ( errs ) > 0 {
2016-08-26 09:30:39 +00:00
errors = append ( errors , errs ... )
}
2018-03-02 09:15:02 +00:00
if errs := validateServiceNodePort ( s ) ; len ( errs ) > 0 {
2016-08-26 09:30:39 +00:00
errors = append ( errors , errs ... )
}
2018-03-02 09:15:02 +00:00
if errs := s . SecureServing . Validate ( ) ; len ( errs ) > 0 {
2016-12-14 09:37:20 +00:00
errors = append ( errors , errs ... )
}
2018-03-02 09:15:02 +00:00
if errs := s . Authentication . Validate ( ) ; len ( errs ) > 0 {
2017-05-22 10:03:28 +00:00
errors = append ( errors , errs ... )
}
2018-03-14 06:28:41 +00:00
if errs := s . Authorization . Validate ( ) ; len ( errs ) > 0 {
errors = append ( errors , errs ... )
}
2018-03-02 09:15:02 +00:00
if errs := s . Audit . Validate ( ) ; len ( errs ) > 0 {
2017-06-06 11:31:29 +00:00
errors = append ( errors , errs ... )
}
2018-03-02 09:15:02 +00:00
if errs := s . Admission . Validate ( ) ; len ( errs ) > 0 {
2017-11-30 06:34:36 +00:00
errors = append ( errors , errs ... )
}
2018-03-02 09:15:02 +00:00
if errs := s . InsecureServing . Validate ( ) ; len ( errs ) > 0 {
2016-12-14 09:37:20 +00:00
errors = append ( errors , errs ... )
2016-08-26 09:30:39 +00:00
}
2018-03-02 09:15:02 +00:00
if s . MasterCount <= 0 {
errors = append ( errors , fmt . Errorf ( "--apiserver-count should be a positive number, but value '%d' provided" , s . MasterCount ) )
2016-12-07 07:25:36 +00:00
}
2018-05-07 12:32:20 +00:00
if errs := s . APIEnablement . Validate ( legacyscheme . Scheme , apiextensionsapiserver . Scheme , aggregatorscheme . Scheme ) ; len ( errs ) > 0 {
2017-12-21 03:27:20 +00:00
errors = append ( errors , errs ... )
}
2016-12-14 09:37:20 +00:00
return errors
2016-08-09 11:35:53 +00:00
}