diff options
author | Matthew Heon <matthew.heon@gmail.com> | 2017-12-05 09:30:51 -0500 |
---|---|---|
committer | Matthew Heon <matthew.heon@gmail.com> | 2017-12-05 09:30:51 -0500 |
commit | ceb7fb1c60e559337523259f1e0063135e686c95 (patch) | |
tree | e842a19dee45006d327c45e8fcf4df6ede311163 /libpod/container.go | |
parent | 92bc448624e29fc84087bafcccd0e52b328a53e4 (diff) | |
download | podman-ceb7fb1c60e559337523259f1e0063135e686c95.tar.gz podman-ceb7fb1c60e559337523259f1e0063135e686c95.tar.bz2 podman-ceb7fb1c60e559337523259f1e0063135e686c95.zip |
Do not recreate OCI spec in init() if it exists
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
Diffstat (limited to 'libpod/container.go')
-rw-r--r-- | libpod/container.go | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/libpod/container.go b/libpod/container.go index c53184ea3..d12167d15 100644 --- a/libpod/container.go +++ b/libpod/container.go @@ -476,38 +476,37 @@ func (c *Container) init() (err error) { return err } - // Make the OCI runtime spec we will use - g := generate.NewFromSpec(c.config.Spec) - // Mount ShmDir from host into container - g.AddBindMount(c.config.ShmDir, "/dev/shm", []string{"rw"}) - c.runningSpec = g.Spec() - c.runningSpec.Root.Path = c.state.Mountpoint - c.runningSpec.Annotations[crioAnnotations.Created] = c.config.CreatedTime.Format(time.RFC3339Nano) - c.runningSpec.Annotations["org.opencontainers.image.stopSignal"] = fmt.Sprintf("%d", c.config.StopSignal) - // Save the OCI spec to disk jsonPath := filepath.Join(c.bundlePath(), "config.json") - // If the OCI spec already exists, replace it if _, err := os.Stat(jsonPath); err != nil { if !os.IsNotExist(err) { return errors.Wrapf(err, "error doing stat on container %s spec", c.ID()) } - } else { - // No error, the spec exists. Remove so we can replace. - if err := os.Remove(jsonPath); err != nil { - return errors.Wrapf(err, "error replacing spec of container %s", c.ID()) + + // The spec does not exist, needs to be created + g := generate.NewFromSpec(c.config.Spec) + // Mount ShmDir from host into container + g.AddBindMount(c.config.ShmDir, "/dev/shm", []string{"rw"}) + c.runningSpec = g.Spec() + c.runningSpec.Root.Path = c.state.Mountpoint + c.runningSpec.Annotations[crioAnnotations.Created] = c.config.CreatedTime.Format(time.RFC3339Nano) + c.runningSpec.Annotations["org.opencontainers.image.stopSignal"] = fmt.Sprintf("%d", c.config.StopSignal) + + fileJSON, err := json.Marshal(c.runningSpec) + if err != nil { + return errors.Wrapf(err, "error exporting runtime spec for container %s to JSON", c.ID()) } + if err := ioutil.WriteFile(jsonPath, fileJSON, 0644); err != nil { + return errors.Wrapf(err, "error writing runtime spec JSON to file for container %s", c.ID()) + } + + logrus.Debugf("Created OCI spec for container %s at %s", c.ID(), jsonPath) + } else { + // The spec exists + logrus.Debugf("Using existing OCI spec for container %s at %s", c.ID(), jsonPath) } - fileJSON, err := json.Marshal(c.runningSpec) - if err != nil { - return errors.Wrapf(err, "error exporting runtime spec for container %s to JSON", c.ID()) - } - if err := ioutil.WriteFile(jsonPath, fileJSON, 0644); err != nil { - return errors.Wrapf(err, "error writing runtime spec JSON to file for container %s", c.ID()) - } - c.state.ConfigPath = jsonPath - logrus.Debugf("Created OCI spec for container %s at %s", c.ID(), jsonPath) + c.state.ConfigPath = jsonPath // With the spec complete, do an OCI create // TODO set cgroup parent in a sane fashion |