libnetwork: return concrete-typed *Endpoint

libnetwork.Endpoint is an interface with a single implementation.

https://github.com/golang/go/wiki/CodeReviewComments#interfaces

Signed-off-by: Cory Snider <csnider@mirantis.com>
This commit is contained in:
Cory Snider 2023-01-11 20:42:24 -05:00
parent 581f005aad
commit c71555f030
20 changed files with 193 additions and 230 deletions

View file

@ -83,7 +83,7 @@ func (p *bridgeProvider) New() (network.Namespace, error) {
} }
type lnInterface struct { type lnInterface struct {
ep libnetwork.Endpoint ep *libnetwork.Endpoint
sbx *libnetwork.Sandbox sbx *libnetwork.Sandbox
sync.Once sync.Once
err error err error

View file

@ -291,7 +291,7 @@ func (daemon *Daemon) updateNetworkSettings(container *container.Container, n li
return nil return nil
} }
func (daemon *Daemon) updateEndpointNetworkSettings(container *container.Container, n libnetwork.Network, ep libnetwork.Endpoint) error { func (daemon *Daemon) updateEndpointNetworkSettings(container *container.Container, n libnetwork.Network, ep *libnetwork.Endpoint) error {
if err := buildEndpointInfo(container.NetworkSettings, n, ep); err != nil { if err := buildEndpointInfo(container.NetworkSettings, n, ep); err != nil {
return err return err
} }
@ -834,7 +834,7 @@ func (daemon *Daemon) connectToNetwork(container *container.Container, idOrName
return nil return nil
} }
func updateJoinInfo(networkSettings *network.Settings, n libnetwork.Network, ep libnetwork.Endpoint) error { func updateJoinInfo(networkSettings *network.Settings, n libnetwork.Network, ep *libnetwork.Endpoint) error {
if ep == nil { if ep == nil {
return errors.New("invalid enppoint whhile building portmap info") return errors.New("invalid enppoint whhile building portmap info")
} }
@ -881,11 +881,11 @@ func (daemon *Daemon) ForceEndpointDelete(name string, networkName string) error
func (daemon *Daemon) disconnectFromNetwork(container *container.Container, n libnetwork.Network, force bool) error { func (daemon *Daemon) disconnectFromNetwork(container *container.Container, n libnetwork.Network, force bool) error {
var ( var (
ep libnetwork.Endpoint ep *libnetwork.Endpoint
sbox *libnetwork.Sandbox sbox *libnetwork.Sandbox
) )
s := func(current libnetwork.Endpoint) bool { s := func(current *libnetwork.Endpoint) bool {
epInfo := current.Info() epInfo := current.Info()
if epInfo == nil { if epInfo == nil {
return false return false

View file

@ -969,7 +969,7 @@ func getPortMapInfo(sb *libnetwork.Sandbox) nat.PortMap {
return pm return pm
} }
func getEndpointPortMapInfo(ep libnetwork.Endpoint) (nat.PortMap, error) { func getEndpointPortMapInfo(ep *libnetwork.Endpoint) (nat.PortMap, error) {
pm := nat.PortMap{} pm := nat.PortMap{}
driverInfo, err := ep.DriverInfo() driverInfo, err := ep.DriverInfo()
if err != nil { if err != nil {
@ -1013,7 +1013,7 @@ func getEndpointPortMapInfo(ep libnetwork.Endpoint) (nat.PortMap, error) {
} }
// buildEndpointInfo sets endpoint-related fields on container.NetworkSettings based on the provided network and endpoint. // buildEndpointInfo sets endpoint-related fields on container.NetworkSettings based on the provided network and endpoint.
func buildEndpointInfo(networkSettings *internalnetwork.Settings, n libnetwork.Network, ep libnetwork.Endpoint) error { func buildEndpointInfo(networkSettings *internalnetwork.Settings, n libnetwork.Network, ep *libnetwork.Endpoint) error {
if ep == nil { if ep == nil {
return errors.New("endpoint cannot be nil") return errors.New("endpoint cannot be nil")
} }

View file

@ -7,7 +7,7 @@ import (
) )
// getEndpointInNetwork returns the container's endpoint to the provided network. // getEndpointInNetwork returns the container's endpoint to the provided network.
func getEndpointInNetwork(name string, n libnetwork.Network) (libnetwork.Endpoint, error) { func getEndpointInNetwork(name string, n libnetwork.Network) (*libnetwork.Endpoint, error) {
endpointName := strings.TrimPrefix(name, "/") endpointName := strings.TrimPrefix(name, "/")
return n.EndpointByName(endpointName) return n.EndpointByName(endpointName)
} }

View file

@ -551,7 +551,7 @@ func (n *network) leaveCluster() error {
return agent.networkDB.LeaveNetwork(n.ID()) return agent.networkDB.LeaveNetwork(n.ID())
} }
func (ep *endpoint) addDriverInfoToCluster() error { func (ep *Endpoint) addDriverInfoToCluster() error {
n := ep.getNetwork() n := ep.getNetwork()
if !n.isClusterEligible() { if !n.isClusterEligible() {
return nil return nil
@ -573,7 +573,7 @@ func (ep *endpoint) addDriverInfoToCluster() error {
return nil return nil
} }
func (ep *endpoint) deleteDriverInfoFromCluster() error { func (ep *Endpoint) deleteDriverInfoFromCluster() error {
n := ep.getNetwork() n := ep.getNetwork()
if !n.isClusterEligible() { if !n.isClusterEligible() {
return nil return nil
@ -595,7 +595,7 @@ func (ep *endpoint) deleteDriverInfoFromCluster() error {
return nil return nil
} }
func (ep *endpoint) addServiceInfoToCluster(sb *Sandbox) error { func (ep *Endpoint) addServiceInfoToCluster(sb *Sandbox) error {
if ep.isAnonymous() && len(ep.myAliases) == 0 || ep.Iface() == nil || ep.Iface().Address() == nil { if ep.isAnonymous() && len(ep.myAliases) == 0 || ep.Iface() == nil || ep.Iface().Address() == nil {
return nil return nil
} }
@ -677,7 +677,7 @@ func (ep *endpoint) addServiceInfoToCluster(sb *Sandbox) error {
return nil return nil
} }
func (ep *endpoint) deleteServiceInfoFromCluster(sb *Sandbox, fullRemove bool, method string) error { func (ep *Endpoint) deleteServiceInfoFromCluster(sb *Sandbox, fullRemove bool, method string) error {
if ep.isAnonymous() && len(ep.myAliases) == 0 { if ep.isAnonymous() && len(ep.myAliases) == 0 {
return nil return nil
} }
@ -742,7 +742,7 @@ func (ep *endpoint) deleteServiceInfoFromCluster(sb *Sandbox, fullRemove bool, m
return nil return nil
} }
func disableServiceInNetworkDB(a *agent, n *network, ep *endpoint) { func disableServiceInNetworkDB(a *agent, n *network, ep *Endpoint) {
var epRec EndpointRecord var epRec EndpointRecord
logrus.Debugf("disableServiceInNetworkDB for %s %s", ep.svcName, ep.ID()) logrus.Debugf("disableServiceInNetworkDB for %s %s", ep.svcName, ep.ID())

View file

@ -90,8 +90,8 @@ type Controller struct {
cfg *config.Config cfg *config.Config
stores []datastore.DataStore stores []datastore.DataStore
extKeyListener net.Listener extKeyListener net.Listener
watchCh chan *endpoint watchCh chan *Endpoint
unWatchCh chan *endpoint unWatchCh chan *Endpoint
svcRecords map[string]svcInfo svcRecords map[string]svcInfo
nmap map[string]*netWatch nmap map[string]*netWatch
serviceBindings map[serviceKey]*service serviceBindings map[serviceKey]*service
@ -959,7 +959,7 @@ func (c *Controller) NewSandbox(containerID string, options ...SandboxOption) (*
sb = &Sandbox{ sb = &Sandbox{
id: sandboxID, id: sandboxID,
containerID: containerID, containerID: containerID,
endpoints: []*endpoint{}, endpoints: []*Endpoint{},
epPriority: map[string]int{}, epPriority: map[string]int{},
populatedEndpoints: map[string]struct{}{}, populatedEndpoints: map[string]struct{}{},
config: containerConfig{}, config: containerConfig{},

View file

@ -84,9 +84,7 @@ func (sb *Sandbox) setupDefaultGW() error {
} }
}() }()
epLocal := newEp.(*endpoint) if err = newEp.sbJoin(sb); err != nil {
if err = epLocal.sbJoin(sb); err != nil {
return fmt.Errorf("container %s: endpoint join on GW Network failed: %v", sb.containerID, err) return fmt.Errorf("container %s: endpoint join on GW Network failed: %v", sb.containerID, err)
} }
@ -95,7 +93,7 @@ func (sb *Sandbox) setupDefaultGW() error {
// If present, detach and remove the endpoint connecting the sandbox to the default gw network. // If present, detach and remove the endpoint connecting the sandbox to the default gw network.
func (sb *Sandbox) clearDefaultGW() error { func (sb *Sandbox) clearDefaultGW() error {
var ep *endpoint var ep *Endpoint
if ep = sb.getEndpointInGWNetwork(); ep == nil { if ep = sb.getEndpointInGWNetwork(); ep == nil {
return nil return nil
@ -116,7 +114,7 @@ func (sb *Sandbox) clearDefaultGW() error {
func (sb *Sandbox) needDefaultGW() bool { func (sb *Sandbox) needDefaultGW() bool {
var needGW bool var needGW bool
for _, ep := range sb.getConnectedEndpoints() { for _, ep := range sb.Endpoints() {
if ep.endpointInGWNetwork() { if ep.endpointInGWNetwork() {
continue continue
} }
@ -145,8 +143,8 @@ func (sb *Sandbox) needDefaultGW() bool {
return needGW return needGW
} }
func (sb *Sandbox) getEndpointInGWNetwork() *endpoint { func (sb *Sandbox) getEndpointInGWNetwork() *Endpoint {
for _, ep := range sb.getConnectedEndpoints() { for _, ep := range sb.Endpoints() {
if ep.getNetwork().name == libnGWNetwork && strings.HasPrefix(ep.Name(), "gateway_") { if ep.getNetwork().name == libnGWNetwork && strings.HasPrefix(ep.Name(), "gateway_") {
return ep return ep
} }
@ -154,7 +152,7 @@ func (sb *Sandbox) getEndpointInGWNetwork() *endpoint {
return nil return nil
} }
func (ep *endpoint) endpointInGWNetwork() bool { func (ep *Endpoint) endpointInGWNetwork() bool {
if ep.getNetwork().name == libnGWNetwork && strings.HasPrefix(ep.Name(), "gateway_") { if ep.getNetwork().name == libnGWNetwork && strings.HasPrefix(ep.Name(), "gateway_") {
return true return true
} }
@ -175,8 +173,8 @@ func (c *Controller) defaultGwNetwork() (Network, error) {
} }
// Returns the endpoint which is providing external connectivity to the sandbox // Returns the endpoint which is providing external connectivity to the sandbox
func (sb *Sandbox) getGatewayEndpoint() *endpoint { func (sb *Sandbox) getGatewayEndpoint() *Endpoint {
for _, ep := range sb.getConnectedEndpoints() { for _, ep := range sb.Endpoints() {
if ep.getNetwork().Type() == "null" || ep.getNetwork().Type() == "host" { if ep.getNetwork().Type() == "null" || ep.getNetwork().Type() == "host" {
continue continue
} }

View file

@ -14,40 +14,13 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
// Endpoint represents a logical connection between a network and a sandbox.
type Endpoint interface {
// A system generated id for this endpoint.
ID() string
// Name returns the name of this endpoint.
Name() string
// Network returns the name of the network to which this endpoint is attached.
Network() string
// Join joins the sandbox to the endpoint and populates into the sandbox
// the network resources allocated for the endpoint.
Join(sandbox *Sandbox, options ...EndpointOption) error
// Leave detaches the network resources populated in the sandbox.
Leave(sandbox *Sandbox, options ...EndpointOption) error
// Return certain operational data belonging to this endpoint
Info() EndpointInfo
// DriverInfo returns a collection of driver operational data related to this endpoint retrieved from the driver
DriverInfo() (map[string]interface{}, error)
// Delete and detaches this endpoint from the network.
Delete(force bool) error
}
// EndpointOption is an option setter function type used to pass various options to Network // EndpointOption is an option setter function type used to pass various options to Network
// and Endpoint interfaces methods. The various setter functions of type EndpointOption are // and Endpoint interfaces methods. The various setter functions of type EndpointOption are
// provided by libnetwork, they look like <Create|Join|Leave>Option[...](...) // provided by libnetwork, they look like <Create|Join|Leave>Option[...](...)
type EndpointOption func(ep *endpoint) type EndpointOption func(ep *Endpoint)
type endpoint struct { // Endpoint represents a logical connection between a network and a sandbox.
type Endpoint struct {
name string name string
id string id string
network *network network *network
@ -75,7 +48,7 @@ type endpoint struct {
mu sync.Mutex mu sync.Mutex
} }
func (ep *endpoint) MarshalJSON() ([]byte, error) { func (ep *Endpoint) MarshalJSON() ([]byte, error) {
ep.mu.Lock() ep.mu.Lock()
defer ep.mu.Unlock() defer ep.mu.Unlock()
@ -102,7 +75,7 @@ func (ep *endpoint) MarshalJSON() ([]byte, error) {
return json.Marshal(epMap) return json.Marshal(epMap)
} }
func (ep *endpoint) UnmarshalJSON(b []byte) (err error) { func (ep *Endpoint) UnmarshalJSON(b []byte) (err error) {
ep.mu.Lock() ep.mu.Lock()
defer ep.mu.Unlock() defer ep.mu.Unlock()
@ -221,15 +194,15 @@ func (ep *endpoint) UnmarshalJSON(b []byte) (err error) {
return nil return nil
} }
func (ep *endpoint) New() datastore.KVObject { func (ep *Endpoint) New() datastore.KVObject {
return &endpoint{network: ep.getNetwork()} return &Endpoint{network: ep.getNetwork()}
} }
func (ep *endpoint) CopyTo(o datastore.KVObject) error { func (ep *Endpoint) CopyTo(o datastore.KVObject) error {
ep.mu.Lock() ep.mu.Lock()
defer ep.mu.Unlock() defer ep.mu.Unlock()
dstEp := o.(*endpoint) dstEp := o.(*Endpoint)
dstEp.name = ep.name dstEp.name = ep.name
dstEp.id = ep.id dstEp.id = ep.id
dstEp.sandboxID = ep.sandboxID dstEp.sandboxID = ep.sandboxID
@ -276,28 +249,31 @@ func (ep *endpoint) CopyTo(o datastore.KVObject) error {
return nil return nil
} }
func (ep *endpoint) ID() string { // ID returns the system-generated id for this endpoint.
func (ep *Endpoint) ID() string {
ep.mu.Lock() ep.mu.Lock()
defer ep.mu.Unlock() defer ep.mu.Unlock()
return ep.id return ep.id
} }
func (ep *endpoint) Name() string { // Name returns the name of this endpoint.
func (ep *Endpoint) Name() string {
ep.mu.Lock() ep.mu.Lock()
defer ep.mu.Unlock() defer ep.mu.Unlock()
return ep.name return ep.name
} }
func (ep *endpoint) MyAliases() []string { func (ep *Endpoint) MyAliases() []string {
ep.mu.Lock() ep.mu.Lock()
defer ep.mu.Unlock() defer ep.mu.Unlock()
return ep.myAliases return ep.myAliases
} }
func (ep *endpoint) Network() string { // Network returns the name of the network to which this endpoint is attached.
func (ep *Endpoint) Network() string {
if ep.network == nil { if ep.network == nil {
return "" return ""
} }
@ -305,41 +281,41 @@ func (ep *endpoint) Network() string {
return ep.network.name return ep.network.name
} }
func (ep *endpoint) isAnonymous() bool { func (ep *Endpoint) isAnonymous() bool {
ep.mu.Lock() ep.mu.Lock()
defer ep.mu.Unlock() defer ep.mu.Unlock()
return ep.anonymous return ep.anonymous
} }
// isServiceEnabled check if service is enabled on the endpoint // isServiceEnabled check if service is enabled on the endpoint
func (ep *endpoint) isServiceEnabled() bool { func (ep *Endpoint) isServiceEnabled() bool {
ep.mu.Lock() ep.mu.Lock()
defer ep.mu.Unlock() defer ep.mu.Unlock()
return ep.serviceEnabled return ep.serviceEnabled
} }
// enableService sets service enabled on the endpoint // enableService sets service enabled on the endpoint
func (ep *endpoint) enableService() { func (ep *Endpoint) enableService() {
ep.mu.Lock() ep.mu.Lock()
defer ep.mu.Unlock() defer ep.mu.Unlock()
ep.serviceEnabled = true ep.serviceEnabled = true
} }
// disableService disables service on the endpoint // disableService disables service on the endpoint
func (ep *endpoint) disableService() { func (ep *Endpoint) disableService() {
ep.mu.Lock() ep.mu.Lock()
defer ep.mu.Unlock() defer ep.mu.Unlock()
ep.serviceEnabled = false ep.serviceEnabled = false
} }
func (ep *endpoint) needResolver() bool { func (ep *Endpoint) needResolver() bool {
ep.mu.Lock() ep.mu.Lock()
defer ep.mu.Unlock() defer ep.mu.Unlock()
return !ep.disableResolution return !ep.disableResolution
} }
// endpoint Key structure : endpoint/network-id/endpoint-id // endpoint Key structure : endpoint/network-id/endpoint-id
func (ep *endpoint) Key() []string { func (ep *Endpoint) Key() []string {
if ep.network == nil { if ep.network == nil {
return nil return nil
} }
@ -347,7 +323,7 @@ func (ep *endpoint) Key() []string {
return []string{datastore.EndpointKeyPrefix, ep.network.id, ep.id} return []string{datastore.EndpointKeyPrefix, ep.network.id, ep.id}
} }
func (ep *endpoint) KeyPrefix() []string { func (ep *Endpoint) KeyPrefix() []string {
if ep.network == nil { if ep.network == nil {
return nil return nil
} }
@ -355,7 +331,7 @@ func (ep *endpoint) KeyPrefix() []string {
return []string{datastore.EndpointKeyPrefix, ep.network.id} return []string{datastore.EndpointKeyPrefix, ep.network.id}
} }
func (ep *endpoint) Value() []byte { func (ep *Endpoint) Value() []byte {
b, err := json.Marshal(ep) b, err := json.Marshal(ep)
if err != nil { if err != nil {
return nil return nil
@ -363,34 +339,34 @@ func (ep *endpoint) Value() []byte {
return b return b
} }
func (ep *endpoint) SetValue(value []byte) error { func (ep *Endpoint) SetValue(value []byte) error {
return json.Unmarshal(value, ep) return json.Unmarshal(value, ep)
} }
func (ep *endpoint) Index() uint64 { func (ep *Endpoint) Index() uint64 {
ep.mu.Lock() ep.mu.Lock()
defer ep.mu.Unlock() defer ep.mu.Unlock()
return ep.dbIndex return ep.dbIndex
} }
func (ep *endpoint) SetIndex(index uint64) { func (ep *Endpoint) SetIndex(index uint64) {
ep.mu.Lock() ep.mu.Lock()
defer ep.mu.Unlock() defer ep.mu.Unlock()
ep.dbIndex = index ep.dbIndex = index
ep.dbExists = true ep.dbExists = true
} }
func (ep *endpoint) Exists() bool { func (ep *Endpoint) Exists() bool {
ep.mu.Lock() ep.mu.Lock()
defer ep.mu.Unlock() defer ep.mu.Unlock()
return ep.dbExists return ep.dbExists
} }
func (ep *endpoint) Skip() bool { func (ep *Endpoint) Skip() bool {
return ep.getNetwork().Skip() return ep.getNetwork().Skip()
} }
func (ep *endpoint) processOptions(options ...EndpointOption) { func (ep *Endpoint) processOptions(options ...EndpointOption) {
ep.mu.Lock() ep.mu.Lock()
defer ep.mu.Unlock() defer ep.mu.Unlock()
@ -401,14 +377,14 @@ func (ep *endpoint) processOptions(options ...EndpointOption) {
} }
} }
func (ep *endpoint) getNetwork() *network { func (ep *Endpoint) getNetwork() *network {
ep.mu.Lock() ep.mu.Lock()
defer ep.mu.Unlock() defer ep.mu.Unlock()
return ep.network return ep.network
} }
func (ep *endpoint) getNetworkFromStore() (*network, error) { func (ep *Endpoint) getNetworkFromStore() (*network, error) {
if ep.network == nil { if ep.network == nil {
return nil, fmt.Errorf("invalid network object in endpoint %s", ep.Name()) return nil, fmt.Errorf("invalid network object in endpoint %s", ep.Name())
} }
@ -416,7 +392,9 @@ func (ep *endpoint) getNetworkFromStore() (*network, error) {
return ep.network.getController().getNetworkFromStore(ep.network.id) return ep.network.getController().getNetworkFromStore(ep.network.id)
} }
func (ep *endpoint) Join(sb *Sandbox, options ...EndpointOption) error { // Join joins the sandbox to the endpoint and populates into the sandbox
// the network resources allocated for the endpoint.
func (ep *Endpoint) Join(sb *Sandbox, options ...EndpointOption) error {
if sb == nil || sb.ID() == "" || sb.Key() == "" { if sb == nil || sb.ID() == "" || sb.Key() == "" {
return types.BadRequestErrorf("invalid Sandbox passed to endpoint join: %v", sb) return types.BadRequestErrorf("invalid Sandbox passed to endpoint join: %v", sb)
} }
@ -427,7 +405,7 @@ func (ep *endpoint) Join(sb *Sandbox, options ...EndpointOption) error {
return ep.sbJoin(sb, options...) return ep.sbJoin(sb, options...)
} }
func (ep *endpoint) sbJoin(sb *Sandbox, options ...EndpointOption) (err error) { func (ep *Endpoint) sbJoin(sb *Sandbox, options ...EndpointOption) (err error) {
n, err := ep.getNetworkFromStore() n, err := ep.getNetworkFromStore()
if err != nil { if err != nil {
return fmt.Errorf("failed to get network from store during join: %v", err) return fmt.Errorf("failed to get network from store during join: %v", err)
@ -586,7 +564,7 @@ func (ep *endpoint) sbJoin(sb *Sandbox, options ...EndpointOption) (err error) {
return nil return nil
} }
func (ep *endpoint) rename(name string) error { func (ep *Endpoint) rename(name string) error {
var ( var (
err error err error
netWatch *netWatch netWatch *netWatch
@ -669,14 +647,15 @@ func (ep *endpoint) rename(name string) error {
return err return err
} }
func (ep *endpoint) hasInterface(iName string) bool { func (ep *Endpoint) hasInterface(iName string) bool {
ep.mu.Lock() ep.mu.Lock()
defer ep.mu.Unlock() defer ep.mu.Unlock()
return ep.iface != nil && ep.iface.srcName == iName return ep.iface != nil && ep.iface.srcName == iName
} }
func (ep *endpoint) Leave(sb *Sandbox, options ...EndpointOption) error { // Leave detaches the network resources populated in the sandbox.
func (ep *Endpoint) Leave(sb *Sandbox, options ...EndpointOption) error {
if sb == nil || sb.ID() == "" || sb.Key() == "" { if sb == nil || sb.ID() == "" || sb.Key() == "" {
return types.BadRequestErrorf("invalid Sandbox passed to endpoint leave: %v", sb) return types.BadRequestErrorf("invalid Sandbox passed to endpoint leave: %v", sb)
} }
@ -687,7 +666,7 @@ func (ep *endpoint) Leave(sb *Sandbox, options ...EndpointOption) error {
return ep.sbLeave(sb, false, options...) return ep.sbLeave(sb, false, options...)
} }
func (ep *endpoint) sbLeave(sb *Sandbox, force bool, options ...EndpointOption) error { func (ep *Endpoint) sbLeave(sb *Sandbox, force bool, options ...EndpointOption) error {
n, err := ep.getNetworkFromStore() n, err := ep.getNetworkFromStore()
if err != nil { if err != nil {
return fmt.Errorf("failed to get network from store during leave: %v", err) return fmt.Errorf("failed to get network from store during leave: %v", err)
@ -795,7 +774,8 @@ func (ep *endpoint) sbLeave(sb *Sandbox, force bool, options ...EndpointOption)
return nil return nil
} }
func (ep *endpoint) Delete(force bool) error { // Delete deletes and detaches this endpoint from the network.
func (ep *Endpoint) Delete(force bool) error {
var err error var err error
n, err := ep.getNetworkFromStore() n, err := ep.getNetworkFromStore()
if err != nil { if err != nil {
@ -853,7 +833,7 @@ func (ep *endpoint) Delete(force bool) error {
return nil return nil
} }
func (ep *endpoint) deleteEndpoint(force bool) error { func (ep *Endpoint) deleteEndpoint(force bool) error {
ep.mu.Lock() ep.mu.Lock()
n := ep.network n := ep.network
name := ep.name name := ep.name
@ -882,7 +862,7 @@ func (ep *endpoint) deleteEndpoint(force bool) error {
return nil return nil
} }
func (ep *endpoint) getSandbox() (*Sandbox, bool) { func (ep *Endpoint) getSandbox() (*Sandbox, bool) {
c := ep.network.getController() c := ep.network.getController()
ep.mu.Lock() ep.mu.Lock()
sid := ep.sandboxID sid := ep.sandboxID
@ -895,7 +875,7 @@ func (ep *endpoint) getSandbox() (*Sandbox, bool) {
return ps, ok return ps, ok
} }
func (ep *endpoint) getFirstInterfaceIPv4Address() net.IP { func (ep *Endpoint) getFirstInterfaceIPv4Address() net.IP {
ep.mu.Lock() ep.mu.Lock()
defer ep.mu.Unlock() defer ep.mu.Unlock()
@ -906,7 +886,7 @@ func (ep *endpoint) getFirstInterfaceIPv4Address() net.IP {
return nil return nil
} }
func (ep *endpoint) getFirstInterfaceIPv6Address() net.IP { func (ep *Endpoint) getFirstInterfaceIPv6Address() net.IP {
ep.mu.Lock() ep.mu.Lock()
defer ep.mu.Unlock() defer ep.mu.Unlock()
@ -920,7 +900,7 @@ func (ep *endpoint) getFirstInterfaceIPv6Address() net.IP {
// EndpointOptionGeneric function returns an option setter for a Generic option defined // EndpointOptionGeneric function returns an option setter for a Generic option defined
// in a Dictionary of Key-Value pair // in a Dictionary of Key-Value pair
func EndpointOptionGeneric(generic map[string]interface{}) EndpointOption { func EndpointOptionGeneric(generic map[string]interface{}) EndpointOption {
return func(ep *endpoint) { return func(ep *Endpoint) {
for k, v := range generic { for k, v := range generic {
ep.generic[k] = v ep.generic[k] = v
} }
@ -934,7 +914,7 @@ var (
// CreateOptionIpam function returns an option setter for the ipam configuration for this endpoint // CreateOptionIpam function returns an option setter for the ipam configuration for this endpoint
func CreateOptionIpam(ipV4, ipV6 net.IP, llIPs []net.IP, ipamOptions map[string]string) EndpointOption { func CreateOptionIpam(ipV4, ipV6 net.IP, llIPs []net.IP, ipamOptions map[string]string) EndpointOption {
return func(ep *endpoint) { return func(ep *Endpoint) {
ep.prefAddress = ipV4 ep.prefAddress = ipV4
ep.prefAddressV6 = ipV6 ep.prefAddressV6 = ipV6
if len(llIPs) != 0 { if len(llIPs) != 0 {
@ -953,7 +933,7 @@ func CreateOptionIpam(ipV4, ipV6 net.IP, llIPs []net.IP, ipamOptions map[string]
// CreateOptionExposedPorts function returns an option setter for the container exposed // CreateOptionExposedPorts function returns an option setter for the container exposed
// ports option to be passed to network.CreateEndpoint() method. // ports option to be passed to network.CreateEndpoint() method.
func CreateOptionExposedPorts(exposedPorts []types.TransportPort) EndpointOption { func CreateOptionExposedPorts(exposedPorts []types.TransportPort) EndpointOption {
return func(ep *endpoint) { return func(ep *Endpoint) {
// Defensive copy // Defensive copy
eps := make([]types.TransportPort, len(exposedPorts)) eps := make([]types.TransportPort, len(exposedPorts))
copy(eps, exposedPorts) copy(eps, exposedPorts)
@ -966,7 +946,7 @@ func CreateOptionExposedPorts(exposedPorts []types.TransportPort) EndpointOption
// CreateOptionPortMapping function returns an option setter for the mapping // CreateOptionPortMapping function returns an option setter for the mapping
// ports option to be passed to network.CreateEndpoint() method. // ports option to be passed to network.CreateEndpoint() method.
func CreateOptionPortMapping(portBindings []types.PortBinding) EndpointOption { func CreateOptionPortMapping(portBindings []types.PortBinding) EndpointOption {
return func(ep *endpoint) { return func(ep *Endpoint) {
// Store a copy of the bindings as generic data to pass to the driver // Store a copy of the bindings as generic data to pass to the driver
pbs := make([]types.PortBinding, len(portBindings)) pbs := make([]types.PortBinding, len(portBindings))
copy(pbs, portBindings) copy(pbs, portBindings)
@ -977,7 +957,7 @@ func CreateOptionPortMapping(portBindings []types.PortBinding) EndpointOption {
// CreateOptionDNS function returns an option setter for dns entry option to // CreateOptionDNS function returns an option setter for dns entry option to
// be passed to container Create method. // be passed to container Create method.
func CreateOptionDNS(dns []string) EndpointOption { func CreateOptionDNS(dns []string) EndpointOption {
return func(ep *endpoint) { return func(ep *Endpoint) {
ep.generic[netlabel.DNSServers] = dns ep.generic[netlabel.DNSServers] = dns
} }
} }
@ -985,7 +965,7 @@ func CreateOptionDNS(dns []string) EndpointOption {
// CreateOptionAnonymous function returns an option setter for setting // CreateOptionAnonymous function returns an option setter for setting
// this endpoint as anonymous // this endpoint as anonymous
func CreateOptionAnonymous() EndpointOption { func CreateOptionAnonymous() EndpointOption {
return func(ep *endpoint) { return func(ep *Endpoint) {
ep.anonymous = true ep.anonymous = true
} }
} }
@ -993,14 +973,14 @@ func CreateOptionAnonymous() EndpointOption {
// CreateOptionDisableResolution function returns an option setter to indicate // CreateOptionDisableResolution function returns an option setter to indicate
// this endpoint doesn't want embedded DNS server functionality // this endpoint doesn't want embedded DNS server functionality
func CreateOptionDisableResolution() EndpointOption { func CreateOptionDisableResolution() EndpointOption {
return func(ep *endpoint) { return func(ep *Endpoint) {
ep.disableResolution = true ep.disableResolution = true
} }
} }
// CreateOptionAlias function returns an option setter for setting endpoint alias // CreateOptionAlias function returns an option setter for setting endpoint alias
func CreateOptionAlias(name string, alias string) EndpointOption { func CreateOptionAlias(name string, alias string) EndpointOption {
return func(ep *endpoint) { return func(ep *Endpoint) {
if ep.aliases == nil { if ep.aliases == nil {
ep.aliases = make(map[string]string) ep.aliases = make(map[string]string)
} }
@ -1010,7 +990,7 @@ func CreateOptionAlias(name string, alias string) EndpointOption {
// CreateOptionService function returns an option setter for setting service binding configuration // CreateOptionService function returns an option setter for setting service binding configuration
func CreateOptionService(name, id string, vip net.IP, ingressPorts []*PortConfig, aliases []string) EndpointOption { func CreateOptionService(name, id string, vip net.IP, ingressPorts []*PortConfig, aliases []string) EndpointOption {
return func(ep *endpoint) { return func(ep *Endpoint) {
ep.svcName = name ep.svcName = name
ep.svcID = id ep.svcID = id
ep.virtualIP = vip ep.virtualIP = vip
@ -1021,14 +1001,14 @@ func CreateOptionService(name, id string, vip net.IP, ingressPorts []*PortConfig
// CreateOptionMyAlias function returns an option setter for setting endpoint's self alias // CreateOptionMyAlias function returns an option setter for setting endpoint's self alias
func CreateOptionMyAlias(alias string) EndpointOption { func CreateOptionMyAlias(alias string) EndpointOption {
return func(ep *endpoint) { return func(ep *Endpoint) {
ep.myAliases = append(ep.myAliases, alias) ep.myAliases = append(ep.myAliases, alias)
} }
} }
// CreateOptionLoadBalancer function returns an option setter for denoting the endpoint is a load balancer for a network // CreateOptionLoadBalancer function returns an option setter for denoting the endpoint is a load balancer for a network
func CreateOptionLoadBalancer() EndpointOption { func CreateOptionLoadBalancer() EndpointOption {
return func(ep *endpoint) { return func(ep *Endpoint) {
ep.loadBalancer = true ep.loadBalancer = true
} }
} }
@ -1036,7 +1016,7 @@ func CreateOptionLoadBalancer() EndpointOption {
// JoinOptionPriority function returns an option setter for priority option to // JoinOptionPriority function returns an option setter for priority option to
// be passed to the endpoint.Join() method. // be passed to the endpoint.Join() method.
func JoinOptionPriority(prio int) EndpointOption { func JoinOptionPriority(prio int) EndpointOption {
return func(ep *endpoint) { return func(ep *Endpoint) {
// ep lock already acquired // ep lock already acquired
c := ep.network.getController() c := ep.network.getController()
c.mu.Lock() c.mu.Lock()
@ -1050,11 +1030,11 @@ func JoinOptionPriority(prio int) EndpointOption {
} }
} }
func (ep *endpoint) DataScope() string { func (ep *Endpoint) DataScope() string {
return ep.getNetwork().DataScope() return ep.getNetwork().DataScope()
} }
func (ep *endpoint) assignAddress(ipam ipamapi.Ipam, assignIPv4, assignIPv6 bool) error { func (ep *Endpoint) assignAddress(ipam ipamapi.Ipam, assignIPv4, assignIPv6 bool) error {
var err error var err error
n := ep.getNetwork() n := ep.getNetwork()
@ -1077,7 +1057,7 @@ func (ep *endpoint) assignAddress(ipam ipamapi.Ipam, assignIPv4, assignIPv6 bool
return err return err
} }
func (ep *endpoint) assignAddressVersion(ipVer int, ipam ipamapi.Ipam) error { func (ep *Endpoint) assignAddressVersion(ipVer int, ipam ipamapi.Ipam) error {
var ( var (
poolID *string poolID *string
address **net.IPNet address **net.IPNet
@ -1136,7 +1116,7 @@ func (ep *endpoint) assignAddressVersion(ipVer int, ipam ipamapi.Ipam) error {
return fmt.Errorf("no available IPv%d addresses on this network's address pools: %s (%s)", ipVer, n.Name(), n.ID()) return fmt.Errorf("no available IPv%d addresses on this network's address pools: %s (%s)", ipVer, n.Name(), n.ID())
} }
func (ep *endpoint) releaseAddress() { func (ep *Endpoint) releaseAddress() {
n := ep.getNetwork() n := ep.getNetwork()
if n.hasSpecialDriver() { if n.hasSpecialDriver() {
return return

View file

@ -187,7 +187,8 @@ type tableEntry struct {
value []byte value []byte
} }
func (ep *endpoint) Info() EndpointInfo { // Info returns certain operational data belonging to this endpoint.
func (ep *Endpoint) Info() EndpointInfo {
if ep.sandboxID != "" { if ep.sandboxID != "" {
return ep return ep
} }
@ -211,7 +212,7 @@ func (ep *endpoint) Info() EndpointInfo {
return sb.getEndpoint(ep.ID()) return sb.getEndpoint(ep.ID())
} }
func (ep *endpoint) Iface() InterfaceInfo { func (ep *Endpoint) Iface() InterfaceInfo {
ep.mu.Lock() ep.mu.Lock()
defer ep.mu.Unlock() defer ep.mu.Unlock()
@ -222,7 +223,7 @@ func (ep *endpoint) Iface() InterfaceInfo {
return nil return nil
} }
func (ep *endpoint) Interface() driverapi.InterfaceInfo { func (ep *Endpoint) Interface() driverapi.InterfaceInfo {
ep.mu.Lock() ep.mu.Lock()
defer ep.mu.Unlock() defer ep.mu.Unlock()
@ -288,7 +289,7 @@ func (epi *endpointInterface) SetNames(srcName string, dstPrefix string) error {
return nil return nil
} }
func (ep *endpoint) InterfaceName() driverapi.InterfaceNameInfo { func (ep *Endpoint) InterfaceName() driverapi.InterfaceNameInfo {
ep.mu.Lock() ep.mu.Lock()
defer ep.mu.Unlock() defer ep.mu.Unlock()
@ -299,7 +300,7 @@ func (ep *endpoint) InterfaceName() driverapi.InterfaceNameInfo {
return nil return nil
} }
func (ep *endpoint) AddStaticRoute(destination *net.IPNet, routeType int, nextHop net.IP) error { func (ep *Endpoint) AddStaticRoute(destination *net.IPNet, routeType int, nextHop net.IP) error {
ep.mu.Lock() ep.mu.Lock()
defer ep.mu.Unlock() defer ep.mu.Unlock()
@ -315,7 +316,7 @@ func (ep *endpoint) AddStaticRoute(destination *net.IPNet, routeType int, nextHo
return nil return nil
} }
func (ep *endpoint) AddTableEntry(tableName, key string, value []byte) error { func (ep *Endpoint) AddTableEntry(tableName, key string, value []byte) error {
ep.mu.Lock() ep.mu.Lock()
defer ep.mu.Unlock() defer ep.mu.Unlock()
@ -328,7 +329,7 @@ func (ep *endpoint) AddTableEntry(tableName, key string, value []byte) error {
return nil return nil
} }
func (ep *endpoint) Sandbox() *Sandbox { func (ep *Endpoint) Sandbox() *Sandbox {
cnt, ok := ep.getSandbox() cnt, ok := ep.getSandbox()
if !ok { if !ok {
return nil return nil
@ -336,13 +337,13 @@ func (ep *endpoint) Sandbox() *Sandbox {
return cnt return cnt
} }
func (ep *endpoint) LoadBalancer() bool { func (ep *Endpoint) LoadBalancer() bool {
ep.mu.Lock() ep.mu.Lock()
defer ep.mu.Unlock() defer ep.mu.Unlock()
return ep.loadBalancer return ep.loadBalancer
} }
func (ep *endpoint) StaticRoutes() []*types.StaticRoute { func (ep *Endpoint) StaticRoutes() []*types.StaticRoute {
ep.mu.Lock() ep.mu.Lock()
defer ep.mu.Unlock() defer ep.mu.Unlock()
@ -353,7 +354,7 @@ func (ep *endpoint) StaticRoutes() []*types.StaticRoute {
return ep.joinInfo.StaticRoutes return ep.joinInfo.StaticRoutes
} }
func (ep *endpoint) Gateway() net.IP { func (ep *Endpoint) Gateway() net.IP {
ep.mu.Lock() ep.mu.Lock()
defer ep.mu.Unlock() defer ep.mu.Unlock()
@ -364,7 +365,7 @@ func (ep *endpoint) Gateway() net.IP {
return types.GetIPCopy(ep.joinInfo.gw) return types.GetIPCopy(ep.joinInfo.gw)
} }
func (ep *endpoint) GatewayIPv6() net.IP { func (ep *Endpoint) GatewayIPv6() net.IP {
ep.mu.Lock() ep.mu.Lock()
defer ep.mu.Unlock() defer ep.mu.Unlock()
@ -375,7 +376,7 @@ func (ep *endpoint) GatewayIPv6() net.IP {
return types.GetIPCopy(ep.joinInfo.gw6) return types.GetIPCopy(ep.joinInfo.gw6)
} }
func (ep *endpoint) SetGateway(gw net.IP) error { func (ep *Endpoint) SetGateway(gw net.IP) error {
ep.mu.Lock() ep.mu.Lock()
defer ep.mu.Unlock() defer ep.mu.Unlock()
@ -383,7 +384,7 @@ func (ep *endpoint) SetGateway(gw net.IP) error {
return nil return nil
} }
func (ep *endpoint) SetGatewayIPv6(gw6 net.IP) error { func (ep *Endpoint) SetGatewayIPv6(gw6 net.IP) error {
ep.mu.Lock() ep.mu.Lock()
defer ep.mu.Unlock() defer ep.mu.Unlock()
@ -391,7 +392,7 @@ func (ep *endpoint) SetGatewayIPv6(gw6 net.IP) error {
return nil return nil
} }
func (ep *endpoint) retrieveFromStore() (*endpoint, error) { func (ep *Endpoint) retrieveFromStore() (*Endpoint, error) {
n, err := ep.getNetworkFromStore() n, err := ep.getNetworkFromStore()
if err != nil { if err != nil {
return nil, fmt.Errorf("could not find network in store to get latest endpoint %s: %v", ep.Name(), err) return nil, fmt.Errorf("could not find network in store to get latest endpoint %s: %v", ep.Name(), err)
@ -399,7 +400,7 @@ func (ep *endpoint) retrieveFromStore() (*endpoint, error) {
return n.getEndpointFromStore(ep.ID()) return n.getEndpointFromStore(ep.ID())
} }
func (ep *endpoint) DisableGatewayService() { func (ep *Endpoint) DisableGatewayService() {
ep.mu.Lock() ep.mu.Lock()
defer ep.mu.Unlock() defer ep.mu.Unlock()

View file

@ -5,7 +5,8 @@ package libnetwork
import "fmt" import "fmt"
func (ep *endpoint) DriverInfo() (map[string]interface{}, error) { // DriverInfo returns a collection of driver operational data related to this endpoint retrieved from the driver.
func (ep *Endpoint) DriverInfo() (map[string]interface{}, error) {
ep, err := ep.retrieveFromStore() ep, err := ep.retrieveFromStore()
if err != nil { if err != nil {
return nil, err return nil, err

View file

@ -5,7 +5,8 @@ package libnetwork
import "fmt" import "fmt"
func (ep *endpoint) DriverInfo() (map[string]interface{}, error) { // DriverInfo returns a collection of driver operational data related to this endpoint retrieved from the driver.
func (ep *Endpoint) DriverInfo() (map[string]interface{}, error) {
ep, err := ep.retrieveFromStore() ep, err := ep.retrieveFromStore()
if err != nil { if err != nil {
return nil, err return nil, err

View file

@ -188,7 +188,7 @@ func TestEndpointMarshalling(t *testing.T) {
lla = append(lla, ll) lla = append(lla, ll)
} }
e := &endpoint{ e := &Endpoint{
name: "Bau", name: "Bau",
id: "efghijklmno", id: "efghijklmno",
sandboxID: "ambarabaciccicocco", sandboxID: "ambarabaciccicocco",
@ -213,7 +213,7 @@ func TestEndpointMarshalling(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
ee := &endpoint{} ee := &Endpoint{}
err = json.Unmarshal(b, ee) err = json.Unmarshal(b, ee)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

View file

@ -852,7 +852,7 @@ type parallelTester struct {
func (pt parallelTester) Do(t *testing.T, thrNumber int) error { func (pt parallelTester) Do(t *testing.T, thrNumber int) error {
var ( var (
ep libnetwork.Endpoint ep *libnetwork.Endpoint
sb *libnetwork.Sandbox sb *libnetwork.Sandbox
err error err error
) )

View file

@ -520,8 +520,8 @@ func TestNetworkEndpointsWalkers(t *testing.T) {
// Test Endpoint Walk method // Test Endpoint Walk method
var epName string var epName string
var epWanted libnetwork.Endpoint var epWanted *libnetwork.Endpoint
wlk := func(ep libnetwork.Endpoint) bool { wlk := func(ep *libnetwork.Endpoint) bool {
if ep.Name() == epName { if ep.Name() == epName {
epWanted = ep epWanted = ep
return true return true

View file

@ -38,22 +38,22 @@ type Network interface {
// CreateEndpoint creates a new endpoint to this network symbolically identified by the // CreateEndpoint creates a new endpoint to this network symbolically identified by the
// specified unique name. The options parameter carries driver specific options. // specified unique name. The options parameter carries driver specific options.
CreateEndpoint(name string, options ...EndpointOption) (Endpoint, error) CreateEndpoint(name string, options ...EndpointOption) (*Endpoint, error)
// Delete the network. // Delete the network.
Delete(options ...NetworkDeleteOption) error Delete(options ...NetworkDeleteOption) error
// Endpoints returns the list of Endpoint(s) in this network. // Endpoints returns the list of Endpoint(s) in this network.
Endpoints() []Endpoint Endpoints() []*Endpoint
// WalkEndpoints uses the provided function to walk the Endpoints. // WalkEndpoints uses the provided function to walk the Endpoints.
WalkEndpoints(walker EndpointWalker) WalkEndpoints(walker EndpointWalker)
// EndpointByName returns the Endpoint which has the passed name. If not found, the error ErrNoSuchEndpoint is returned. // EndpointByName returns the Endpoint which has the passed name. If not found, the error ErrNoSuchEndpoint is returned.
EndpointByName(name string) (Endpoint, error) EndpointByName(name string) (*Endpoint, error)
// EndpointByID returns the Endpoint which has the passed id. If not found, the error ErrNoSuchEndpoint is returned. // EndpointByID returns the Endpoint which has the passed id. If not found, the error ErrNoSuchEndpoint is returned.
EndpointByID(id string) (Endpoint, error) EndpointByID(id string) (*Endpoint, error)
// Info returns certain operational data belonging to this network. // Info returns certain operational data belonging to this network.
Info() NetworkInfo Info() NetworkInfo
@ -86,7 +86,7 @@ type NetworkInfo interface {
// EndpointWalker is a client provided function which will be used to walk the Endpoints. // EndpointWalker is a client provided function which will be used to walk the Endpoints.
// When the function returns true, the walk will stop. // When the function returns true, the walk will stop.
type EndpointWalker func(ep Endpoint) bool type EndpointWalker func(ep *Endpoint) bool
// ipInfo is the reverse mapping from IP to service name to serve the PTR query. // ipInfo is the reverse mapping from IP to service name to serve the PTR query.
// extResolver is set if an external server resolves a service name to this IP. // extResolver is set if an external server resolves a service name to this IP.
@ -1135,7 +1135,7 @@ func (n *network) deleteNetwork() error {
return nil return nil
} }
func (n *network) addEndpoint(ep *endpoint) error { func (n *network) addEndpoint(ep *Endpoint) error {
d, err := n.driver(true) d, err := n.driver(true)
if err != nil { if err != nil {
return fmt.Errorf("failed to add endpoint: %v", err) return fmt.Errorf("failed to add endpoint: %v", err)
@ -1150,7 +1150,7 @@ func (n *network) addEndpoint(ep *endpoint) error {
return nil return nil
} }
func (n *network) CreateEndpoint(name string, options ...EndpointOption) (Endpoint, error) { func (n *network) CreateEndpoint(name string, options ...EndpointOption) (*Endpoint, error) {
var err error var err error
if !config.IsValidName(name) { if !config.IsValidName(name) {
return nil, ErrInvalidName(name) return nil, ErrInvalidName(name)
@ -1170,10 +1170,10 @@ func (n *network) CreateEndpoint(name string, options ...EndpointOption) (Endpoi
return n.createEndpoint(name, options...) return n.createEndpoint(name, options...)
} }
func (n *network) createEndpoint(name string, options ...EndpointOption) (Endpoint, error) { func (n *network) createEndpoint(name string, options ...EndpointOption) (*Endpoint, error) {
var err error var err error
ep := &endpoint{name: name, generic: make(map[string]interface{}), iface: &endpointInterface{}} ep := &Endpoint{name: name, generic: make(map[string]interface{}), iface: &endpointInterface{}}
ep.id = stringid.GenerateRandomID() ep.id = stringid.GenerateRandomID()
// Initialize ep.network with a possibly stale copy of n. We need this to get network from // Initialize ep.network with a possibly stale copy of n. We need this to get network from
@ -1268,19 +1268,12 @@ func (n *network) createEndpoint(name string, options ...EndpointOption) (Endpoi
return ep, nil return ep, nil
} }
func (n *network) Endpoints() []Endpoint { func (n *network) Endpoints() []*Endpoint {
var list []Endpoint
endpoints, err := n.getEndpointsFromStore() endpoints, err := n.getEndpointsFromStore()
if err != nil { if err != nil {
logrus.Error(err) logrus.Error(err)
} }
return endpoints
for _, ep := range endpoints {
list = append(list, ep)
}
return list
} }
func (n *network) WalkEndpoints(walker EndpointWalker) { func (n *network) WalkEndpoints(walker EndpointWalker) {
@ -1291,13 +1284,13 @@ func (n *network) WalkEndpoints(walker EndpointWalker) {
} }
} }
func (n *network) EndpointByName(name string) (Endpoint, error) { func (n *network) EndpointByName(name string) (*Endpoint, error) {
if name == "" { if name == "" {
return nil, ErrInvalidName(name) return nil, ErrInvalidName(name)
} }
var e Endpoint var e *Endpoint
s := func(current Endpoint) bool { s := func(current *Endpoint) bool {
if current.Name() == name { if current.Name() == name {
e = current e = current
return true return true
@ -1314,7 +1307,7 @@ func (n *network) EndpointByName(name string) (Endpoint, error) {
return e, nil return e, nil
} }
func (n *network) EndpointByID(id string) (Endpoint, error) { func (n *network) EndpointByID(id string) (*Endpoint, error) {
if id == "" { if id == "" {
return nil, ErrInvalidID(id) return nil, ErrInvalidID(id)
} }
@ -1327,7 +1320,7 @@ func (n *network) EndpointByID(id string) (Endpoint, error) {
return ep, nil return ep, nil
} }
func (n *network) updateSvcRecord(ep *endpoint, localEps []*endpoint, isAdd bool) { func (n *network) updateSvcRecord(ep *Endpoint, localEps []*Endpoint, isAdd bool) {
var ipv6 net.IP var ipv6 net.IP
epName := ep.Name() epName := ep.Name()
if iface := ep.Iface(); iface != nil && iface.Address() != nil { if iface := ep.Iface(); iface != nil && iface.Address() != nil {
@ -1472,7 +1465,7 @@ func (n *network) deleteSvcRecords(eID, name, serviceID string, epIP net.IP, epI
} }
} }
func (n *network) getSvcRecords(ep *endpoint) []etchosts.Record { func (n *network) getSvcRecords(ep *Endpoint) []etchosts.Record {
n.Lock() n.Lock()
defer n.Unlock() defer n.Unlock()

View file

@ -40,7 +40,7 @@ type Sandbox struct {
controller *Controller controller *Controller
resolver Resolver resolver Resolver
resolverOnce sync.Once resolverOnce sync.Once
endpoints []*endpoint endpoints []*Endpoint
epPriority map[string]int epPriority map[string]int
populatedEndpoints map[string]struct{} populatedEndpoints map[string]struct{}
joinLeaveDone chan struct{} joinLeaveDone chan struct{}
@ -178,7 +178,7 @@ func (sb *Sandbox) delete(force bool) error {
// Detach from all endpoints // Detach from all endpoints
retain := false retain := false
for _, ep := range sb.getConnectedEndpoints() { for _, ep := range sb.Endpoints() {
// gw network endpoint detach and removal are automatic // gw network endpoint detach and removal are automatic
if ep.endpointInGWNetwork() && !force { if ep.endpointInGWNetwork() && !force {
continue continue
@ -241,7 +241,7 @@ func (sb *Sandbox) delete(force bool) error {
func (sb *Sandbox) Rename(name string) error { func (sb *Sandbox) Rename(name string) error {
var err error var err error
for _, ep := range sb.getConnectedEndpoints() { for _, ep := range sb.Endpoints() {
if ep.endpointInGWNetwork() { if ep.endpointInGWNetwork() {
continue continue
} }
@ -268,7 +268,7 @@ func (sb *Sandbox) Rename(name string) error {
// re-joins all the endpoints without destroying the osl sandbox // re-joins all the endpoints without destroying the osl sandbox
func (sb *Sandbox) Refresh(options ...SandboxOption) error { func (sb *Sandbox) Refresh(options ...SandboxOption) error {
// Store connected endpoints // Store connected endpoints
epList := sb.getConnectedEndpoints() epList := sb.Endpoints()
// Detach from all endpoints // Detach from all endpoints
for _, ep := range epList { for _, ep := range epList {
@ -317,28 +317,17 @@ func (sb *Sandbox) UnmarshalJSON(b []byte) (err error) {
} }
// Endpoints returns all the endpoints connected to the sandbox. // Endpoints returns all the endpoints connected to the sandbox.
func (sb *Sandbox) Endpoints() []Endpoint { func (sb *Sandbox) Endpoints() []*Endpoint {
sb.mu.Lock() sb.mu.Lock()
defer sb.mu.Unlock() defer sb.mu.Unlock()
endpoints := make([]Endpoint, len(sb.endpoints)) eps := make([]*Endpoint, len(sb.endpoints))
for i, ep := range sb.endpoints {
endpoints[i] = ep
}
return endpoints
}
func (sb *Sandbox) getConnectedEndpoints() []*endpoint {
sb.mu.Lock()
defer sb.mu.Unlock()
eps := make([]*endpoint, len(sb.endpoints))
copy(eps, sb.endpoints) copy(eps, sb.endpoints)
return eps return eps
} }
func (sb *Sandbox) addEndpoint(ep *endpoint) { func (sb *Sandbox) addEndpoint(ep *Endpoint) {
sb.mu.Lock() sb.mu.Lock()
defer sb.mu.Unlock() defer sb.mu.Unlock()
@ -352,14 +341,14 @@ func (sb *Sandbox) addEndpoint(ep *endpoint) {
sb.endpoints[i] = ep sb.endpoints[i] = ep
} }
func (sb *Sandbox) removeEndpoint(ep *endpoint) { func (sb *Sandbox) removeEndpoint(ep *Endpoint) {
sb.mu.Lock() sb.mu.Lock()
defer sb.mu.Unlock() defer sb.mu.Unlock()
sb.removeEndpointRaw(ep) sb.removeEndpointRaw(ep)
} }
func (sb *Sandbox) removeEndpointRaw(ep *endpoint) { func (sb *Sandbox) removeEndpointRaw(ep *Endpoint) {
for i, e := range sb.endpoints { for i, e := range sb.endpoints {
if e == ep { if e == ep {
sb.endpoints = append(sb.endpoints[:i], sb.endpoints[i+1:]...) sb.endpoints = append(sb.endpoints[:i], sb.endpoints[i+1:]...)
@ -368,7 +357,7 @@ func (sb *Sandbox) removeEndpointRaw(ep *endpoint) {
} }
} }
func (sb *Sandbox) getEndpoint(id string) *endpoint { func (sb *Sandbox) getEndpoint(id string) *Endpoint {
sb.mu.Lock() sb.mu.Lock()
defer sb.mu.Unlock() defer sb.mu.Unlock()
@ -381,7 +370,7 @@ func (sb *Sandbox) getEndpoint(id string) *endpoint {
return nil return nil
} }
func (sb *Sandbox) updateGateway(ep *endpoint) error { func (sb *Sandbox) updateGateway(ep *Endpoint) error {
sb.mu.Lock() sb.mu.Lock()
osSbox := sb.osSbox osSbox := sb.osSbox
sb.mu.Unlock() sb.mu.Unlock()
@ -411,7 +400,7 @@ func (sb *Sandbox) updateGateway(ep *endpoint) error {
} }
func (sb *Sandbox) HandleQueryResp(name string, ip net.IP) { func (sb *Sandbox) HandleQueryResp(name string, ip net.IP) {
for _, ep := range sb.getConnectedEndpoints() { for _, ep := range sb.Endpoints() {
n := ep.getNetwork() n := ep.getNetwork()
n.HandleQueryResp(name, ip) n.HandleQueryResp(name, ip)
} }
@ -421,7 +410,7 @@ func (sb *Sandbox) ResolveIP(ip string) string {
var svc string var svc string
logrus.Debugf("IP To resolve %v", ip) logrus.Debugf("IP To resolve %v", ip)
for _, ep := range sb.getConnectedEndpoints() { for _, ep := range sb.Endpoints() {
n := ep.getNetwork() n := ep.getNetwork()
svc = n.ResolveIP(ip) svc = n.ResolveIP(ip)
if len(svc) != 0 { if len(svc) != 0 {
@ -458,7 +447,7 @@ func (sb *Sandbox) ResolveService(name string) ([]*net.SRV, []net.IP) {
return nil, nil return nil, nil
} }
for _, ep := range sb.getConnectedEndpoints() { for _, ep := range sb.Endpoints() {
n := ep.getNetwork() n := ep.getNetwork()
srv, ip = n.ResolveService(name) srv, ip = n.ResolveService(name)
@ -469,8 +458,8 @@ func (sb *Sandbox) ResolveService(name string) ([]*net.SRV, []net.IP) {
return srv, ip return srv, ip
} }
func getDynamicNwEndpoints(epList []*endpoint) []*endpoint { func getDynamicNwEndpoints(epList []*Endpoint) []*Endpoint {
eps := []*endpoint{} eps := []*Endpoint{}
for _, ep := range epList { for _, ep := range epList {
n := ep.getNetwork() n := ep.getNetwork()
if n.dynamic && !n.ingress { if n.dynamic && !n.ingress {
@ -480,7 +469,7 @@ func getDynamicNwEndpoints(epList []*endpoint) []*endpoint {
return eps return eps
} }
func getIngressNwEndpoint(epList []*endpoint) *endpoint { func getIngressNwEndpoint(epList []*Endpoint) *Endpoint {
for _, ep := range epList { for _, ep := range epList {
n := ep.getNetwork() n := ep.getNetwork()
if n.ingress { if n.ingress {
@ -490,8 +479,8 @@ func getIngressNwEndpoint(epList []*endpoint) *endpoint {
return nil return nil
} }
func getLocalNwEndpoints(epList []*endpoint) []*endpoint { func getLocalNwEndpoints(epList []*Endpoint) []*Endpoint {
eps := []*endpoint{} eps := []*Endpoint{}
for _, ep := range epList { for _, ep := range epList {
n := ep.getNetwork() n := ep.getNetwork()
if !n.dynamic && !n.ingress { if !n.dynamic && !n.ingress {
@ -530,12 +519,12 @@ func (sb *Sandbox) ResolveName(name string, ipType int) ([]net.IP, bool) {
} }
} }
epList := sb.getConnectedEndpoints() epList := sb.Endpoints()
// In swarm mode services with exposed ports are connected to user overlay // In swarm mode services with exposed ports are connected to user overlay
// network, ingress network and docker_gwbridge network. Name resolution // network, ingress network and docker_gwbridge network. Name resolution
// should prioritize returning the VIP/IPs on user overlay network. // should prioritize returning the VIP/IPs on user overlay network.
newList := []*endpoint{} newList := []*Endpoint{}
if !sb.controller.isDistributedControl() { if !sb.controller.isDistributedControl() {
newList = append(newList, getDynamicNwEndpoints(epList)...) newList = append(newList, getDynamicNwEndpoints(epList)...)
ingressEP := getIngressNwEndpoint(epList) ingressEP := getIngressNwEndpoint(epList)
@ -568,7 +557,7 @@ func (sb *Sandbox) ResolveName(name string, ipType int) ([]net.IP, bool) {
return nil, false return nil, false
} }
func (sb *Sandbox) resolveName(req string, networkName string, epList []*endpoint, alias bool, ipType int) ([]net.IP, bool) { func (sb *Sandbox) resolveName(req string, networkName string, epList []*Endpoint, alias bool, ipType int) ([]net.IP, bool) {
var ipv6Miss bool var ipv6Miss bool
for _, ep := range epList { for _, ep := range epList {
@ -664,7 +653,7 @@ func (sb *Sandbox) SetKey(basePath string) error {
} }
} }
for _, ep := range sb.getConnectedEndpoints() { for _, ep := range sb.Endpoints() {
if err = sb.populateNetworkResources(ep); err != nil { if err = sb.populateNetworkResources(ep); err != nil {
return err return err
} }
@ -683,7 +672,7 @@ func (sb *Sandbox) EnableService() (err error) {
} }
} }
}() }()
for _, ep := range sb.getConnectedEndpoints() { for _, ep := range sb.Endpoints() {
if !ep.isServiceEnabled() { if !ep.isServiceEnabled() {
if err := ep.addServiceInfoToCluster(sb); err != nil { if err := ep.addServiceInfoToCluster(sb); err != nil {
return fmt.Errorf("could not update state for endpoint %s into cluster: %v", ep.Name(), err) return fmt.Errorf("could not update state for endpoint %s into cluster: %v", ep.Name(), err)
@ -705,7 +694,7 @@ func (sb *Sandbox) DisableService() (err error) {
err = fmt.Errorf("failed to disable service on sandbox:%s, for endpoints %s", sb.ID(), strings.Join(failedEps, ",")) err = fmt.Errorf("failed to disable service on sandbox:%s, for endpoints %s", sb.ID(), strings.Join(failedEps, ","))
} }
}() }()
for _, ep := range sb.getConnectedEndpoints() { for _, ep := range sb.Endpoints() {
if ep.isServiceEnabled() { if ep.isServiceEnabled() {
if err := ep.deleteServiceInfoFromCluster(sb, false, "DisableService"); err != nil { if err := ep.deleteServiceInfoFromCluster(sb, false, "DisableService"); err != nil {
failedEps = append(failedEps, ep.Name()) failedEps = append(failedEps, ep.Name())
@ -718,7 +707,7 @@ func (sb *Sandbox) DisableService() (err error) {
return nil return nil
} }
func releaseOSSboxResources(osSbox osl.Sandbox, ep *endpoint) { func releaseOSSboxResources(osSbox osl.Sandbox, ep *Endpoint) {
for _, i := range osSbox.Info().Interfaces() { for _, i := range osSbox.Info().Interfaces() {
// Only remove the interfaces owned by this endpoint from the sandbox. // Only remove the interfaces owned by this endpoint from the sandbox.
if ep.hasInterface(i.SrcName()) { if ep.hasInterface(i.SrcName()) {
@ -763,7 +752,7 @@ func (sb *Sandbox) releaseOSSbox() {
return return
} }
for _, ep := range sb.getConnectedEndpoints() { for _, ep := range sb.Endpoints() {
releaseOSSboxResources(osSbox, ep) releaseOSSboxResources(osSbox, ep)
} }
@ -819,7 +808,7 @@ func (sb *Sandbox) restoreOslSandbox() error {
return sb.osSbox.Restore(Ifaces, routes, gwep.joinInfo.gw, gwep.joinInfo.gw6) return sb.osSbox.Restore(Ifaces, routes, gwep.joinInfo.gw, gwep.joinInfo.gw6)
} }
func (sb *Sandbox) populateNetworkResources(ep *endpoint) error { func (sb *Sandbox) populateNetworkResources(ep *Endpoint) error {
sb.mu.Lock() sb.mu.Lock()
if sb.osSbox == nil { if sb.osSbox == nil {
sb.mu.Unlock() sb.mu.Unlock()
@ -907,7 +896,7 @@ func (sb *Sandbox) populateNetworkResources(ep *endpoint) error {
return nil return nil
} }
func (sb *Sandbox) clearNetworkResources(origEp *endpoint) error { func (sb *Sandbox) clearNetworkResources(origEp *Endpoint) error {
ep := sb.getEndpoint(origEp.id) ep := sb.getEndpoint(origEp.id)
if ep == nil { if ep == nil {
return fmt.Errorf("could not find the sandbox endpoint data for endpoint %s", return fmt.Errorf("could not find the sandbox endpoint data for endpoint %s",
@ -934,7 +923,7 @@ func (sb *Sandbox) clearNetworkResources(origEp *endpoint) error {
} }
var ( var (
gwepBefore, gwepAfter *endpoint gwepBefore, gwepAfter *Endpoint
index = -1 index = -1
) )
for i, e := range sb.endpoints { for i, e := range sb.endpoints {
@ -1184,7 +1173,7 @@ func OptionLoadBalancer(nid string) SandboxOption {
// epi.internal <=> epj.internal # non-internal < internal // epi.internal <=> epj.internal # non-internal < internal
// epi.joininfo <=> epj.joininfo # ipv6 < ipv4 // epi.joininfo <=> epj.joininfo # ipv6 < ipv4
// epi.name <=> epj.name # bar < foo // epi.name <=> epj.name # bar < foo
func (epi *endpoint) Less(epj *endpoint) bool { func (epi *Endpoint) Less(epj *Endpoint) bool {
var ( var (
prioi, prioj int prioi, prioj int
) )

View file

@ -147,7 +147,7 @@ func (sb *Sandbox) storeUpdate() error {
retry: retry:
sbs.Eps = nil sbs.Eps = nil
for _, ep := range sb.getConnectedEndpoints() { for _, ep := range sb.Endpoints() {
// If the endpoint is not persisted then do not add it to // If the endpoint is not persisted then do not add it to
// the sandbox checkpoint // the sandbox checkpoint
if ep.Skip() { if ep.Skip() {
@ -211,7 +211,7 @@ func (c *Controller) sandboxCleanup(activeSandboxes map[string]interface{}) {
id: sbs.ID, id: sbs.ID,
controller: sbs.c, controller: sbs.c,
containerID: sbs.Cid, containerID: sbs.Cid,
endpoints: []*endpoint{}, endpoints: []*Endpoint{},
populatedEndpoints: map[string]struct{}{}, populatedEndpoints: map[string]struct{}{},
dbIndex: sbs.dbIndex, dbIndex: sbs.dbIndex,
isStub: true, isStub: true,
@ -251,16 +251,16 @@ func (c *Controller) sandboxCleanup(activeSandboxes map[string]interface{}) {
for _, eps := range sbs.Eps { for _, eps := range sbs.Eps {
n, err := c.getNetworkFromStore(eps.Nid) n, err := c.getNetworkFromStore(eps.Nid)
var ep *endpoint var ep *Endpoint
if err != nil { if err != nil {
logrus.Errorf("getNetworkFromStore for nid %s failed while trying to build sandbox for cleanup: %v", eps.Nid, err) logrus.Errorf("getNetworkFromStore for nid %s failed while trying to build sandbox for cleanup: %v", eps.Nid, err)
n = &network{id: eps.Nid, ctrlr: c, drvOnce: &sync.Once{}, persist: true} n = &network{id: eps.Nid, ctrlr: c, drvOnce: &sync.Once{}, persist: true}
ep = &endpoint{id: eps.Eid, network: n, sandboxID: sbs.ID} ep = &Endpoint{id: eps.Eid, network: n, sandboxID: sbs.ID}
} else { } else {
ep, err = n.getEndpointFromStore(eps.Eid) ep, err = n.getEndpointFromStore(eps.Eid)
if err != nil { if err != nil {
logrus.Errorf("getEndpointFromStore for eid %s failed while trying to build sandbox for cleanup: %v", eps.Eid, err) logrus.Errorf("getEndpointFromStore for eid %s failed while trying to build sandbox for cleanup: %v", eps.Eid, err)
ep = &endpoint{id: eps.Eid, network: n, sandboxID: sbs.ID} ep = &Endpoint{id: eps.Eid, network: n, sandboxID: sbs.ID}
} }
} }
if _, ok := activeSandboxes[sb.ID()]; ok && err != nil { if _, ok := activeSandboxes[sb.ID()]; ok && err != nil {

View file

@ -21,7 +21,7 @@ import (
// Populate all loadbalancers on the network that the passed endpoint // Populate all loadbalancers on the network that the passed endpoint
// belongs to, into this sandbox. // belongs to, into this sandbox.
func (sb *Sandbox) populateLoadBalancers(ep *endpoint) { func (sb *Sandbox) populateLoadBalancers(ep *Endpoint) {
// This is an interface less endpoint. Nothing to do. // This is an interface less endpoint. Nothing to do.
if ep.Iface() == nil { if ep.Iface() == nil {
return return
@ -37,14 +37,14 @@ func (sb *Sandbox) populateLoadBalancers(ep *endpoint) {
} }
} }
func (n *network) findLBEndpointSandbox() (*endpoint, *Sandbox, error) { func (n *network) findLBEndpointSandbox() (*Endpoint, *Sandbox, error) {
// TODO: get endpoint from store? See EndpointInfo() // TODO: get endpoint from store? See EndpointInfo()
var ep *endpoint var ep *Endpoint
// Find this node's LB sandbox endpoint: there should be exactly one // Find this node's LB sandbox endpoint: there should be exactly one
for _, e := range n.Endpoints() { for _, e := range n.Endpoints() {
epi := e.Info() epi := e.Info()
if epi != nil && epi.LoadBalancer() { if epi != nil && epi.LoadBalancer() {
ep = e.(*endpoint) ep = e
break break
} }
} }
@ -66,7 +66,7 @@ func (n *network) findLBEndpointSandbox() (*endpoint, *Sandbox, error) {
// Searches the OS sandbox for the name of the endpoint interface // Searches the OS sandbox for the name of the endpoint interface
// within the sandbox. This is required for adding/removing IP // within the sandbox. This is required for adding/removing IP
// aliases to the interface. // aliases to the interface.
func findIfaceDstName(sb *Sandbox, ep *endpoint) string { func findIfaceDstName(sb *Sandbox, ep *Endpoint) string {
srcName := ep.Iface().SrcName() srcName := ep.Iface().SrcName()
for _, i := range sb.osSbox.Info().Interfaces() { for _, i := range sb.osSbox.Info().Interfaces() {
if i.SrcName() == srcName { if i.SrcName() == srcName {

View file

@ -161,7 +161,7 @@ func numEnabledBackends(lb *loadBalancer) int {
return nEnabled return nEnabled
} }
func (sb *Sandbox) populateLoadBalancers(ep *endpoint) { func (sb *Sandbox) populateLoadBalancers(ep *Endpoint) {
} }
func arrangeIngressFilterRule() { func arrangeIngressFilterRule() {

View file

@ -158,10 +158,10 @@ func (c *Controller) getNetworksFromStore() []*network {
return nl return nl
} }
func (n *network) getEndpointFromStore(eid string) (*endpoint, error) { func (n *network) getEndpointFromStore(eid string) (*Endpoint, error) {
var errors []string var errors []string
for _, store := range n.ctrlr.getStores() { for _, store := range n.ctrlr.getStores() {
ep := &endpoint{id: eid, network: n} ep := &Endpoint{id: eid, network: n}
err := store.GetObject(datastore.Key(ep.Key()...), ep) err := store.GetObject(datastore.Key(ep.Key()...), ep)
// Continue searching in the next store if the key is not found in this store // Continue searching in the next store if the key is not found in this store
if err != nil { if err != nil {
@ -176,12 +176,12 @@ func (n *network) getEndpointFromStore(eid string) (*endpoint, error) {
return nil, fmt.Errorf("could not find endpoint %s: %v", eid, errors) return nil, fmt.Errorf("could not find endpoint %s: %v", eid, errors)
} }
func (n *network) getEndpointsFromStore() ([]*endpoint, error) { func (n *network) getEndpointsFromStore() ([]*Endpoint, error) {
var epl []*endpoint var epl []*Endpoint
tmp := endpoint{network: n} tmp := Endpoint{network: n}
for _, store := range n.getController().getStores() { for _, store := range n.getController().getStores() {
kvol, err := store.List(datastore.Key(tmp.KeyPrefix()...), &endpoint{network: n}) kvol, err := store.List(datastore.Key(tmp.KeyPrefix()...), &Endpoint{network: n})
// Continue searching in the next store if no keys found in this store // Continue searching in the next store if no keys found in this store
if err != nil { if err != nil {
if err != datastore.ErrKeyNotFound { if err != datastore.ErrKeyNotFound {
@ -192,7 +192,7 @@ func (n *network) getEndpointsFromStore() ([]*endpoint, error) {
} }
for _, kvo := range kvol { for _, kvo := range kvol {
ep := kvo.(*endpoint) ep := kvo.(*Endpoint)
epl = append(epl, ep) epl = append(epl, ep)
} }
} }
@ -238,16 +238,16 @@ retry:
} }
type netWatch struct { type netWatch struct {
localEps map[string]*endpoint localEps map[string]*Endpoint
remoteEps map[string]*endpoint remoteEps map[string]*Endpoint
stopCh chan struct{} stopCh chan struct{}
} }
func (c *Controller) getLocalEps(nw *netWatch) []*endpoint { func (c *Controller) getLocalEps(nw *netWatch) []*Endpoint {
c.mu.Lock() c.mu.Lock()
defer c.mu.Unlock() defer c.mu.Unlock()
var epl []*endpoint var epl []*Endpoint
for _, ep := range nw.localEps { for _, ep := range nw.localEps {
epl = append(epl, ep) epl = append(epl, ep)
} }
@ -255,15 +255,15 @@ func (c *Controller) getLocalEps(nw *netWatch) []*endpoint {
return epl return epl
} }
func (c *Controller) watchSvcRecord(ep *endpoint) { func (c *Controller) watchSvcRecord(ep *Endpoint) {
c.watchCh <- ep c.watchCh <- ep
} }
func (c *Controller) unWatchSvcRecord(ep *endpoint) { func (c *Controller) unWatchSvcRecord(ep *Endpoint) {
c.unWatchCh <- ep c.unWatchCh <- ep
} }
func (c *Controller) networkWatchLoop(nw *netWatch, ep *endpoint, ecCh <-chan datastore.KVObject) { func (c *Controller) networkWatchLoop(nw *netWatch, ep *Endpoint, ecCh <-chan datastore.KVObject) {
for { for {
select { select {
case <-nw.stopCh: case <-nw.stopCh:
@ -277,9 +277,9 @@ func (c *Controller) networkWatchLoop(nw *netWatch, ep *endpoint, ecCh <-chan da
} }
c.mu.Lock() c.mu.Lock()
var addEp []*endpoint var addEp []*Endpoint
delEpMap := make(map[string]*endpoint) delEpMap := make(map[string]*Endpoint)
renameEpMap := make(map[string]bool) renameEpMap := make(map[string]bool)
for k, v := range nw.remoteEps { for k, v := range nw.remoteEps {
delEpMap[k] = v delEpMap[k] = v
@ -327,7 +327,7 @@ func (c *Controller) networkWatchLoop(nw *netWatch, ep *endpoint, ecCh <-chan da
} }
} }
func (c *Controller) processEndpointCreate(nmap map[string]*netWatch, ep *endpoint) { func (c *Controller) processEndpointCreate(nmap map[string]*netWatch, ep *Endpoint) {
n := ep.getNetwork() n := ep.getNetwork()
if !c.isDistributedControl() && n.Scope() == datastore.SwarmScope && n.driverIsMultihost() { if !c.isDistributedControl() && n.Scope() == datastore.SwarmScope && n.driverIsMultihost() {
return return
@ -356,8 +356,8 @@ func (c *Controller) processEndpointCreate(nmap map[string]*netWatch, ep *endpoi
} }
nw = &netWatch{ nw = &netWatch{
localEps: make(map[string]*endpoint), localEps: make(map[string]*Endpoint),
remoteEps: make(map[string]*endpoint), remoteEps: make(map[string]*Endpoint),
} }
// Update the svc db for the local endpoint join right away // Update the svc db for the local endpoint join right away
@ -389,7 +389,7 @@ func (c *Controller) processEndpointCreate(nmap map[string]*netWatch, ep *endpoi
go c.networkWatchLoop(nw, ep, ch) go c.networkWatchLoop(nw, ep, ch)
} }
func (c *Controller) processEndpointDelete(nmap map[string]*netWatch, ep *endpoint) { func (c *Controller) processEndpointDelete(nmap map[string]*netWatch, ep *Endpoint) {
n := ep.getNetwork() n := ep.getNetwork()
if !c.isDistributedControl() && n.Scope() == datastore.SwarmScope && n.driverIsMultihost() { if !c.isDistributedControl() && n.Scope() == datastore.SwarmScope && n.driverIsMultihost() {
return return
@ -439,8 +439,8 @@ func (c *Controller) startWatch() {
if c.watchCh != nil { if c.watchCh != nil {
return return
} }
c.watchCh = make(chan *endpoint) c.watchCh = make(chan *Endpoint)
c.unWatchCh = make(chan *endpoint) c.unWatchCh = make(chan *Endpoint)
c.nmap = make(map[string]*netWatch) c.nmap = make(map[string]*netWatch)
go c.watchLoop() go c.watchLoop()