Skip to content

Commit

Permalink
Use existing interface to request IP address during restore
Browse files Browse the repository at this point in the history
The initial implementation to request the same IP address for a
container during a restore was based on environment variables
influencing CNI.

With this commit the IP address selection switches to Podman's internal
static IP API.

This commit does a comment change in libpod/container_easyjson.go to
avoid unnecessary re-generation of libpod/container_easyjson.go during
build as this fails in CI. The reason for this is that make sees that
libpod/container_easyjson.go needs to be re-created. The commit,
however, only changes a part of libpod/container.go which is marked as
'ffjson: skip'.

Signed-off-by: Adrian Reber <[email protected]>
  • Loading branch information
adrianreber committed Jan 9, 2019
1 parent ab8e03b commit 2553dad
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
5 changes: 5 additions & 0 deletions libpod/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ type Container struct {

rootlessSlirpSyncR *os.File
rootlessSlirpSyncW *os.File

// A restored container should have the same IP address as before
// being checkpointed. If requestedIP is set it will be used instead
// of config.StaticIP.
requestedIP net.IP
}

// containerState contains the current state of the container
Expand Down
2 changes: 1 addition & 1 deletion libpod/container_easyjson.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 1 addition & 9 deletions libpod/container_internal_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,10 +547,8 @@ func (c *Container) restore(ctx context.Context, options ContainerCheckpointOpti
}
}
if IP != nil {
env := fmt.Sprintf("IP=%s", IP)
// Tell CNI which IP address we want.
os.Setenv("CNI_ARGS", env)
logrus.Debugf("Restoring container with %s", env)
c.requestedIP = IP
}
}

Expand All @@ -566,12 +564,6 @@ func (c *Container) restore(ctx context.Context, options ContainerCheckpointOpti
return err
}

// TODO: use existing way to request static IPs, once it is merged in ocicni
// https://github.com/cri-o/ocicni/pull/23/

// CNI_ARGS was used to request a certain IP address. Unconditionally remove it.
os.Unsetenv("CNI_ARGS")

// Read config
jsonPath := filepath.Join(c.bundlePath(), "config.json")
logrus.Debugf("generate.NewFromFile at %v", jsonPath)
Expand Down
22 changes: 20 additions & 2 deletions libpod/networking_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,16 @@ func (r *Runtime) getPodNetwork(id, name, nsPath string, networks []string, port

// Create and configure a new network namespace for a container
func (r *Runtime) configureNetNS(ctr *Container, ctrNS ns.NetNS) ([]*cnitypes.Result, error) {
podNetwork := r.getPodNetwork(ctr.ID(), ctr.Name(), ctrNS.Path(), ctr.config.Networks, ctr.config.PortMappings, ctr.config.StaticIP)
var requestedIP net.IP
if ctr.requestedIP != nil {
requestedIP = ctr.requestedIP
// cancel request for a specific IP in case the container is reused later
ctr.requestedIP = nil
} else {
requestedIP = ctr.config.StaticIP
}

podNetwork := r.getPodNetwork(ctr.ID(), ctr.Name(), ctrNS.Path(), ctr.config.Networks, ctr.config.PortMappings, requestedIP)

results, err := r.netPlugin.SetUpPod(podNetwork)
if err != nil {
Expand Down Expand Up @@ -258,7 +267,16 @@ func (r *Runtime) teardownNetNS(ctr *Container) error {

logrus.Debugf("Tearing down network namespace at %s for container %s", ctr.state.NetNS.Path(), ctr.ID())

podNetwork := r.getPodNetwork(ctr.ID(), ctr.Name(), ctr.state.NetNS.Path(), ctr.config.Networks, ctr.config.PortMappings, ctr.config.StaticIP)
var requestedIP net.IP
if ctr.requestedIP != nil {
requestedIP = ctr.requestedIP
// cancel request for a specific IP in case the container is reused later
ctr.requestedIP = nil
} else {
requestedIP = ctr.config.StaticIP
}

podNetwork := r.getPodNetwork(ctr.ID(), ctr.Name(), ctr.state.NetNS.Path(), ctr.config.Networks, ctr.config.PortMappings, requestedIP)

// The network may have already been torn down, so don't fail here, just log
if err := r.netPlugin.TearDownPod(podNetwork); err != nil {
Expand Down

0 comments on commit 2553dad

Please sign in to comment.