Changes required to support windows service discovery

Signed-off-by: msabansal <sabansal@microsoft.com>
This commit is contained in:
msabansal 2016-09-12 17:17:09 -07:00
parent dc8631ea53
commit d1e0a78614
8 changed files with 43 additions and 7 deletions

View file

@ -782,7 +782,7 @@ func (container *Container) BuildJoinOptions(n libnetwork.Network) ([]libnetwork
}
// BuildCreateEndpointOptions builds endpoint options from a given network.
func (container *Container) BuildCreateEndpointOptions(n libnetwork.Network, epConfig *networktypes.EndpointSettings, sb libnetwork.Sandbox) ([]libnetwork.EndpointOption, error) {
func (container *Container) BuildCreateEndpointOptions(n libnetwork.Network, epConfig *networktypes.EndpointSettings, sb libnetwork.Sandbox, daemonDNS []string) ([]libnetwork.EndpointOption, error) {
var (
bindings = make(nat.PortMap)
pbList []types.PortBinding
@ -792,7 +792,8 @@ func (container *Container) BuildCreateEndpointOptions(n libnetwork.Network, epC
defaultNetName := runconfig.DefaultDaemonNetworkMode().NetworkName()
if n.Name() == defaultNetName || container.NetworkSettings.IsAnonymousEndpoint {
if (!container.EnableServiceDiscoveryOnDefaultNetwork() && n.Name() == defaultNetName) ||
container.NetworkSettings.IsAnonymousEndpoint {
createOptions = append(createOptions, libnetwork.CreateOptionAnonymous())
}
@ -914,6 +915,19 @@ func (container *Container) BuildCreateEndpointOptions(n libnetwork.Network, epC
}
}
var dns []string
if len(container.HostConfig.DNS) > 0 {
dns = container.HostConfig.DNS
} else if len(daemonDNS) > 0 {
dns = daemonDNS
}
if len(dns) > 0 {
createOptions = append(createOptions,
libnetwork.CreateOptionDNS(dns))
}
createOptions = append(createOptions,
libnetwork.CreateOptionPortMapping(pbList),
libnetwork.CreateOptionExposedPorts(exposeList))

View file

@ -93,3 +93,8 @@ func (container *Container) BuildHostnameFile() error {
func (container *Container) canMountFS() bool {
return true
}
// EnableServiceDiscoveryOnDefaultNetwork Enable service discovery on default network
func (container *Container) EnableServiceDiscoveryOnDefaultNetwork() bool {
return false
}

View file

@ -428,3 +428,8 @@ func cleanResourcePath(path string) string {
func (container *Container) canMountFS() bool {
return true
}
// EnableServiceDiscoveryOnDefaultNetwork Enable service discovery on default network
func (container *Container) EnableServiceDiscoveryOnDefaultNetwork() bool {
return false
}

View file

@ -110,3 +110,8 @@ func (container *Container) BuildHostnameFile() error {
func (container *Container) canMountFS() bool {
return !containertypes.Isolation.IsHyperV(container.HostConfig.Isolation)
}
// EnableServiceDiscoveryOnDefaultNetwork Enable service discovery on default network
func (container *Container) EnableServiceDiscoveryOnDefaultNetwork() bool {
return true
}

View file

@ -597,11 +597,12 @@ func cleanOperationalData(es *network.EndpointSettings) {
}
func (daemon *Daemon) updateNetworkConfig(container *container.Container, n libnetwork.Network, endpointConfig *networktypes.EndpointSettings, updateSettings bool) error {
if !containertypes.NetworkMode(n.Name()).IsUserDefined() {
if hasUserDefinedIPAddress(endpointConfig) && !enableIPOnPredefinedNetwork() {
return runconfig.ErrUnsupportedNetworkAndIP
}
if endpointConfig != nil && len(endpointConfig.Aliases) > 0 {
if endpointConfig != nil && len(endpointConfig.Aliases) > 0 && !container.EnableServiceDiscoveryOnDefaultNetwork() {
return runconfig.ErrUnsupportedNetworkAndAlias
}
} else {
@ -673,9 +674,8 @@ func (daemon *Daemon) connectToNetwork(container *container.Container, idOrName
}
controller := daemon.netController
sb := daemon.getNetworkSandbox(container)
createOptions, err := container.BuildCreateEndpointOptions(n, endpointConfig, sb)
createOptions, err := container.BuildCreateEndpointOptions(n, endpointConfig, sb, daemon.configStore.DNS)
if err != nil {
return err
}

View file

@ -53,6 +53,7 @@ func (daemon *Daemon) getLibcontainerdCreateOptions(container *container.Contain
// Get endpoints for the libnetwork allocated networks to the container
var epList []string
AllowUnqualifiedDNSQuery := false
if container.NetworkSettings != nil {
for n := range container.NetworkSettings.Networks {
sn, err := daemon.FindNetwork(n)
@ -72,6 +73,10 @@ func (daemon *Daemon) getLibcontainerdCreateOptions(container *container.Contain
if data["hnsid"] != nil {
epList = append(epList, data["hnsid"].(string))
}
if data["AllowUnqualifiedDNSQuery"] != nil {
AllowUnqualifiedDNSQuery = true
}
}
}
@ -80,7 +85,7 @@ func (daemon *Daemon) getLibcontainerdCreateOptions(container *container.Contain
createOptions = append(createOptions, hvOpts)
createOptions = append(createOptions, layerOpts)
if epList != nil {
createOptions = append(createOptions, &libcontainerd.NetworkEndpointsOption{Endpoints: epList})
createOptions = append(createOptions, &libcontainerd.NetworkEndpointsOption{Endpoints: epList, AllowUnqualifiedDNSQuery: AllowUnqualifiedDNSQuery})
}
return &createOptions, nil

View file

@ -150,6 +150,7 @@ func (clnt *client) Create(containerID string, checkpoint string, checkpointDir
}
if n, ok := option.(*NetworkEndpointsOption); ok {
configuration.EndpointList = n.Endpoints
configuration.AllowUnqualifiedDNSQuery = n.AllowUnqualifiedDNSQuery
continue
}
}

View file

@ -64,7 +64,8 @@ type LayerOption struct {
// NetworkEndpointsOption is a CreateOption that provides the runtime list
// of network endpoints to which a container should be attached during its creation.
type NetworkEndpointsOption struct {
Endpoints []string
Endpoints []string
AllowUnqualifiedDNSQuery bool
}
// Checkpoint holds the details of a checkpoint (not supported in windows)