Remove HNSNetwork's DNS suffix in Windows (#254)

* remove network dns suffix and preserve endpoint dns suffix
This commit is contained in:
Yongli Chen 2018-10-10 15:30:05 -07:00 коммит произвёл Sushant Sharma
Родитель a5018cfa6e
Коммит 530d13adf2
4 изменённых файлов: 49 добавлений и 28 удалений

Просмотреть файл

@ -6,7 +6,6 @@ package network
import (
"fmt"
"net"
"strings"
"github.com/Azure/azure-container-networking/cni"
"github.com/Azure/azure-container-networking/cns"
@ -327,6 +326,14 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error {
return err
}
nwDNSInfo, err := getNetworkDNSSettings(nwCfg, result, k8sNamespace)
if err != nil {
err = plugin.Errorf("Failed to getDNSSettings: %v", err)
return err
}
log.Printf("[cni-net] nwDNSInfo: %v", nwDNSInfo)
// Create the network.
nwInfo := network.NetworkInfo{
Id: networkId,
@ -340,11 +347,8 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error {
},
BridgeName: nwCfg.Bridge,
EnableSnatOnHost: nwCfg.EnableSnatOnHost,
DNS: network.DNSInfo{
Servers: nwCfg.DNS.Nameservers,
Suffix: k8sNamespace + "." + strings.Join(nwCfg.DNS.Search, ","),
},
Policies: policies,
DNS: nwDNSInfo,
Policies: policies,
}
nwInfo.Options = make(map[string]interface{})
@ -386,6 +390,12 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error {
}
}
epDNSInfo, err := getEndpointDNSSettings(nwCfg, result, k8sNamespace)
if err != nil {
err = plugin.Errorf("Failed to getEndpointDNSSettings: %v", err)
return err
}
epInfo = &network.EndpointInfo{
Id: endpointId,
ContainerID: args.ContainerID,
@ -393,17 +403,10 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error {
IfName: args.IfName,
EnableSnatOnHost: nwCfg.EnableSnatOnHost,
EnableInfraVnet: enableInfraVnet,
Data: make(map[string]interface{}),
DNS: epDNSInfo,
Policies: policies,
}
epInfo.Data = make(map[string]interface{})
dns, err := getDNSSettings(nwCfg, result, k8sNamespace)
if err != nil {
log.Printf("Error retrieving dns settings %v", err)
return err
}
epInfo.DNS = dns
epInfo.Policies = policies
// Populate addresses.
for _, ipconfig := range result.IPs {

Просмотреть файл

@ -80,20 +80,24 @@ func setupInfraVnetRoutingForMultitenancy(
}
}
func getDNSSettings(nwCfg *cni.NetworkConfig, result *cniTypesCurr.Result, namespace string) (network.DNSInfo, error) {
var dns network.DNSInfo
func getNetworkDNSSettings(nwCfg *cni.NetworkConfig, result *cniTypesCurr.Result, namespace string) (network.DNSInfo, error) {
var nwDNS network.DNSInfo
if len(nwCfg.DNS.Nameservers) > 0 {
dns = network.DNSInfo{
nwDNS = network.DNSInfo{
Servers: nwCfg.DNS.Nameservers,
Suffix: nwCfg.DNS.Domain,
}
} else {
dns = network.DNSInfo{
nwDNS = network.DNSInfo{
Suffix: result.DNS.Domain,
Servers: result.DNS.Nameservers,
}
}
return dns, nil
return nwDNS, nil
}
func getEndpointDNSSettings(nwCfg *cni.NetworkConfig, result *cniTypesCurr.Result, namespace string) (network.DNSInfo, error) {
return getNetworkDNSSettings(nwCfg, result, namespace)
}

Просмотреть файл

@ -83,25 +83,40 @@ func setupInfraVnetRoutingForMultitenancy(
result *cniTypesCurr.Result) {
}
func getDNSSettings(nwCfg *cni.NetworkConfig, result *cniTypesCurr.Result, namespace string) (network.DNSInfo, error) {
var dns network.DNSInfo
func getNetworkDNSSettings(nwCfg *cni.NetworkConfig, result *cniTypesCurr.Result, namespace string) (network.DNSInfo, error) {
var nwDNS network.DNSInfo
if (len(nwCfg.DNS.Search) == 0) != (len(nwCfg.DNS.Nameservers) == 0) {
err := fmt.Errorf("Wrong DNS configuration: %+v", nwCfg.DNS)
return dns, err
return nwDNS, err
}
nwDNS = network.DNSInfo{
Servers: nwCfg.DNS.Nameservers,
}
return nwDNS, nil
}
func getEndpointDNSSettings(nwCfg *cni.NetworkConfig, result *cniTypesCurr.Result, namespace string) (network.DNSInfo, error) {
var epDNS network.DNSInfo
if (len(nwCfg.DNS.Search) == 0) != (len(nwCfg.DNS.Nameservers) == 0) {
err := fmt.Errorf("Wrong DNS configuration: %+v", nwCfg.DNS)
return epDNS, err
}
if len(nwCfg.DNS.Search) > 0 {
dns = network.DNSInfo{
epDNS = network.DNSInfo{
Servers: nwCfg.DNS.Nameservers,
Suffix: namespace + "." + strings.Join(nwCfg.DNS.Search, ","),
}
} else {
dns = network.DNSInfo{
epDNS = network.DNSInfo{
Suffix: result.DNS.Domain,
Servers: result.DNS.Nameservers,
}
}
return dns, nil
return epDNS, nil
}

Просмотреть файл

@ -33,7 +33,6 @@ func (nm *networkManager) newNetworkImpl(nwInfo *NetworkInfo, extIf *externalInt
hnsNetwork := &hcsshim.HNSNetwork{
Name: nwInfo.Id,
NetworkAdapterName: networkAdapterName,
DNSSuffix: nwInfo.DNS.Suffix,
DNSServerList: strings.Join(nwInfo.DNS.Servers, ","),
Policies: policy.SerializePolicies(policy.NetworkPolicy, nwInfo.Policies),
}