aboutsummaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2022-08-29 06:56:15 -0400
committerGitHub <noreply@github.com>2022-08-29 06:56:15 -0400
commite78363d24ce631c36579a294864af159f180a535 (patch)
treed1a6fa18e113447c71f22f785b1bddc2ea133da6 /libpod
parent3a6342062821cec7670bd9b4a5f3234866a8ed8e (diff)
parent78aec2130242b81659bd199c6c8605c76e681ff6 (diff)
downloadpodman-e78363d24ce631c36579a294864af159f180a535.tar.gz
podman-e78363d24ce631c36579a294864af159f180a535.tar.bz2
podman-e78363d24ce631c36579a294864af159f180a535.zip
Merge pull request #15516 from kubealex/handle-connected-network
Handle an already connected network in libpod API
Diffstat (limited to 'libpod')
-rw-r--r--libpod/boltdb_state.go2
-rw-r--r--libpod/define/errors.go3
-rw-r--r--libpod/networking_linux.go5
3 files changed, 9 insertions, 1 deletions
diff --git a/libpod/boltdb_state.go b/libpod/boltdb_state.go
index 81f11410b..e5a7e20fc 100644
--- a/libpod/boltdb_state.go
+++ b/libpod/boltdb_state.go
@@ -1278,7 +1278,7 @@ func (s *BoltState) NetworkConnect(ctr *Container, network string, opts types.Pe
}
netConnected := ctrNetworksBkt.Get([]byte(network))
if netConnected != nil {
- return fmt.Errorf("container %s is already connected to network %q: %w", ctr.ID(), network, define.ErrNetworkExists)
+ return fmt.Errorf("container %s is already connected to network %q: %w", ctr.ID(), network, define.ErrNetworkConnected)
}
// Add the network
diff --git a/libpod/define/errors.go b/libpod/define/errors.go
index fd27e89de..be471c27e 100644
--- a/libpod/define/errors.go
+++ b/libpod/define/errors.go
@@ -179,6 +179,9 @@ var (
// ErrNetworkInUse indicates the requested operation failed because the network was in use
ErrNetworkInUse = errors.New("network is being used")
+ // ErrNetworkConnected indicates that the required operation failed because the container is already a network endpoint
+ ErrNetworkConnected = errors.New("network is already connected")
+
// ErrStoreNotInitialized indicates that the container storage was never
// initialized.
ErrStoreNotInitialized = errors.New("the container storage was never initialized")
diff --git a/libpod/networking_linux.go b/libpod/networking_linux.go
index c05796768..c10c3c0b2 100644
--- a/libpod/networking_linux.go
+++ b/libpod/networking_linux.go
@@ -1357,6 +1357,11 @@ func (c *Container) NetworkConnect(nameOrID, netName string, netOpts types.PerNe
}
if err := c.runtime.state.NetworkConnect(c, netName, netOpts); err != nil {
+ // Docker compat: treat requests to attach already attached networks as a no-op, ignoring opts
+ if errors.Is(err, define.ErrNetworkConnected) && c.ensureState(define.ContainerStateConfigured) {
+ return nil
+ }
+
return err
}
c.newNetworkEvent(events.NetworkConnect, netName)