This repository has been archived by the owner on Nov 18, 2019. It is now read-only.
/
start.go
97 lines (80 loc) · 2.56 KB
/
start.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package server
import (
"fmt"
"io"
"net"
"github.com/appscode/kutil/meta"
"github.com/appscode/service-broker/pkg/broker"
"github.com/appscode/service-broker/pkg/server"
"github.com/spf13/pflag"
admissionv1beta1 "k8s.io/api/admission/v1beta1"
genericapiserver "k8s.io/apiserver/pkg/server"
genericoptions "k8s.io/apiserver/pkg/server/options"
"kmodules.xyz/client-go/tools/clientcmd"
)
const defaultEtcdPathPrefix = "/registry/service-broker.appscode.com"
type BrokerServerOptions struct {
RecommendedOptions *genericoptions.RecommendedOptions
ExtraOptions *ExtraOptions
StdOut io.Writer
StdErr io.Writer
}
func NewBrokerServerOptions(out, errOut io.Writer) *BrokerServerOptions {
o := &BrokerServerOptions{
// TODO we will nil out the etcd storage options. This requires a later level of k8s.io/apiserver
RecommendedOptions: genericoptions.NewRecommendedOptions(
defaultEtcdPathPrefix,
server.Codecs.LegacyCodec(admissionv1beta1.SchemeGroupVersion),
genericoptions.NewProcessInfo("service-broker", meta.Namespace()),
),
ExtraOptions: NewExtraOptions(),
StdOut: out,
StdErr: errOut,
}
o.RecommendedOptions.Etcd = nil
o.RecommendedOptions.Admission = nil
return o
}
func (o BrokerServerOptions) AddFlags(fs *pflag.FlagSet) {
o.RecommendedOptions.AddFlags(fs)
o.ExtraOptions.AddFlags(fs)
}
func (o BrokerServerOptions) Validate(args []string) error {
return nil
}
func (o *BrokerServerOptions) Complete() error {
return nil
}
func (o BrokerServerOptions) Config() (*server.BrokerServerConfig, error) {
// TODO have a "real" external address
if err := o.RecommendedOptions.SecureServing.MaybeDefaultWithSelfSignedCerts("localhost", nil, []net.IP{net.ParseIP("127.0.0.1")}); err != nil {
return nil, fmt.Errorf("error creating self-signed certificates: %v", err)
}
serverConfig := genericapiserver.NewRecommendedConfig(server.Codecs)
serverConfig.EnableMetrics = true
if err := o.RecommendedOptions.ApplyTo(serverConfig); err != nil {
return nil, err
}
// Fixes https://github.com/Azure/AKS/issues/522
clientcmd.Fix(serverConfig.ClientConfig)
extraConfig := broker.NewConfig(serverConfig.ClientConfig)
if err := o.ExtraOptions.ApplyTo(extraConfig); err != nil {
return nil, err
}
config := &server.BrokerServerConfig{
GenericConfig: serverConfig,
ExtraConfig: extraConfig,
}
return config, nil
}
func (o BrokerServerOptions) Run(stopCh <-chan struct{}) error {
config, err := o.Config()
if err != nil {
return err
}
s, err := config.Complete().New()
if err != nil {
return err
}
return s.Run(stopCh)
}