forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
master_args.go
640 lines (528 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
package start
import (
"fmt"
"net"
"net/url"
"path"
"strconv"
"github.com/golang/glog"
"github.com/spf13/pflag"
"github.com/GoogleCloudPlatform/kubernetes/pkg/master/ports"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/openshift/origin/pkg/cmd/flagtypes"
"github.com/openshift/origin/pkg/cmd/server/admin"
configapi "github.com/openshift/origin/pkg/cmd/server/api"
"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
// PortalNet is a CIDR notation IP range from which to assign portal IPs. This must not overlap
// with any IP ranges assigned to nodes for pods.
PortalNet flagtypes.IPNet
// 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
PauseControllers bool
// DNSBindAddr exposed for integration tests to set
DNSBindAddr flagtypes.Addr
// EtcdDir is the etcd data directory.
EtcdDir string
ConfigDir *util.StringFlag
// NodeList contains the hostnames of each node. This currently must be specified
// up front. Comma delimited list
NodeList util.StringList
// 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 util.StringList
ListenArg *ListenArg
ImageFormatArgs *ImageFormatArgs
KubeConnectionArgs *KubeConnectionArgs
SchedulerConfigFile string
NetworkArgs *NetworkArgs
}
// 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.PortalNet, prefix+"portal-net", "A CIDR notation IP range from which to assign portal IPs. This must not overlap with any IP ranges assigned to nodes for pods.")
flags.Var(&args.DNSBindAddr, prefix+"dns", "The address to listen for DNS requests on.")
flags.BoolVar(&args.PauseControllers, prefix+"pause", false, "If true, wait for a signal before starting the controllers.")
flags.StringVar(&args.EtcdDir, prefix+"etcd-dir", "openshift.local.etcd", "The etcd data directory.")
flags.Var(&args.NodeList, prefix+"nodes", "The hostnames of each node. This currently must be specified up front. Comma delimited list")
flags.Var(&args.CORSAllowedOrigins, prefix+"cors-allowed-origins", "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")
}
// 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(),
PortalNet: flagtypes.DefaultIPNet("172.30.0.0/16"),
MasterPublicAddr: flagtypes.Addr{Value: "localhost:8443", DefaultScheme: "https", DefaultPort: 8443, AllowPrefix: true}.Default(),
DNSBindAddr: flagtypes.Addr{Value: "0.0.0.0:53", DefaultScheme: "tcp", DefaultPort: 53, AllowPrefix: true}.Default(),
ConfigDir: &util.StringFlag{},
ListenArg: NewDefaultListenArg(),
ImageFormatArgs: NewDefaultImageFormatArgs(),
KubeConnectionArgs: NewDefaultKubeConnectionArgs(),
NetworkArgs: NewDefaultNetworkArgs(),
}
return config
}
// GetPolicyFile returns the policy filepath for master
func (args MasterArgs) GetPolicyFile() string {
return path.Join(args.ConfigDir.Value(), "policy.json")
}
// GetConfigFileToWrite returns the configuration filepath for master
func (args MasterArgs) GetConfigFileToWrite() string {
return path.Join(args.ConfigDir.Value(), "master-config.yaml")
}
// 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
}
// 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 := util.NewStringSet(args.CORSAllowedOrigins...)
corsAllowedOrigins.Insert(assetPublicAddr.Host, masterPublicAddr.Host, "localhost", "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
}
}
builtInKubernetes := len(args.KubeConnectionArgs.ClientConfigLoadingRules.ExplicitPath) == 0
var kubernetesMasterConfig *configapi.KubernetesMasterConfig
if builtInKubernetes {
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())
config := &configapi.MasterConfig{
ServingInfo: configapi.HTTPServingInfo{
ServingInfo: configapi.ServingInfo{
BindAddress: args.ListenArg.ListenAddr.URL.Host,
},
},
CORSAllowedOrigins: corsAllowedOrigins.List(),
MasterPublicURL: masterPublicAddr.String(),
KubernetesMasterConfig: kubernetesMasterConfig,
EtcdConfig: etcdConfig,
OAuthConfig: oauthConfig,
PauseControllers: args.PauseControllers,
AssetConfig: &configapi.AssetConfig{
ServingInfo: configapi.HTTPServingInfo{
ServingInfo: configapi.ServingInfo{
BindAddress: args.GetAssetBindAddress(),
},
},
LogoutURL: "",
MasterPublicURL: masterPublicAddr.String(),
PublicURL: assetPublicAddr.String(),
},
DNSConfig: &configapi.DNSConfig{
BindAddress: dnsBindAddr.URL.Host,
},
MasterClients: configapi.MasterClients{
OpenShiftLoopbackKubeConfig: admin.DefaultKubeConfigFilename(args.ConfigDir.Value(), bootstrappolicy.MasterUnqualifiedUsername),
ExternalKubernetesKubeConfig: args.KubeConnectionArgs.ClientConfigLoadingRules.ExplicitPath,
},
EtcdClientInfo: configapi.EtcdConnectionInfo{
URLs: []string{etcdAddress.String()},
},
KubeletClientInfo: configapi.KubeletConnectionInfo{
Port: ports.KubeletPort,
},
PolicyConfig: configapi.PolicyConfig{
BootstrapPolicyFile: args.GetPolicyFile(),
OpenShiftSharedResourcesNamespace: bootstrappolicy.DefaultOpenShiftSharedResourcesNamespace,
},
ImageConfig: configapi.ImageConfig{
Format: args.ImageFormatArgs.ImageTemplate.Format,
Latest: args.ImageFormatArgs.ImageTemplate.Latest,
},
ProjectConfig: configapi.ProjectConfig{
DefaultNodeSelector: "",
ProjectRequestMessage: "",
ProjectRequestTemplate: "",
// Allocator defaults on
SecurityAllocator: &configapi.SecurityAllocator{},
},
NetworkConfig: configapi.NetworkConfig{
NetworkPluginName: args.NetworkArgs.NetworkPluginName,
ClusterNetworkCIDR: args.NetworkArgs.ClusterNetworkCIDR,
HostSubnetLength: args.NetworkArgs.HostSubnetLength,
},
}
if args.ListenArg.UseTLS() {
config.ServingInfo.ServerCert = admin.DefaultMasterServingCertInfo(args.ConfigDir.Value())
config.ServingInfo.ClientCA = admin.DefaultAPIClientCAFile(args.ConfigDir.Value())
config.AssetConfig.ServingInfo.ServerCert = admin.DefaultAssetServingCertInfo(args.ConfigDir.Value())
// Only set up ca/cert info for kubelet connections if we're self-hosting Kubernetes
if builtInKubernetes {
config.KubeletClientInfo.CA = admin.DefaultRootCAFile(args.ConfigDir.Value())
config.KubeletClientInfo.ClientCert = kubeletClientInfo.CertLocation
config.ServiceAccountConfig.MasterCA = admin.DefaultRootCAFile(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
}
}
if builtInKubernetes {
// When we start Kubernetes, 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()),
}
} else {
// When running against an external Kubernetes, we're only responsible for the builder and deployer accounts.
// We don't have the private key, but we need to get the public key to authenticate signed tokens.
// TODO: JTL: take arg for public key(s)?
config.ServiceAccountConfig.ManagedNames = []string{
bootstrappolicy.BuilderServiceAccountName,
bootstrappolicy.DeployerServiceAccountName,
}
config.ServiceAccountConfig.PublicKeyFiles = []string{}
}
// Roundtrip the config to v1 and back to ensure proper defaults are set.
ext, err := configapi.Scheme.ConvertToVersion(config, "v1")
if err != nil {
return nil, err
}
internal, err := configapi.Scheme.ConvertToVersion(ext, "")
if err != nil {
return nil, err
}
return internal.(*configapi.MasterConfig), 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: "auto",
},
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
},
}
// Make sure we don't start up in a permissive auth mode they don't expect
if cmdutil.Env("OPENSHIFT_OAUTH_HANDLER", "login") != "login" {
return nil, fmt.Errorf("OPENSHIFT_OAUTH_HANDLER is deprecated. Use the master configuration file to configure OAuth.")
}
if cmdutil.Env("OPENSHIFT_OAUTH_PASSWORD_AUTH", "anypassword") != "anypassword" {
return nil, fmt.Errorf("OPENSHIFT_OAUTH_PASSWORD_AUTH is deprecated. Use the master configuration file to configure OAuth.")
}
// Warn about deprecation
// TODO: remove before 3.0
deprecated := []string{
"OPENSHIFT_OAUTH_ACCESS_TOKEN_MAX_AGE_SECONDS",
"OPENSHIFT_OAUTH_AUTHORIZE_TOKEN_MAX_AGE_SECONDS",
"OPENSHIFT_OAUTH_GRANT_HANDLER",
"OPENSHIFT_OAUTH_HANDLER",
"OPENSHIFT_OAUTH_PASSWORD_AUTH",
"OPENSHIFT_OAUTH_REQUEST_HANDLERS",
"OPENSHIFT_OAUTH_SESSION_MAX_AGE_SECONDS",
"OPENSHIFT_OAUTH_SESSION_NAME",
"OPENSHIFT_OAUTH_SESSION_SECRET",
}
for _, key := range deprecated {
if value := cmdutil.Env(key, ""); len(value) != 0 {
glog.Warningf("%s is deprecated. Use the master configuration file to configure OAuth.", key)
}
}
config.IdentityProviders = append(config.IdentityProviders,
configapi.IdentityProvider{
Name: "anypassword",
UseAsChallenger: true,
UseAsLogin: true,
Provider: runtime.EmbeddedObject{
&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) {
servicesSubnet := net.IPNet(args.PortalNet)
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()
}
staticNodeList := util.NewStringSet(args.NodeList...)
staticNodeList.Delete("")
config := &configapi.KubernetesMasterConfig{
MasterIP: masterIP,
ServicesSubnet: servicesSubnet.String(),
StaticNodeNames: staticNodeList.List(),
SchedulerConfigFile: args.SchedulerConfigFile,
}
return config, nil
}
func (args MasterArgs) Validate() error {
masterAddr, err := args.GetMasterAddress()
if addr, err := masterAddr, err; err != nil {
return err
} else if len(addr.Path) != 0 {
return fmt.Errorf("master url may not include a path: '%v'", addr.Path)
}
if addr, err := args.GetMasterPublicAddress(); err != nil {
return err
} else 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
}
if addr, err := args.KubeConnectionArgs.GetKubernetesAddress(masterAddr); err != nil {
return err
} else 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() (util.StringSet, 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 := util.NewStringSet("localhost", "127.0.0.1", "openshift.default.svc.cluster.local", "kubernetes.default.svc.cluster.local", masterAddr.Host, masterPublicAddr.Host, assetPublicAddr.Host)
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 := util.StringSet{}
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: 53}.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 (args MasterArgs) GetAssetBindAddress() string {
return args.ListenArg.ListenAddr.URL.Host
}
func getHost(theURL url.URL) string {
host, _, err := net.SplitHostPort(theURL.Host)
if err != nil {
return theURL.Host
}
return host
}
func getPort(theURL url.URL) int {
_, port, err := net.SplitHostPort(theURL.Host)
if err != nil {
return 0
}
intport, _ := strconv.Atoi(port)
return intport
}