Skip to content

Commit 3ddb72c

Browse files
Michelle Coneashvindeodhar
authored andcommitted
Add dns capabilities to allow for custom dns in Windows (#305)
* Add dns capabilities to allow for custom dns in Windows Co-authored-by: James Sturtevant <[email protected]> * Move customDNS logic for Windows into network_windows.go and update link for RuntimeDNSConfig Co-authored-by: James Sturtevant <[email protected]> * Concatenate the elements of DNS.Searches
1 parent d8d848f commit 3ddb72c

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

cni/azure-windows.conflist

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"mode": "bridge",
88
"bridge": "azure0",
99
"capabilities": {
10-
"portMappings": true
10+
"portMappings": true,
11+
"dns": true
1112
},
1213
"ipam": {
1314
"type": "azure-vnet-ipam"

cni/netconfig.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,16 @@ type PortMapping struct {
2828
Protocol string `json:"protocol"`
2929
HostIp string `json:"hostIP,omitempty"`
3030
}
31-
3231
type RuntimeConfig struct {
33-
PortMappings []PortMapping `json:"portMappings,omitempty"`
32+
PortMappings []PortMapping `json:"portMappings,omitempty"`
33+
DNS RuntimeDNSConfig `json:"dns,omitempty"`
34+
}
35+
36+
// https://github.com/kubernetes/kubernetes/blob/master/pkg/kubelet/dockershim/network/cni/cni.go#L104
37+
type RuntimeDNSConfig struct {
38+
Servers []string `json:"servers,omitempty"`
39+
Searches []string `json:"searches,omitempty"`
40+
Options []string `json:"options,omitempty"`
3441
}
3542

3643
// NetworkConfig represents Azure CNI plugin network configuration.

cni/network/network_windows.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ func setupInfraVnetRoutingForMultitenancy(
134134
func getNetworkDNSSettings(nwCfg *cni.NetworkConfig, result *cniTypesCurr.Result, namespace string) (network.DNSInfo, error) {
135135
var nwDNS network.DNSInfo
136136

137+
// use custom dns if present
138+
nwDNS = getCustomDNS(nwCfg)
139+
if len(nwDNS.Servers) > 0 || nwDNS.Suffix != "" {
140+
return nwDNS, nil
141+
}
142+
137143
if (len(nwCfg.DNS.Search) == 0) != (len(nwCfg.DNS.Nameservers) == 0) {
138144
err := fmt.Errorf("Wrong DNS configuration: %+v", nwCfg.DNS)
139145
return nwDNS, err
@@ -149,6 +155,12 @@ func getNetworkDNSSettings(nwCfg *cni.NetworkConfig, result *cniTypesCurr.Result
149155
func getEndpointDNSSettings(nwCfg *cni.NetworkConfig, result *cniTypesCurr.Result, namespace string) (network.DNSInfo, error) {
150156
var epDNS network.DNSInfo
151157

158+
// use custom dns if present
159+
epDNS = getCustomDNS(nwCfg)
160+
if len(epDNS.Servers) > 0 || epDNS.Suffix != "" {
161+
return epDNS, nil
162+
}
163+
152164
if (len(nwCfg.DNS.Search) == 0) != (len(nwCfg.DNS.Nameservers) == 0) {
153165
err := fmt.Errorf("Wrong DNS configuration: %+v", nwCfg.DNS)
154166
return epDNS, err
@@ -192,3 +204,17 @@ func getPoliciesFromRuntimeCfg(nwCfg *cni.NetworkConfig) []policy.Policy {
192204

193205
return policies
194206
}
207+
208+
func getCustomDNS(nwCfg *cni.NetworkConfig) network.DNSInfo {
209+
log.Printf("[net] RuntimeConfigs: %+v", nwCfg.RuntimeConfig)
210+
211+
var search string
212+
if len(nwCfg.RuntimeConfig.DNS.Searches) > 0 {
213+
search = strings.Join(nwCfg.RuntimeConfig.DNS.Searches, ",")
214+
}
215+
216+
return network.DNSInfo{
217+
Servers: nwCfg.RuntimeConfig.DNS.Servers,
218+
Suffix: search,
219+
}
220+
}

0 commit comments

Comments
 (0)