Skip to content

Commit

Permalink
container restore/import: store networks from db
Browse files Browse the repository at this point in the history
It is important that we store the current networks from the db in the
config. Also make sure to properly handle aliases and ignore static ip/mac
addresses.

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 committed Dec 14, 2021
1 parent 3e9af20 commit 094e1d7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
18 changes: 18 additions & 0 deletions libpod/container_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2206,6 +2206,24 @@ func (c *Container) canWithPrevious() error {
// prepareCheckpointExport writes the config and spec to
// JSON files for later export
func (c *Container) prepareCheckpointExport() error {
networks, err := c.networks()
if err != nil {
return err
}
// make sure to exclude the short ID alias since the container gets a new ID on restore
for net, opts := range networks {
newAliases := make([]string, 0, len(opts.Aliases))
for _, alias := range opts.Aliases {
if alias != c.config.ID[:12] {
newAliases = append(newAliases, alias)
}
}
opts.Aliases = newAliases
networks[net] = opts
}

// add the networks from the db to the config so that the exported checkpoint still stores all current networks
c.config.Networks = networks
// save live config
if _, err := metadata.WriteJSONFile(c.config, c.bundlePath(), metadata.ConfigDumpFile); err != nil {
return err
Expand Down
12 changes: 12 additions & 0 deletions pkg/checkpoint/checkpoint_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ func CRImportCheckpoint(ctx context.Context, runtime *libpod.Runtime, restoreOpt
}
}

if restoreOptions.IgnoreStaticIP || restoreOptions.IgnoreStaticMAC {
for net, opts := range ctrConfig.Networks {
if restoreOptions.IgnoreStaticIP {
opts.StaticIPs = nil
}
if restoreOptions.IgnoreStaticMAC {
opts.StaticMAC = nil
}
ctrConfig.Networks[net] = opts
}
}

ctrID := ctrConfig.ID
newName := false

Expand Down

0 comments on commit 094e1d7

Please sign in to comment.