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"
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.
2016-12-14 09:37:20 +00:00
func ( options * ServerRunOptions ) Validate ( ) [ ] error {
var errors [ ] error
if errs := options . Etcd . Validate ( ) ; len ( errs ) > 0 {
errors = append ( errors , errs ... )
}
if errs := validateClusterIPFlags ( options ) ; len ( errs ) > 0 {
2016-08-26 09:30:39 +00:00
errors = append ( errors , errs ... )
}
2016-12-14 09:37:20 +00:00
if errs := validateServiceNodePort ( options ) ; len ( errs ) > 0 {
2016-08-26 09:30:39 +00:00
errors = append ( errors , errs ... )
}
2016-12-14 09:37:20 +00:00
if errs := options . SecureServing . Validate ( ) ; len ( errs ) > 0 {
errors = append ( errors , errs ... )
}
2017-05-22 10:03:28 +00:00
if errs := options . Authentication . Validate ( ) ; len ( errs ) > 0 {
errors = append ( errors , errs ... )
}
2016-12-14 09:37:20 +00:00
if errs := options . InsecureServing . Validate ( "insecure-port" ) ; len ( errs ) > 0 {
errors = append ( errors , errs ... )
2016-08-26 09:30:39 +00:00
}
2016-12-07 07:25:36 +00:00
if options . MasterCount <= 0 {
errors = append ( errors , fmt . Errorf ( "--apiserver-count should be a positive number, but value '%d' provided" , options . MasterCount ) )
}
2016-12-14 09:37:20 +00:00
return errors
2016-08-09 11:35:53 +00:00
}