summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorPaul Holzinger <pholzing@redhat.com>2022-05-06 13:49:07 +0200
committerPaul Holzinger <pholzing@redhat.com>2022-05-06 14:05:45 +0200
commited8c1dfb4c62b05a944c811d49cd56d21c1c1ede (patch)
treeeb0a93700366ae66d7b6443eaf7e40be5c159563 /libpod
parent5d5cb402cb6be818d6efd52d2198b00a55df0f1b (diff)
downloadpodman-ed8c1dfb4c62b05a944c811d49cd56d21c1c1ede.tar.gz
podman-ed8c1dfb4c62b05a944c811d49cd56d21c1c1ede.tar.bz2
podman-ed8c1dfb4c62b05a944c811d49cd56d21c1c1ede.zip
libpod: add c.ConfigWithNetworks()
Reading the networks requires an extra db operation. Most c.Config() callers do not need them so create a new function which returns the config with networks. [NO NEW TESTS NEEDED] Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container.go27
1 files changed, 16 insertions, 11 deletions
diff --git a/libpod/container.go b/libpod/container.go
index 457b290b7..4b2af02ab 100644
--- a/libpod/container.go
+++ b/libpod/container.go
@@ -281,21 +281,29 @@ type ContainerNetworkDescriptions map[string]int
// Config accessors
// Unlocked
-// Config returns the configuration used to create the container
+// Config returns the configuration used to create the container.
+// Note that the returned config does not include the actual networks.
+// Use ConfigWithNetworks() if you need them.
func (c *Container) Config() *ContainerConfig {
returnConfig := new(ContainerConfig)
if err := JSONDeepCopy(c.config, returnConfig); err != nil {
return nil
}
+ return returnConfig
+}
- if c != nil {
- networks, err := c.networks()
- if err != nil {
- return nil
- }
+// Config returns the configuration used to create the container.
+func (c *Container) ConfigWithNetworks() *ContainerConfig {
+ returnConfig := c.Config()
+ if returnConfig == nil {
+ return nil
+ }
- returnConfig.Networks = networks
+ networks, err := c.networks()
+ if err != nil {
+ return nil
}
+ returnConfig.Networks = networks
return returnConfig
}
@@ -1269,10 +1277,7 @@ func (c *Container) NetworkMode() string {
// Unlocked accessor for networks
func (c *Container) networks() (map[string]types.PerNetworkOptions, error) {
- if c != nil && c.runtime != nil && c.runtime.state != nil { // can fail if c.networks is called from the tests
- return c.runtime.state.GetNetworks(c)
- }
- return nil, nil
+ return c.runtime.state.GetNetworks(c)
}
// getInterfaceByName returns a formatted interface name for a given