Skip to content

Commit 88a9642

Browse files
MHBauerarschles
authored andcommitted
validate the apiserver options (#1116)
per kubernetes/kubernetes#50308 (comment)
1 parent 0b5d6c6 commit 88a9642

File tree

3 files changed

+50
-7
lines changed

3 files changed

+50
-7
lines changed

cmd/apiserver/app/server/options.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ package server
1919
import (
2020
"os"
2121

22+
"github.com/golang/glog"
2223
"github.com/kubernetes-incubator/service-catalog/pkg/registry/servicecatalog/server"
2324
"github.com/spf13/pflag"
25+
utilerrors "k8s.io/apimachinery/pkg/util/errors"
2426
genericserveroptions "k8s.io/apiserver/pkg/server/options"
2527
)
2628

@@ -52,6 +54,21 @@ type ServiceCatalogServerOptions struct {
5254
StandaloneMode bool
5355
}
5456

57+
// NewServiceCatalogServerOptions creates a new instances of
58+
// ServiceCatalogServerOptions with all sub-options filled in.
59+
func NewServiceCatalogServerOptions() *ServiceCatalogServerOptions {
60+
return &ServiceCatalogServerOptions{
61+
GenericServerRunOptions: genericserveroptions.NewServerRunOptions(),
62+
AdmissionOptions: genericserveroptions.NewAdmissionOptions(),
63+
SecureServingOptions: genericserveroptions.NewSecureServingOptions(),
64+
AuthenticationOptions: genericserveroptions.NewDelegatingAuthenticationOptions(),
65+
AuthorizationOptions: genericserveroptions.NewDelegatingAuthorizationOptions(),
66+
AuditOptions: genericserveroptions.NewAuditOptions(),
67+
EtcdOptions: NewEtcdOptions(),
68+
TPROptions: NewTPROptions(),
69+
}
70+
}
71+
5572
func (s *ServiceCatalogServerOptions) addFlags(flags *pflag.FlagSet) {
5673
flags.StringVar(
5774
&s.StorageTypeString,
@@ -83,6 +100,32 @@ func (s *ServiceCatalogServerOptions) StorageType() (server.StorageType, error)
83100
return server.StorageTypeFromString(s.StorageTypeString)
84101
}
85102

103+
// Validate checks all subOptions flags have been set and that they
104+
// have not been set in a conflictory manner.
105+
func (s *ServiceCatalogServerOptions) Validate() error {
106+
errors := []error{}
107+
// TODO uncomment after 1.8 rebase expecting
108+
// https://github.com/kubernetes/kubernetes/pull/50308/files
109+
// errors = append(errors, s.AdmissionOptions.Validate()...)
110+
errors = append(errors, s.SecureServingOptions.Validate()...)
111+
errors = append(errors, s.AuthenticationOptions.Validate()...)
112+
errors = append(errors, s.AuthorizationOptions.Validate()...)
113+
// etcd options
114+
if "etcd" == s.StorageTypeString {
115+
etcdErrs := s.EtcdOptions.Validate()
116+
if len(etcdErrs) > 0 {
117+
glog.Errorln("Error validating etcd options, do you have `--etcd-servers localhost` set?")
118+
}
119+
errors = append(errors, etcdErrs...)
120+
}
121+
// TODO add alternative storage validation
122+
// errors = append(errors, s.TPROptions.Validate()...)
123+
// TODO uncomment after 1.8 rebase expecting
124+
// https://github.com/kubernetes/kubernetes/pull/47043
125+
// errors = append(errors, s.AuditOptions.Validate()...)
126+
return utilerrors.NewAggregate(errors)
127+
}
128+
86129
// standaloneMode returns true if the env var SERVICE_CATALOG_STANALONE=true
87130
// If enabled, we will assume no integration with Kubernetes API server is performed.
88131
// It is intended for testing purposes only.

cmd/apiserver/app/server/run_server.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ func RunServer(opts *ServiceCatalogServerOptions) error {
4343
if there is a need to stop the API server */
4444
opts.StopCh = make(chan struct{})
4545
}
46+
47+
err = opts.Validate()
48+
if nil != err {
49+
return err
50+
}
51+
4652
if storageType == server.StorageTypeTPR {
4753
return runTPRServer(opts)
4854
}
@@ -102,12 +108,6 @@ func runEtcdServer(opts *ServiceCatalogServerOptions) error {
102108
return err
103109
}
104110

105-
// etcd options
106-
if errs := etcdOpts.Validate(); len(errs) > 0 {
107-
glog.Errorln("Error validating etcd options, do you have `--etcd-servers localhost` set?")
108-
return errs[0]
109-
}
110-
111111
glog.V(4).Infoln("Creating storage factory")
112112

113113
// The API server stores objects using a particular API version for each

cmd/apiserver/app/server/run_server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929

3030
// make sure RunServer returns with an error when TPR fails to install
3131
func TestRunServerInstallTPRFails(t *testing.T) {
32-
options := &ServiceCatalogServerOptions{}
32+
options := NewServiceCatalogServerOptions()
3333

3434
fakeClientset := &kubeclientfake.Clientset{}
3535
fakeClientset.AddReactor("get", "thirdpartyresources", func(core.Action) (bool, runtime.Object, error) {

0 commit comments

Comments
 (0)