Update containers common package

The new version adds NetworkCreateOptions. For now pass nil

[NO NEW TESTS NEEDED]

Signed-off-by: Ygal Blum <ygal.blum@gmail.com>
This commit is contained in:
Ygal Blum
2022-12-05 15:39:18 +02:00
parent 68e51834a9
commit 7d16c2b69e
18 changed files with 54 additions and 22 deletions

View File

@@ -21,7 +21,7 @@ import (
// NetworkCreate will take a partial filled Network and fill the
// missing fields. It creates the Network and returns the full Network.
func (n *netavarkNetwork) NetworkCreate(net types.Network) (types.Network, error) {
func (n *netavarkNetwork) NetworkCreate(net types.Network, options *types.NetworkCreateOptions) (types.Network, error) {
n.lock.Lock()
defer n.lock.Unlock()
err := n.loadNetworks()
@@ -30,6 +30,11 @@ func (n *netavarkNetwork) NetworkCreate(net types.Network) (types.Network, error
}
network, err := n.networkCreate(&net, false)
if err != nil {
if options != nil && options.IgnoreIfExists && errors.Is(err, types.ErrNetworkExists) {
if network, ok := n.networks[net.Name]; ok {
return *network, nil
}
}
return types.Network{}, err
}
// add the new network to the map

View File

@@ -95,7 +95,7 @@ type InitConfig struct {
// Note: The networks are not loaded from disk until a method is called.
func NewNetworkInterface(conf *InitConfig) (types.ContainerNetwork, error) {
// TODO: consider using a shared memory lock
lock, err := lockfile.GetLockfile(filepath.Join(conf.NetworkConfigDir, "netavark.lock"))
lock, err := lockfile.GetLockFile(filepath.Join(conf.NetworkConfigDir, "netavark.lock"))
if err != nil {
return nil, err
}