Merge pull request #359 from jhowardmsft/jjh/state_struct
Windows: Refactor state struct
This commit is contained in:
commit
7caef5626b
|
@ -1,3 +1,5 @@
|
|||
// +build linux freebsd
|
||||
|
||||
package configs
|
||||
|
||||
import (
|
|
@ -0,0 +1,3 @@
|
|||
package configs
|
||||
|
||||
// All current tests are for Unix-specific functionality
|
|
@ -30,8 +30,9 @@ const (
|
|||
Destroyed
|
||||
)
|
||||
|
||||
// State represents a running container's state
|
||||
type State struct {
|
||||
// BaseState represents the platform agnostic pieces relating to a
|
||||
// running container's state
|
||||
type BaseState struct {
|
||||
// ID is the container ID.
|
||||
ID string `json:"id"`
|
||||
|
||||
|
@ -41,19 +42,8 @@ type State struct {
|
|||
// InitProcessStartTime is the init process start time.
|
||||
InitProcessStartTime string `json:"init_process_start"`
|
||||
|
||||
// Path to all the cgroups setup for a container. Key is cgroup subsystem name
|
||||
// with the value as the path.
|
||||
CgroupPaths map[string]string `json:"cgroup_paths"`
|
||||
|
||||
// NamespacePaths are filepaths to the container's namespaces. Key is the namespace type
|
||||
// with the value as the path.
|
||||
NamespacePaths map[configs.NamespaceType]string `json:"namespace_paths"`
|
||||
|
||||
// Config is the container's configuration.
|
||||
Config configs.Config `json:"config"`
|
||||
|
||||
// Container's standard descriptors (std{in,out,err}), needed for checkpoint and restore
|
||||
ExternalDescriptors []string `json:"external_descriptors,omitempty"`
|
||||
}
|
||||
|
||||
// A libcontainer container object.
|
||||
|
|
|
@ -36,6 +36,24 @@ type linuxContainer struct {
|
|||
criuVersion int
|
||||
}
|
||||
|
||||
// State represents a running container's state
|
||||
type State struct {
|
||||
BaseState
|
||||
|
||||
// Platform specific fields below here
|
||||
|
||||
// Path to all the cgroups setup for a container. Key is cgroup subsystem name
|
||||
// with the value as the path.
|
||||
CgroupPaths map[string]string `json:"cgroup_paths"`
|
||||
|
||||
// NamespacePaths are filepaths to the container's namespaces. Key is the namespace type
|
||||
// with the value as the path.
|
||||
NamespacePaths map[configs.NamespaceType]string `json:"namespace_paths"`
|
||||
|
||||
// Container's standard descriptors (std{in,out,err}), needed for checkpoint and restore
|
||||
ExternalDescriptors []string `json:"external_descriptors,omitempty"`
|
||||
}
|
||||
|
||||
// ID returns the container's unique ID
|
||||
func (c *linuxContainer) ID() string {
|
||||
return c.id
|
||||
|
@ -917,10 +935,12 @@ func (c *linuxContainer) currentState() (*State, error) {
|
|||
return nil, newSystemError(err)
|
||||
}
|
||||
state := &State{
|
||||
BaseState: BaseState{
|
||||
ID: c.ID(),
|
||||
Config: *c.config,
|
||||
InitProcessPid: c.initProcess.pid(),
|
||||
InitProcessStartTime: startTime,
|
||||
},
|
||||
CgroupPaths: c.cgroupManager.GetPaths(),
|
||||
NamespacePaths: make(map[configs.NamespaceType]string),
|
||||
ExternalDescriptors: c.initProcess.externalDescriptors(),
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package libcontainer
|
||||
|
||||
// State represents a running container's state
|
||||
type State struct {
|
||||
BaseState
|
||||
|
||||
// Platform specific fields below here
|
||||
}
|
|
@ -137,8 +137,10 @@ func TestFactoryLoadContainer(t *testing.T) {
|
|||
Rootfs: "/mycontainer/root",
|
||||
}
|
||||
expectedState = &State{
|
||||
BaseState: BaseState{
|
||||
InitProcessPid: 1024,
|
||||
Config: *expectedConfig,
|
||||
},
|
||||
}
|
||||
)
|
||||
if err := os.Mkdir(filepath.Join(root, id), 0700); err != nil {
|
||||
|
|
Loading…
Reference in New Issue