Skip to content

Commit

Permalink
Merge pull request #14136 from Luap99/config-networks
Browse files Browse the repository at this point in the history
libpod: add c.ConfigWithNetworks()
  • Loading branch information
openshift-merge-robot authored May 6, 2022
2 parents a64dd31 + ed8c1df commit a0ecb86
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
27 changes: 16 additions & 11 deletions libpod/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion pkg/specgen/generate/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package generate
import (
"context"
"encoding/json"
"fmt"
"os"
"strings"
"time"
Expand Down Expand Up @@ -352,7 +353,10 @@ func ConfigToSpec(rt *libpod.Runtime, specg *specgen.SpecGenerator, contaierID s
if err != nil {
return nil, nil, err
}
conf := c.Config()
conf := c.ConfigWithNetworks()
if conf == nil {
return nil, nil, fmt.Errorf("failed to get config for container %s", c.ID())
}

tmpSystemd := conf.Systemd
tmpMounts := conf.Mounts
Expand Down

0 comments on commit a0ecb86

Please sign in to comment.