aboutsummaryrefslogtreecommitdiff
path: root/libpod/boltdb_state_internal.go
diff options
context:
space:
mode:
Diffstat (limited to 'libpod/boltdb_state_internal.go')
-rw-r--r--libpod/boltdb_state_internal.go62
1 files changed, 25 insertions, 37 deletions
diff --git a/libpod/boltdb_state_internal.go b/libpod/boltdb_state_internal.go
index e71d82736..5f0f6ba7d 100644
--- a/libpod/boltdb_state_internal.go
+++ b/libpod/boltdb_state_internal.go
@@ -563,6 +563,28 @@ func (s *BoltState) addContainer(ctr *Container, pod *Pod) error {
ctrNamespace = []byte(ctr.config.Namespace)
}
+ // make sure to marshal the network options before we get the db lock
+ networks := make(map[string][]byte, len(ctr.config.Networks))
+ for net, opts := range ctr.config.Networks {
+ // Check that we don't have any empty network names
+ if net == "" {
+ return errors.Wrapf(define.ErrInvalidArg, "network names cannot be an empty string")
+ }
+ if opts.InterfaceName == "" {
+ return errors.Wrapf(define.ErrInvalidArg, "network interface name cannot be an empty string")
+ }
+ // always add the short id as alias for docker compat
+ opts.Aliases = append(opts.Aliases, ctr.config.ID[:12])
+ optBytes, err := json.Marshal(opts)
+ if err != nil {
+ return errors.Wrapf(err, "error marshalling network options JSON for container %s", ctr.ID())
+ }
+ networks[net] = optBytes
+ }
+ // Set the original value to nil. We can safe some space by not storing it in the config
+ // since we store it in a different mutable bucket anyway.
+ ctr.config.Networks = nil
+
db, err := s.getDBCon()
if err != nil {
return err
@@ -646,23 +668,6 @@ func (s *BoltState) addContainer(ctr *Container, pod *Pod) error {
return errors.Wrapf(err, "name \"%s\" is in use", ctr.Name())
}
- allNets := make(map[string]bool)
-
- // Check that we don't have any empty network names
- for _, net := range ctr.config.Networks {
- if net == "" {
- return errors.Wrapf(define.ErrInvalidArg, "network names cannot be an empty string")
- }
- allNets[net] = true
- }
-
- // Each network we have aliases for, must exist in networks
- for net := range ctr.config.NetworkAliases {
- if !allNets[net] {
- return errors.Wrapf(define.ErrNoSuchNetwork, "container %s has network aliases for network %q but is not part of that network", ctr.ID(), net)
- }
- }
-
// No overlapping containers
// Add the new container to the DB
if err := idsBucket.Put(ctrID, ctrName); err != nil {
@@ -706,34 +711,17 @@ func (s *BoltState) addContainer(ctr *Container, pod *Pod) error {
return errors.Wrapf(err, "error adding container %s netns path to DB", ctr.ID())
}
}
- if ctr.config.Networks != nil {
+ if len(networks) > 0 {
ctrNetworksBkt, err := newCtrBkt.CreateBucket(networksBkt)
if err != nil {
return errors.Wrapf(err, "error creating networks bucket for container %s", ctr.ID())
}
- for _, network := range ctr.config.Networks {
- if err := ctrNetworksBkt.Put([]byte(network), ctrID); err != nil {
+ for network, opts := range networks {
+ if err := ctrNetworksBkt.Put([]byte(network), opts); err != nil {
return errors.Wrapf(err, "error adding network %q to networks bucket for container %s", network, ctr.ID())
}
}
}
- if ctr.config.NetworkAliases != nil {
- ctrAliasesBkt, err := newCtrBkt.CreateBucket(aliasesBkt)
- if err != nil {
- return errors.Wrapf(err, "error creating network aliases bucket for container %s", ctr.ID())
- }
- for net, aliases := range ctr.config.NetworkAliases {
- netAliasesBkt, err := ctrAliasesBkt.CreateBucket([]byte(net))
- if err != nil {
- return errors.Wrapf(err, "error creating network aliases bucket for network %q in container %s", net, ctr.ID())
- }
- for _, alias := range aliases {
- if err := netAliasesBkt.Put([]byte(alias), ctrID); err != nil {
- return errors.Wrapf(err, "error creating network alias %q in network %q for container %s", alias, net, ctr.ID())
- }
- }
- }
- }
if _, err := newCtrBkt.CreateBucket(dependenciesBkt); err != nil {
return errors.Wrapf(err, "error creating dependencies bucket for container %s", ctr.ID())