@@ -19,8 +19,10 @@ package server
19
19
import (
20
20
"os"
21
21
22
+ "github.com/golang/glog"
22
23
"github.com/kubernetes-incubator/service-catalog/pkg/registry/servicecatalog/server"
23
24
"github.com/spf13/pflag"
25
+ utilerrors "k8s.io/apimachinery/pkg/util/errors"
24
26
genericserveroptions "k8s.io/apiserver/pkg/server/options"
25
27
)
26
28
@@ -52,6 +54,21 @@ type ServiceCatalogServerOptions struct {
52
54
StandaloneMode bool
53
55
}
54
56
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
+
55
72
func (s * ServiceCatalogServerOptions ) addFlags (flags * pflag.FlagSet ) {
56
73
flags .StringVar (
57
74
& s .StorageTypeString ,
@@ -83,6 +100,32 @@ func (s *ServiceCatalogServerOptions) StorageType() (server.StorageType, error)
83
100
return server .StorageTypeFromString (s .StorageTypeString )
84
101
}
85
102
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
+
86
129
// standaloneMode returns true if the env var SERVICE_CATALOG_STANALONE=true
87
130
// If enabled, we will assume no integration with Kubernetes API server is performed.
88
131
// It is intended for testing purposes only.
0 commit comments