Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to attach swarm overlay networks by prefix id #38699

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 16 additions & 3 deletions daemon/container_operations.go
Expand Up @@ -10,6 +10,8 @@ import (
"strings"
"time"

apitypes "github.com/docker/docker/api/types"

containertypes "github.com/docker/docker/api/types/container"
networktypes "github.com/docker/docker/api/types/network"
"github.com/docker/docker/container"
Expand Down Expand Up @@ -379,20 +381,31 @@ func (daemon *Daemon) findAndAttachNetwork(container *container.Container, idOrN
}

for {
var nr apitypes.NetworkResource

// In all other cases, attempt to attach to the network to
// trigger attachment in the swarm cluster manager.
if daemon.clusterProvider != nil {
var err error
config, err = daemon.clusterProvider.AttachNetwork(id, container.ID, addresses)
nr, err = daemon.cluster.GetNetwork(id)
if err != nil {
return nil, nil, err
}
config, err = daemon.clusterProvider.AttachNetwork(nr.ID, container.ID, addresses)
if err != nil {
return nil, nil, err
}
}

n, err = daemon.FindNetwork(id)
if daemon.clusterProvider != nil {
n, err = daemon.GetNetworkByID(nr.ID)
} else {
n, err = daemon.FindNetwork(id)
}

if err != nil {
if daemon.clusterProvider != nil {
if err := daemon.clusterProvider.DetachNetwork(id, container.ID); err != nil {
if err := daemon.clusterProvider.DetachNetwork(nr.ID, container.ID); err != nil {
logrus.Warnf("Could not rollback attachment for container %s to network %s: %v", container.ID, idOrName, err)
}
}
Expand Down