diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2022-08-31 08:54:38 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-31 08:54:38 -0400 |
commit | badbe62081b48d065245f92d5360164ecddf0aa9 (patch) | |
tree | 163f7d4875a6b769d8421f43c7d1f7c2f647111d /libpod | |
parent | 42f6094d6ec0f10eb758eaf4864a5d52f55e1c9d (diff) | |
parent | 3439657f91eccae1e4cec2c3fb291d2c55bbe871 (diff) | |
download | podman-badbe62081b48d065245f92d5360164ecddf0aa9.tar.gz podman-badbe62081b48d065245f92d5360164ecddf0aa9.tar.bz2 podman-badbe62081b48d065245f92d5360164ecddf0aa9.zip |
Merge pull request #15554 from openshift-cherrypick-robot/cherry-pick-15516-to-v4.2
[v4.2] Handle an already connected network in libpod API
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/boltdb_state.go | 2 | ||||
-rw-r--r-- | libpod/define/errors.go | 3 | ||||
-rw-r--r-- | libpod/networking_linux.go | 5 |
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) |