Skip to content

Commit 162c5c0

Browse files
Add a dnsBindAddress configuration to the node
Allows the installer to start node DNS without having to set a config flag. BindAddress is consistent with others of this type.
1 parent 98e19bc commit 162c5c0

File tree

11 files changed

+42
-17
lines changed

11 files changed

+42
-17
lines changed

docs/man/man1/openshift-start-network.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ will start the network proxy and SDN plugins with given configuration file. The
3535
The set of network components to disable
3636

3737
.PP
38-
\fB\-\-enable\fP="plugins,proxy"
38+
\fB\-\-enable\fP="dns,plugins,proxy"
3939
The set of network components to enable
4040

4141
.PP

docs/man/man1/openshift-start-node.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ will start a node with given configuration file. The node will run in the foregr
3939
The set of node components to disable
4040

4141
.PP
42-
\fB\-\-enable\fP="kubelet,plugins,proxy"
42+
\fB\-\-enable\fP="dns,kubelet,plugins,proxy"
4343
The set of node components to enable
4444

4545
.PP

pkg/cmd/server/api/types.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,14 @@ type NodeConfig struct {
112112
// MasterClientConnectionOverrides provides overrides to the client connection used to connect to the master.
113113
MasterClientConnectionOverrides *ClientConnectionOverrides
114114

115+
// DNSBindAddress is the ip:port to serve on. If this is not set, the DNS server will not be started.
116+
DNSBindAddress string
117+
115118
// DNSDomain holds the domain suffix
116119
DNSDomain string
117120

118-
// DNSIP holds the IP
121+
// DNSIP is the IP address that the DNS server will listen on and which will be reported into pods. Defaults
122+
// to the service IP of the Kubernetes master.
119123
DNSIP string
120124

121125
// NetworkConfig provides network options for the node

pkg/cmd/server/api/v1/swagger_doc.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,8 +531,9 @@ var map_NodeConfig = map[string]string{
531531
"servingInfo": "ServingInfo describes how to start serving",
532532
"masterKubeConfig": "MasterKubeConfig is a filename for the .kubeconfig file that describes how to connect this node to the master",
533533
"masterClientConnectionOverrides": "MasterClientConnectionOverrides provides overrides to the client connection used to connect to the master.",
534+
"dnsBindAddress": "DNSBindAddress is the ip:port to serve on. If this is not set, the DNS server will not be started.",
534535
"dnsDomain": "DNSDomain holds the domain suffix",
535-
"dnsIP": "DNSIP holds the IP",
536+
"dnsIP": "DNSIP is the IP address that the DNS server will listen on and which will be reported into pods. Defaults to the service IP of the Kubernetes master. This IP must be listening on port 53 for compatibility with libc resolvers (which cannot be configured to resolve names from any other port).",
536537
"networkPluginName": "Deprecated and maintained for backward compatibility, use NetworkConfig.NetworkPluginName instead",
537538
"networkConfig": "NetworkConfig provides network options for the node",
538539
"volumeDirectory": "VolumeDirectory is the directory that volumes will be stored under",

pkg/cmd/server/api/v1/types.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,15 @@ type NodeConfig struct {
2929
// MasterClientConnectionOverrides provides overrides to the client connection used to connect to the master.
3030
MasterClientConnectionOverrides *ClientConnectionOverrides `json:"masterClientConnectionOverrides"`
3131

32+
// DNSBindAddress is the ip:port to serve on. If this is not set, the DNS server will not be started.
33+
DNSBindAddress string `json:"dnsBindAddress"`
34+
3235
// DNSDomain holds the domain suffix
3336
DNSDomain string `json:"dnsDomain"`
3437

35-
// DNSIP holds the IP
38+
// DNSIP is the IP address that the DNS server will listen on and which will be reported into pods. Defaults
39+
// to the service IP of the Kubernetes master. This IP must be listening on port 53 for compatibility with
40+
// libc resolvers (which cannot be configured to resolve names from any other port).
3641
DNSIP string `json:"dnsIP"`
3742

3843
// Deprecated and maintained for backward compatibility, use NetworkConfig.NetworkPluginName instead

pkg/cmd/server/api/v1/types_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ authConfig:
3131
authenticationCacheTTL: ""
3232
authorizationCacheSize: 0
3333
authorizationCacheTTL: ""
34+
dnsBindAddress: ""
3435
dnsDomain: ""
3536
dnsIP: ""
3637
dockerConfig:

pkg/cmd/server/api/validation/node.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ func ValidateNodeConfig(config *api.NodeConfig, fldPath *field.Path) ValidationR
2828
}
2929
validationResults.AddErrors(ValidateKubeConfig(config.MasterKubeConfig, fldPath.Child("masterKubeConfig"))...)
3030

31+
if len(config.DNSBindAddress) > 0 {
32+
validationResults.AddErrors(ValidateHostPort(config.DNSBindAddress, fldPath.Child("dnsBindAddress"))...)
33+
}
3134
if len(config.DNSIP) > 0 {
3235
validationResults.AddErrors(ValidateSpecifiedIP(config.DNSIP, fldPath.Child("dnsIP"))...)
3336
}

pkg/cmd/server/kubernetes/node_config.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ func BuildKubernetesNodeConfig(options configapi.NodeConfig, enableProxy, enable
317317
if len(options.DNSIP) > 0 {
318318
dnsConfig.DnsAddr = options.DNSIP + ":53"
319319
}
320+
if len(options.DNSBindAddress) > 0 {
321+
dnsConfig.DnsAddr = options.DNSBindAddress
322+
}
320323
dnsConfig.Domain = server.ClusterDomain + "."
321324
dnsConfig.Local = "openshift.default.svc." + dnsConfig.Domain
322325

@@ -329,7 +332,7 @@ func BuildKubernetesNodeConfig(options configapi.NodeConfig, enableProxy, enable
329332

330333
// TODO: use kubeletConfig.ResolverConfig as an argument to etcd in the event the
331334
// user sets it, instead of passing it to the kubelet.
332-
335+
glog.Infof("DNS Bind to %s", options.DNSBindAddress)
333336
config.ServiceStore = serviceStore
334337
config.EndpointsStore = endpointsStore
335338
config.DNSServer = &dns.Server{

pkg/cmd/server/start/node_args.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ func NewNodeComponentFlag() *utilflags.ComponentFlag {
3737
return utilflags.NewComponentFlag(
3838
map[string][]string{ComponentGroupNetwork: {ComponentProxy, ComponentPlugins}},
3939
ComponentKubelet, ComponentProxy, ComponentPlugins, ComponentDNS,
40-
).DefaultDisable(ComponentDNS)
40+
).DefaultEnable(ComponentDNS)
4141
}
4242

4343
// NewNodeComponentFlag returns a flag capable of handling enabled components for the network
4444
func NewNetworkComponentFlag() *utilflags.ComponentFlag {
45-
return utilflags.NewComponentFlag(nil, ComponentProxy, ComponentPlugins, ComponentDNS).DefaultDisable(ComponentDNS)
45+
return utilflags.NewComponentFlag(nil, ComponentProxy, ComponentPlugins, ComponentDNS).DefaultEnable(ComponentDNS)
4646
}
4747

4848
// NodeArgs is a struct that the command stores flag values into. It holds a partially complete set of parameters for starting a node.
@@ -69,6 +69,8 @@ type NodeArgs struct {
6969
DefaultKubernetesURL *url.URL
7070
ClusterDomain string
7171
ClusterDNS net.IP
72+
// DNSBindAddr is provided for the all-in-one start only and is not exposed via a flag
73+
DNSBindAddr string
7274

7375
// NetworkPluginName is the network plugin to be called for configuring networking for pods.
7476
NetworkPluginName string
@@ -186,8 +188,9 @@ func (args NodeArgs) BuildSerializeableNodeConfig() (*configapi.NodeConfig, erro
186188
VolumeDirectory: args.VolumeDir,
187189
AllowDisabledDocker: args.AllowDisabledDocker,
188190

189-
DNSDomain: args.ClusterDomain,
190-
DNSIP: dnsIP,
191+
DNSBindAddress: args.DNSBindAddr,
192+
DNSDomain: args.ClusterDomain,
193+
DNSIP: dnsIP,
191194

192195
MasterKubeConfig: admin.DefaultNodeKubeConfigFile(args.ConfigDir.Value()),
193196

pkg/cmd/server/start/start_allinone.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,16 @@ func (o *AllInOneOptions) Complete() error {
259259
}
260260

261261
// if node DNS is still enabled, then default the node cluster DNS to a reachable master address
262-
if o.NodeArgs.Components.Enabled(ComponentDNS) && o.NodeArgs.ClusterDNS == nil {
263-
if dnsIP, err := findLocalIPForDNS(o.MasterOptions.MasterArgs); err == nil {
264-
o.NodeArgs.ClusterDNS = dnsIP
265-
} else {
266-
glog.V(2).Infof("Unable to find a local address to report as the node DNS - not using node DNS: %v", err)
262+
if o.NodeArgs.Components.Enabled(ComponentDNS) {
263+
if o.NodeArgs.ClusterDNS == nil {
264+
if dnsIP, err := findLocalIPForDNS(o.MasterOptions.MasterArgs); err == nil {
265+
o.NodeArgs.ClusterDNS = dnsIP
266+
if len(o.NodeArgs.DNSBindAddr) == 0 {
267+
o.NodeArgs.DNSBindAddr = net.JoinHostPort(dnsIP.String(), "53")
268+
}
269+
} else {
270+
glog.V(2).Infof("Unable to find a local address to report as the node DNS - not using node DNS: %v", err)
271+
}
267272
}
268273
}
269274
}

pkg/cmd/server/start/start_node.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ func (o NodeOptions) IsRunFromConfig() bool {
325325
}
326326

327327
func StartNode(nodeConfig configapi.NodeConfig, components *utilflags.ComponentFlag) error {
328-
config, err := kubernetes.BuildKubernetesNodeConfig(nodeConfig, components.Enabled(ComponentProxy), components.Enabled(ComponentDNS))
328+
config, err := kubernetes.BuildKubernetesNodeConfig(nodeConfig, components.Enabled(ComponentProxy), components.Enabled(ComponentDNS) && len(nodeConfig.DNSBindAddress) > 0)
329329
if err != nil {
330330
return err
331331
}
@@ -367,7 +367,7 @@ func StartNode(nodeConfig configapi.NodeConfig, components *utilflags.ComponentF
367367
if components.Enabled(ComponentProxy) {
368368
config.RunProxy()
369369
}
370-
if components.Enabled(ComponentDNS) {
370+
if components.Enabled(ComponentDNS) && config.DNSServer != nil {
371371
config.RunDNS()
372372
}
373373

0 commit comments

Comments
 (0)