Address review comments

Signed-off-by: Matthew Heon <mheon@redhat.com>
This commit is contained in:
Matthew Heon 2017-10-25 12:04:52 -04:00
parent 9b563f7970
commit 3b60d38769
3 changed files with 20 additions and 15 deletions

View file

@ -54,7 +54,7 @@ type Container struct {
} }
// containerState contains the current state of the container // containerState contains the current state of the container
// It is stored as on disk in a per-boot directory // It is stored on disk in a tmpfs and recreated on reboot
type containerRuntimeInfo struct { type containerRuntimeInfo struct {
// The current state of the running container // The current state of the running container
State ContainerState `json:"state"` State ContainerState `json:"state"`
@ -75,12 +75,11 @@ type containerRuntimeInfo struct {
ExitCode int32 `json:"exitCode,omitempty"` ExitCode int32 `json:"exitCode,omitempty"`
// TODO: Save information about image used in container if one is used // TODO: Save information about image used in container if one is used
// TODO save start time, create time (create time in the containerConfig?)
} }
// containerConfig contains all information that was used to create the // containerConfig contains all information that was used to create the
// container. It may not be changed once created. // container. It may not be changed once created.
// It is stored as an unchanging part of on-disk state // It is stored, read-only, on disk
type containerConfig struct { type containerConfig struct {
Spec *spec.Spec `json:"spec"` Spec *spec.Spec `json:"spec"`
ID string `json:"id"` ID string `json:"id"`
@ -281,6 +280,8 @@ func (c *Container) Create() (err error) {
c.state.Mounted = true c.state.Mounted = true
c.state.Mountpoint = mountPoint c.state.Mountpoint = mountPoint
logrus.Debugf("Created root filesystem for container %s at %s", c.ID(), c.state.Mountpoint)
defer func() { defer func() {
if err != nil { if err != nil {
if err2 := c.runtime.storageService.StopContainer(c.ID()); err2 != nil { if err2 := c.runtime.storageService.StopContainer(c.ID()); err2 != nil {
@ -310,12 +311,16 @@ func (c *Container) Create() (err error) {
} }
c.state.ConfigPath = jsonPath c.state.ConfigPath = jsonPath
logrus.Debugf("Created OCI spec for container %s at %s", c.ID(), jsonPath)
// With the spec complete, do an OCI create // With the spec complete, do an OCI create
// TODO set cgroup parent in a sane fashion // TODO set cgroup parent in a sane fashion
if err := c.runtime.ociRuntime.createContainer(c, "/libpod_parent"); err != nil { if err := c.runtime.ociRuntime.createContainer(c, "/libpod_parent"); err != nil {
return err return err
} }
logrus.Debugf("Created container %s in runc", c.ID())
// TODO should flush this state to disk here // TODO should flush this state to disk here
c.state.State = ContainerStateCreated c.state.State = ContainerStateCreated
@ -340,6 +345,8 @@ func (c *Container) Start() error {
return err return err
} }
logrus.Debugf("Started container %s", c.ID())
// TODO should flush state to disk here // TODO should flush state to disk here
c.state.StartedTime = time.Now() c.state.StartedTime = time.Now()
c.state.State = ContainerStateRunning c.state.State = ContainerStateRunning

View file

@ -119,7 +119,7 @@ func (r *OCIRuntime) createContainer(ctr *Container, cgroupParent string) error
childStartPipe, parentStartPipe, err := newPipe() childStartPipe, parentStartPipe, err := newPipe()
if err != nil { if err != nil {
return errors.Wrapf(err, "error creating socket pair") return errors.Wrapf(err, "error creating socket pair for start pipe")
} }
defer parentPipe.Close() defer parentPipe.Close()

View file

@ -22,12 +22,11 @@ func getStorageService(store storage.Store) (*storageService, error) {
return &storageService{store: store}, nil return &storageService{store: store}, nil
} }
// ContainerInfo wraps a subset of information about a container: its ID and // ContainerInfo wraps a subset of information about a container: the locations
// the locations of its nonvolatile and volatile per-container directories, // of its nonvolatile and volatile per-container directories, along with a copy
// along with a copy of the configuration blob from the image that was used to // of the configuration blob from the image that was used to create the
// create the container, if the image had a configuration. // container, if the image had a configuration.
type ContainerInfo struct { type ContainerInfo struct {
ID string
Dir string Dir string
RunDir string RunDir string
Config *v1.Image Config *v1.Image
@ -35,11 +34,11 @@ type ContainerInfo struct {
// RuntimeContainerMetadata is the structure that we encode as JSON and store // RuntimeContainerMetadata is the structure that we encode as JSON and store
// in the metadata field of storage.Container objects. It is used for // in the metadata field of storage.Container objects. It is used for
// specifying attributes of pod sandboxes and containers when they are being // specifying attributes containers when they are being created, and allows a
// created, and allows a container's MountLabel, and possibly other values, to // container's MountLabel, and possibly other values, to be modified in one
// be modified in one read/write cycle via calls to // read/write cycle via calls to storageService.ContainerMetadata,
// RuntimeServer.ContainerMetadata, RuntimeContainerMetadata.SetMountLabel, // RuntimeContainerMetadata.SetMountLabel, and
// and RuntimeServer.SetContainerMetadata. // storageService.SetContainerMetadata.
type RuntimeContainerMetadata struct { type RuntimeContainerMetadata struct {
// The provided name and the ID of the image that was used to // The provided name and the ID of the image that was used to
// instantiate the container. // instantiate the container.
@ -158,7 +157,6 @@ func (r *storageService) CreateContainerStorage(systemContext *types.SystemConte
logrus.Debugf("container %q has run directory %q", container.ID, containerRunDir) logrus.Debugf("container %q has run directory %q", container.ID, containerRunDir)
return ContainerInfo{ return ContainerInfo{
ID: container.ID, // not needed
Dir: containerDir, Dir: containerDir,
RunDir: containerRunDir, RunDir: containerRunDir,
Config: imageConfig, Config: imageConfig,