From 60a86590aa610b55d94422aabba70e883af5c392 Mon Sep 17 00:00:00 2001 From: Madhu Venugopal Date: Tue, 14 Jun 2016 14:55:05 -0700 Subject: [PATCH] Use service alias and configure container's --net-alias Signed-off-by: Madhu Venugopal (cherry picked from commit 07e39e9e7283a159efa18bc8f72cb2dc0e4f700f) --- container/container.go | 2 +- daemon/cluster/cluster.go | 2 +- daemon/cluster/executor/container/adapter.go | 1 - daemon/cluster/executor/container/container.go | 4 ++++ daemon/cluster/provider/network.go | 1 + 5 files changed, 7 insertions(+), 3 deletions(-) diff --git a/container/container.go b/container/container.go index ac1ea199fb..d34226922a 100644 --- a/container/container.go +++ b/container/container.go @@ -823,7 +823,7 @@ func (container *Container) BuildCreateEndpointOptions(n libnetwork.Network, epC }) } - createOptions = append(createOptions, libnetwork.CreateOptionService(svcCfg.Name, svcCfg.ID, net.ParseIP(vip), portConfigs)) + createOptions = append(createOptions, libnetwork.CreateOptionService(svcCfg.Name, svcCfg.ID, net.ParseIP(vip), portConfigs, svcCfg.Aliases[n.ID()])) } if !containertypes.NetworkMode(n.Name()).IsUserDefined() { diff --git a/daemon/cluster/cluster.go b/daemon/cluster/cluster.go index 6f3143bd6b..d2f972e721 100644 --- a/daemon/cluster/cluster.go +++ b/daemon/cluster/cluster.go @@ -918,7 +918,7 @@ func populateNetworkID(ctx context.Context, c swarmapi.ControlClient, s *types.S if err != nil { return err } - s.Networks[i] = types.NetworkAttachmentConfig{Target: apiNetwork.ID} + s.Networks[i].Target = apiNetwork.ID } return nil } diff --git a/daemon/cluster/executor/container/adapter.go b/daemon/cluster/executor/container/adapter.go index f24d91bb8e..32768ace8e 100644 --- a/daemon/cluster/executor/container/adapter.go +++ b/daemon/cluster/executor/container/adapter.go @@ -126,7 +126,6 @@ func (c *containerAdapter) create(ctx context.Context, backend executorpkg.Backe if nc != nil { for n, ep := range nc.EndpointsConfig { - logrus.Errorf("CONNECT %s : %v", n, ep.IPAMConfig.IPv4Address) if err := backend.ConnectContainerToNetwork(cr.ID, n, ep); err != nil { return err } diff --git a/daemon/cluster/executor/container/container.go b/daemon/cluster/executor/container/container.go index 1326bf1a8b..fcd0cba157 100644 --- a/daemon/cluster/executor/container/container.go +++ b/daemon/cluster/executor/container/container.go @@ -348,6 +348,7 @@ func (c *containerConfig) serviceConfig() *clustertypes.ServiceConfig { log.Printf("Creating service config in agent for t = %+v", c.task) svcCfg := &clustertypes.ServiceConfig{ Name: c.task.ServiceAnnotations.Name, + Aliases: make(map[string][]string), ID: c.task.ServiceID, VirtualAddresses: make(map[string]*clustertypes.VirtualAddress), } @@ -357,6 +358,9 @@ func (c *containerConfig) serviceConfig() *clustertypes.ServiceConfig { // We support only IPv4 virtual IP for now. IPv4: c.virtualIP(na.Network.ID), } + if len(na.Aliases) > 0 { + svcCfg.Aliases[na.Network.ID] = na.Aliases + } } if c.task.Endpoint != nil { diff --git a/daemon/cluster/provider/network.go b/daemon/cluster/provider/network.go index d959c15ceb..a383343d7c 100644 --- a/daemon/cluster/provider/network.go +++ b/daemon/cluster/provider/network.go @@ -31,6 +31,7 @@ type PortConfig struct { type ServiceConfig struct { ID string Name string + Aliases map[string][]string VirtualAddresses map[string]*VirtualAddress ExposedPorts []*PortConfig }