forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
master_args.go
651 lines (536 loc) · 21.3 KB
/
master_args.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
package start
import (
"fmt"
"net"
"net/url"
"path"
"regexp"
"strconv"
"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apiserver/pkg/util/flag"
"k8s.io/kubernetes/pkg/master/ports"
"k8s.io/kubernetes/pkg/registry/core/service/ipallocator"
"github.com/openshift/origin/pkg/cmd/flagtypes"
"github.com/openshift/origin/pkg/cmd/server/admin"
configapi "github.com/openshift/origin/pkg/cmd/server/apis/config"
configapiv1 "github.com/openshift/origin/pkg/cmd/server/apis/config/v1"
"github.com/openshift/origin/pkg/cmd/server/bootstrappolicy"
cmdutil "github.com/openshift/origin/pkg/cmd/util"
"github.com/spf13/cobra"
)
// MasterArgs is a struct that the command stores flag values into. It holds a partially complete set of parameters for starting the master
// This object should hold the common set values, but not attempt to handle all cases. The expected path is to use this object to create
// a fully specified config later on. If you need something not set here, then create a fully specified config file and pass that as argument
// to starting the master.
type MasterArgs struct {
// MasterAddr is the master address for use by OpenShift components (host, host:port, or URL).
// Scheme and port default to the --listen scheme and port. When unset, attempt to use the first
// public IPv4 non-loopback address registered on this host.
MasterAddr flagtypes.Addr
// EtcdAddr is the address of the etcd server (host, host:port, or URL). If specified, no built-in
// etcd will be started.
EtcdAddr flagtypes.Addr
// MasterPublicAddr is the master address for use by public clients, if different (host, host:port,
// or URL). Defaults to same as --master.
MasterPublicAddr flagtypes.Addr
// StartAPI controls whether the API component of the master is started (to support the API role)
// TODO: once we implement bastion role and kube/os controller role, revisit
StartAPI bool
// StartControllers controls whether the controller component of the master is started (to support
// the controller role)
StartControllers bool
// DNSBindAddr exposed for integration tests to set
DNSBindAddr flagtypes.Addr
// EtcdDir is the etcd data directory.
EtcdDir string
ConfigDir *flag.StringFlag
// CORSAllowedOrigins is a list of allowed origins for CORS, comma separated.
// An allowed origin can be a regular expression to support subdomain matching.
// CORS is enabled for localhost, 127.0.0.1, and the asset server by default.
CORSAllowedOrigins []string
APIServerCAFiles []string
ListenArg *ListenArg
ImageFormatArgs *ImageFormatArgs
KubeConnectionArgs *KubeConnectionArgs
SchedulerConfigFile string
NetworkArgs *NetworkArgs
OverrideConfig func(config *configapi.MasterConfig) error
}
// BindMasterArgs binds the options to the flags with prefix + default flag names
func BindMasterArgs(args *MasterArgs, flags *pflag.FlagSet, prefix string) {
flags.Var(&args.MasterAddr, prefix+"master", "The master address for use by OpenShift components (host, host:port, or URL). Scheme and port default to the --listen scheme and port. When unset, attempt to use the first public IPv4 non-loopback address registered on this host.")
flags.Var(&args.MasterPublicAddr, prefix+"public-master", "The master address for use by public clients, if different (host, host:port, or URL). Defaults to same as --master.")
flags.Var(&args.EtcdAddr, prefix+"etcd", "The address of the etcd server (host, host:port, or URL). If specified, no built-in etcd will be started.")
flags.Var(&args.DNSBindAddr, prefix+"dns", "The address to listen for DNS requests on.")
flags.StringVar(&args.EtcdDir, prefix+"etcd-dir", "openshift.local.etcd", "The etcd data directory.")
flags.StringSliceVar(&args.APIServerCAFiles, prefix+"certificate-authority", args.APIServerCAFiles, "Optional files containing signing authorities to use (in addition to the generated signer) to verify the API server's serving certificate.")
flags.StringSliceVar(&args.CORSAllowedOrigins, prefix+"cors-allowed-origins", []string{}, "List of allowed origins for CORS, comma separated. An allowed origin can be a regular expression to support subdomain matching. CORS is enabled for localhost, 127.0.0.1, and the asset server by default.")
// autocompletion hints
cobra.MarkFlagFilename(flags, prefix+"etcd-dir")
cobra.MarkFlagFilename(flags, prefix+"certificate-authority")
}
// NewDefaultMasterArgs creates MasterArgs with sub-objects created and default values set.
func NewDefaultMasterArgs() *MasterArgs {
config := &MasterArgs{
MasterAddr: flagtypes.Addr{Value: "localhost:8443", DefaultScheme: "https", DefaultPort: 8443, AllowPrefix: true}.Default(),
EtcdAddr: flagtypes.Addr{Value: "0.0.0.0:4001", DefaultScheme: "https", DefaultPort: 4001}.Default(),
MasterPublicAddr: flagtypes.Addr{Value: "localhost:8443", DefaultScheme: "https", DefaultPort: 8443, AllowPrefix: true}.Default(),
DNSBindAddr: flagtypes.Addr{Value: "0.0.0.0:8053", DefaultScheme: "tcp", DefaultPort: 8053, AllowPrefix: true}.Default(),
ConfigDir: &flag.StringFlag{},
ListenArg: NewDefaultListenArg(),
ImageFormatArgs: NewDefaultImageFormatArgs(),
KubeConnectionArgs: NewDefaultKubeConnectionArgs(),
NetworkArgs: NewDefaultMasterNetworkArgs(),
}
return config
}
// GetConfigFileToWrite returns the configuration filepath for master
func (args MasterArgs) GetConfigFileToWrite() string {
return path.Join(args.ConfigDir.Value(), "master-config.yaml")
}
// makeHostMatchRegex returns a regex that matches this host exactly.
// If host contains a port, the returned regex matches the port exactly.
// If host does not contain a port, the returned regex matches any port or no port.
func makeHostMatchRegex(host string) string {
if _, _, err := net.SplitHostPort(host); err == nil {
// we have a port, match the end exactly
return "//" + regexp.QuoteMeta(host) + "$"
} else {
// we don't have a port, match a port separator or the end
return "//" + regexp.QuoteMeta(host) + "(:|$)"
}
}
// BuildSerializeableMasterConfig takes the MasterArgs (partially complete config) and uses them along with defaulting behavior to create the fully specified
// config object for starting the master
func (args MasterArgs) BuildSerializeableMasterConfig() (*configapi.MasterConfig, error) {
masterPublicAddr, err := args.GetMasterPublicAddress()
if err != nil {
return nil, err
}
assetPublicAddr, err := args.GetAssetPublicAddress()
if err != nil {
return nil, err
}
dnsBindAddr, err := args.GetDNSBindAddress()
if err != nil {
return nil, err
}
listenServingInfo := servingInfoForAddr(&args.ListenArg.ListenAddr)
// always include the all-in-one server's web console as an allowed CORS origin
// always include localhost as an allowed CORS origin
// always include master public address as an allowed CORS origin
corsAllowedOrigins := sets.NewString(args.CORSAllowedOrigins...)
corsAllowedOrigins.Insert(
makeHostMatchRegex(assetPublicAddr.Host),
makeHostMatchRegex(masterPublicAddr.Host),
makeHostMatchRegex("localhost"),
makeHostMatchRegex("127.0.0.1"),
)
etcdAddress, err := args.GetEtcdAddress()
if err != nil {
return nil, err
}
builtInEtcd := !args.EtcdAddr.Provided
var etcdConfig *configapi.EtcdConfig
if builtInEtcd {
etcdConfig, err = args.BuildSerializeableEtcdConfig()
if err != nil {
return nil, err
}
}
kubernetesMasterConfig, err := args.BuildSerializeableKubeMasterConfig()
if err != nil {
return nil, err
}
oauthConfig, err := args.BuildSerializeableOAuthConfig()
if err != nil {
return nil, err
}
kubeletClientInfo := admin.DefaultMasterKubeletClientCertInfo(args.ConfigDir.Value())
etcdClientInfo := admin.DefaultMasterEtcdClientCertInfo(args.ConfigDir.Value())
serviceServingCertSigner := admin.DefaultServiceSignerCAInfo(args.ConfigDir.Value())
dnsServingInfo := servingInfoForAddr(&dnsBindAddr)
config := &configapi.MasterConfig{
ServingInfo: configapi.HTTPServingInfo{
ServingInfo: listenServingInfo,
},
CORSAllowedOrigins: corsAllowedOrigins.List(),
MasterPublicURL: masterPublicAddr.String(),
KubernetesMasterConfig: *kubernetesMasterConfig,
EtcdConfig: etcdConfig,
AuthConfig: configapi.MasterAuthConfig{
RequestHeader: &configapi.RequestHeaderAuthenticationOptions{
ClientCA: admin.DefaultCertFilename(args.ConfigDir.Value(), admin.FrontProxyCAFilePrefix),
ClientCommonNames: []string{bootstrappolicy.AggregatorUsername},
UsernameHeaders: []string{"X-Remote-User"},
GroupHeaders: []string{"X-Remote-Group"},
ExtraHeaderPrefixes: []string{"X-Remote-Extra-"}},
},
AggregatorConfig: configapi.AggregatorConfig{
ProxyClientInfo: admin.DefaultAggregatorClientCertInfo(args.ConfigDir.Value()).CertLocation,
},
OAuthConfig: oauthConfig,
DNSConfig: &configapi.DNSConfig{
BindAddress: dnsServingInfo.BindAddress,
BindNetwork: dnsServingInfo.BindNetwork,
AllowRecursiveQueries: true,
},
MasterClients: configapi.MasterClients{
OpenShiftLoopbackKubeConfig: admin.DefaultKubeConfigFilename(args.ConfigDir.Value(), bootstrappolicy.MasterUnqualifiedUsername),
},
EtcdClientInfo: configapi.EtcdConnectionInfo{
URLs: []string{etcdAddress.String()},
},
KubeletClientInfo: configapi.KubeletConnectionInfo{
Port: ports.KubeletPort,
},
ImageConfig: configapi.ImageConfig{
Format: args.ImageFormatArgs.ImageTemplate.Format,
Latest: args.ImageFormatArgs.ImageTemplate.Latest,
},
ImagePolicyConfig: configapi.ImagePolicyConfig{},
ProjectConfig: configapi.ProjectConfig{
DefaultNodeSelector: "",
ProjectRequestMessage: "",
ProjectRequestTemplate: "",
// Allocator defaults on
SecurityAllocator: &configapi.SecurityAllocator{},
},
NetworkConfig: configapi.MasterNetworkConfig{
NetworkPluginName: args.NetworkArgs.NetworkPluginName,
ClusterNetworks: []configapi.ClusterNetworkEntry{
{
CIDR: args.NetworkArgs.ClusterNetworkCIDR,
HostSubnetLength: args.NetworkArgs.HostSubnetLength,
},
},
ServiceNetworkCIDR: args.NetworkArgs.ServiceNetworkCIDR,
},
VolumeConfig: configapi.MasterVolumeConfig{
DynamicProvisioningEnabled: true,
},
ControllerConfig: configapi.ControllerConfig{
ServiceServingCert: configapi.ServiceServingCert{
Signer: &serviceServingCertSigner,
},
},
}
config.ServingInfo.ServerCert = admin.DefaultMasterServingCertInfo(args.ConfigDir.Value())
config.ServingInfo.ClientCA = admin.DefaultAPIClientCAFile(args.ConfigDir.Value())
if oauthConfig != nil {
s := admin.DefaultCABundleFile(args.ConfigDir.Value())
oauthConfig.MasterCA = &s
}
config.KubeletClientInfo.CA = admin.DefaultRootCAFile(args.ConfigDir.Value())
config.KubeletClientInfo.ClientCert = kubeletClientInfo.CertLocation
config.ServiceAccountConfig.MasterCA = admin.DefaultCABundleFile(args.ConfigDir.Value())
// Only set up ca/cert info for etcd connections if we're self-hosting etcd
if builtInEtcd {
config.EtcdClientInfo.CA = admin.DefaultRootCAFile(args.ConfigDir.Value())
config.EtcdClientInfo.ClientCert = etcdClientInfo.CertLocation
}
// We're responsible for generating all the managed service accounts
config.ServiceAccountConfig.ManagedNames = []string{
bootstrappolicy.DefaultServiceAccountName,
bootstrappolicy.BuilderServiceAccountName,
bootstrappolicy.DeployerServiceAccountName,
}
// We also need the private key file to give to the token generator
config.ServiceAccountConfig.PrivateKeyFile = admin.DefaultServiceAccountPrivateKeyFile(args.ConfigDir.Value())
// We also need the public key file to give to the authenticator
config.ServiceAccountConfig.PublicKeyFiles = []string{
admin.DefaultServiceAccountPublicKeyFile(args.ConfigDir.Value()),
}
internal, err := applyDefaults(config, configapiv1.LegacySchemeGroupVersion)
if err != nil {
return nil, err
}
config = internal.(*configapi.MasterConfig)
// When creating a new config, use Protobuf
configapi.SetProtobufClientDefaults(config.MasterClients.OpenShiftLoopbackClientConnectionOverrides)
return config, nil
}
func (args MasterArgs) BuildSerializeableOAuthConfig() (*configapi.OAuthConfig, error) {
masterAddr, err := args.GetMasterAddress()
if err != nil {
return nil, err
}
masterPublicAddr, err := args.GetMasterPublicAddress()
if err != nil {
return nil, err
}
assetPublicAddr, err := args.GetAssetPublicAddress()
if err != nil {
return nil, err
}
config := &configapi.OAuthConfig{
MasterURL: masterAddr.String(),
MasterPublicURL: masterPublicAddr.String(),
AssetPublicURL: assetPublicAddr.String(),
IdentityProviders: []configapi.IdentityProvider{},
GrantConfig: configapi.GrantConfig{
Method: configapi.GrantHandlerAuto,
},
SessionConfig: &configapi.SessionConfig{
SessionSecretsFile: "",
SessionMaxAgeSeconds: 5 * 60, // 5 minutes
SessionName: "ssn",
},
TokenConfig: configapi.TokenConfig{
AuthorizeTokenMaxAgeSeconds: 5 * 60, // 5 minutes
AccessTokenMaxAgeSeconds: 24 * 60 * 60, // 1 day
AccessTokenInactivityTimeoutSeconds: nil, // no timeouts by default
},
}
config.IdentityProviders = append(config.IdentityProviders,
configapi.IdentityProvider{
Name: "anypassword",
UseAsChallenger: true,
UseAsLogin: true,
Provider: &configapi.AllowAllPasswordIdentityProvider{},
},
)
return config, nil
}
// BuildSerializeableEtcdConfig creates a fully specified etcd startup configuration based on MasterArgs
func (args MasterArgs) BuildSerializeableEtcdConfig() (*configapi.EtcdConfig, error) {
etcdAddr, err := args.GetEtcdAddress()
if err != nil {
return nil, err
}
etcdPeerAddr, err := args.GetEtcdPeerAddress()
if err != nil {
return nil, err
}
config := &configapi.EtcdConfig{
ServingInfo: configapi.ServingInfo{
BindAddress: args.GetEtcdBindAddress(),
},
PeerServingInfo: configapi.ServingInfo{
BindAddress: args.GetEtcdPeerBindAddress(),
},
Address: etcdAddr.Host,
PeerAddress: etcdPeerAddr.Host,
StorageDir: args.EtcdDir,
}
if args.ListenArg.UseTLS() {
config.ServingInfo.ServerCert = admin.DefaultEtcdServingCertInfo(args.ConfigDir.Value())
config.ServingInfo.ClientCA = admin.DefaultEtcdClientCAFile(args.ConfigDir.Value())
config.PeerServingInfo.ServerCert = admin.DefaultEtcdServingCertInfo(args.ConfigDir.Value())
config.PeerServingInfo.ClientCA = admin.DefaultEtcdClientCAFile(args.ConfigDir.Value())
}
return config, nil
}
// BuildSerializeableKubeMasterConfig creates a fully specified kubernetes master startup configuration based on MasterArgs
func (args MasterArgs) BuildSerializeableKubeMasterConfig() (*configapi.KubernetesMasterConfig, error) {
masterAddr, err := args.GetMasterAddress()
if err != nil {
return nil, err
}
masterHost, _, err := net.SplitHostPort(masterAddr.Host)
if err != nil {
masterHost = masterAddr.Host
}
masterIP := ""
if ip := net.ParseIP(masterHost); ip != nil {
masterIP = ip.String()
}
config := &configapi.KubernetesMasterConfig{
MasterIP: masterIP,
ServicesSubnet: args.NetworkArgs.ServiceNetworkCIDR,
SchedulerConfigFile: args.SchedulerConfigFile,
ProxyClientInfo: admin.DefaultProxyClientCertInfo(args.ConfigDir.Value()).CertLocation,
}
return config, nil
}
func (args MasterArgs) Validate() error {
masterAddr, err := args.GetMasterAddress()
if err != nil {
return err
}
if len(masterAddr.Path) != 0 {
return fmt.Errorf("master url may not include a path: '%v'", masterAddr.Path)
}
addr, err := args.GetMasterPublicAddress()
if err != nil {
return err
}
if len(addr.Path) != 0 {
return fmt.Errorf("master public url may not include a path: '%v'", addr.Path)
}
if err := args.KubeConnectionArgs.Validate(); err != nil {
return err
}
addr, err = args.KubeConnectionArgs.GetKubernetesAddress(masterAddr)
if err != nil {
return err
}
if len(addr.Path) != 0 {
return fmt.Errorf("kubernetes url may not include a path: '%v'", addr.Path)
}
return nil
}
// GetServerCertHostnames returns the set of hostnames that any serving certificate for master needs to be valid for.
func (args MasterArgs) GetServerCertHostnames() (sets.String, error) {
masterAddr, err := args.GetMasterAddress()
if err != nil {
return nil, err
}
masterPublicAddr, err := args.GetMasterPublicAddress()
if err != nil {
return nil, err
}
assetPublicAddr, err := args.GetAssetPublicAddress()
if err != nil {
return nil, err
}
allHostnames := sets.NewString(
"localhost", "127.0.0.1",
"openshift.default.svc.cluster.local",
"openshift.default.svc",
"openshift.default",
"openshift",
"kubernetes.default.svc.cluster.local",
"kubernetes.default.svc",
"kubernetes.default",
"kubernetes",
masterAddr.Host, masterPublicAddr.Host, assetPublicAddr.Host)
if _, ipnet, err := net.ParseCIDR(args.NetworkArgs.ServiceNetworkCIDR); err == nil {
// CIDR is ignored if it is invalid, other code handles validation.
if firstServiceIP, err := ipallocator.GetIndexedIP(ipnet, 1); err == nil {
allHostnames.Insert(firstServiceIP.String())
}
}
listenIP := net.ParseIP(args.ListenArg.ListenAddr.Host)
// add the IPs that might be used based on the ListenAddr.
if listenIP != nil && listenIP.IsUnspecified() {
allAddresses, _ := cmdutil.AllLocalIP4()
for _, ip := range allAddresses {
allHostnames.Insert(ip.String())
}
} else {
allHostnames.Insert(args.ListenArg.ListenAddr.Host)
}
certHostnames := sets.String{}
for hostname := range allHostnames {
if host, _, err := net.SplitHostPort(hostname); err == nil {
// add the hostname without the port
certHostnames.Insert(host)
} else {
// add the originally specified hostname
certHostnames.Insert(hostname)
}
}
return certHostnames, nil
}
// GetMasterAddress checks for an unset master address and then attempts to use the first
// public IPv4 non-loopback address registered on this host.
// TODO: make me IPv6 safe
func (args MasterArgs) GetMasterAddress() (*url.URL, error) {
if args.MasterAddr.Provided {
return args.MasterAddr.URL, nil
}
// Use the bind port by default
port := args.ListenArg.ListenAddr.Port
// Use the bind scheme by default
scheme := args.ListenArg.ListenAddr.URL.Scheme
addr := ""
if ip, err := cmdutil.DefaultLocalIP4(); err == nil {
addr = ip.String()
} else if err == cmdutil.ErrorNoDefaultIP {
addr = "127.0.0.1"
} else if err != nil {
return nil, fmt.Errorf("Unable to find a public IP address: %v", err)
}
masterAddr := scheme + "://" + net.JoinHostPort(addr, strconv.Itoa(port))
return url.Parse(masterAddr)
}
func (args MasterArgs) GetDNSBindAddress() (flagtypes.Addr, error) {
if args.DNSBindAddr.Provided {
return args.DNSBindAddr, nil
}
dnsAddr := flagtypes.Addr{Value: args.ListenArg.ListenAddr.Host, DefaultPort: args.DNSBindAddr.DefaultPort}.Default()
return dnsAddr, nil
}
func (args MasterArgs) GetMasterPublicAddress() (*url.URL, error) {
if args.MasterPublicAddr.Provided {
return args.MasterPublicAddr.URL, nil
}
return args.GetMasterAddress()
}
// GetEtcdBindAddress derives the etcd bind address by using the bind address and
// the default etcd port
func (args MasterArgs) GetEtcdBindAddress() string {
return net.JoinHostPort(args.ListenArg.ListenAddr.Host, strconv.Itoa(args.EtcdAddr.DefaultPort))
}
// GetEtcdPeerBindAddress derives the etcd peer address by using the bind address
// and the default etcd peering port
func (args MasterArgs) GetEtcdPeerBindAddress() string {
return net.JoinHostPort(args.ListenArg.ListenAddr.Host, "7001")
}
// GetEtcdAddress returns the address for etcd
func (args MasterArgs) GetEtcdAddress() (*url.URL, error) {
if args.EtcdAddr.Provided {
return args.EtcdAddr.URL, nil
}
// Etcd should be reachable on the same address that the master is (for simplicity)
masterAddr, err := args.GetMasterAddress()
if err != nil {
return nil, err
}
return &url.URL{
// Use the bind scheme by default
Scheme: args.ListenArg.ListenAddr.URL.Scheme,
Host: net.JoinHostPort(getHost(*masterAddr), strconv.Itoa(args.EtcdAddr.DefaultPort)),
}, nil
}
func (args MasterArgs) GetEtcdPeerAddress() (*url.URL, error) {
// Derive from the etcd address, on port 7001
etcdAddress, err := args.GetEtcdAddress()
if err != nil {
return nil, err
}
host, _, err := net.SplitHostPort(etcdAddress.Host)
if err != nil {
return nil, err
}
etcdAddress.Host = net.JoinHostPort(host, "7001")
return etcdAddress, nil
}
func (args MasterArgs) GetAssetPublicAddress() (*url.URL, error) {
t, err := args.GetMasterPublicAddress()
if err != nil {
return nil, err
}
assetPublicAddr := *t
assetPublicAddr.Path = "/console/" // TODO: make a constant
return &assetPublicAddr, nil
}
func getHost(theURL url.URL) string {
host, _, err := net.SplitHostPort(theURL.Host)
if err != nil {
return theURL.Host
}
return host
}
// applyDefaults roundtrips the config to v1 and back to ensure proper defaults are set.
func applyDefaults(config runtime.Object, version schema.GroupVersion) (runtime.Object, error) {
ext, err := configapi.Scheme.ConvertToVersion(config, version)
if err != nil {
return nil, err
}
configapi.Scheme.Default(ext)
return configapi.Scheme.ConvertToVersion(ext, configapi.SchemeGroupVersion)
}
func servingInfoForAddr(addr *flagtypes.Addr) configapi.ServingInfo {
info := configapi.ServingInfo{
BindAddress: addr.URL.Host,
}
if addr.IPv6Host {
info.BindNetwork = "tcp6"
}
return info
}