Windows: Refactor state struct
Signed-off-by: John Howard <jhoward@microsoft.com>
This commit is contained in:
parent
97929bd6dd
commit
fe1cce69b3
|
@ -1,3 +1,5 @@
|
||||||
|
// +build linux freebsd
|
||||||
|
|
||||||
package configs
|
package configs
|
||||||
|
|
||||||
import (
|
import (
|
|
@ -0,0 +1,3 @@
|
||||||
|
package configs
|
||||||
|
|
||||||
|
// All current tests are for Unix-specific functionality
|
|
@ -30,8 +30,9 @@ const (
|
||||||
Destroyed
|
Destroyed
|
||||||
)
|
)
|
||||||
|
|
||||||
// State represents a running container's state
|
// BaseState represents the platform agnostic pieces relating to a
|
||||||
type State struct {
|
// running container's state
|
||||||
|
type BaseState struct {
|
||||||
// ID is the container ID.
|
// ID is the container ID.
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
|
|
||||||
|
@ -41,19 +42,8 @@ type State struct {
|
||||||
// InitProcessStartTime is the init process start time.
|
// InitProcessStartTime is the init process start time.
|
||||||
InitProcessStartTime string `json:"init_process_start"`
|
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 is the container's configuration.
|
||||||
Config configs.Config `json:"config"`
|
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.
|
// A libcontainer container object.
|
||||||
|
|
|
@ -34,6 +34,24 @@ type linuxContainer struct {
|
||||||
m sync.Mutex
|
m sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
// ID returns the container's unique ID
|
||||||
func (c *linuxContainer) ID() string {
|
func (c *linuxContainer) ID() string {
|
||||||
return c.id
|
return c.id
|
||||||
|
@ -899,13 +917,15 @@ func (c *linuxContainer) currentState() (*State, error) {
|
||||||
return nil, newSystemError(err)
|
return nil, newSystemError(err)
|
||||||
}
|
}
|
||||||
state := &State{
|
state := &State{
|
||||||
ID: c.ID(),
|
BaseState: BaseState{
|
||||||
Config: *c.config,
|
ID: c.ID(),
|
||||||
InitProcessPid: c.initProcess.pid(),
|
Config: *c.config,
|
||||||
InitProcessStartTime: startTime,
|
InitProcessPid: c.initProcess.pid(),
|
||||||
CgroupPaths: c.cgroupManager.GetPaths(),
|
InitProcessStartTime: startTime,
|
||||||
NamespacePaths: make(map[configs.NamespaceType]string),
|
},
|
||||||
ExternalDescriptors: c.initProcess.externalDescriptors(),
|
CgroupPaths: c.cgroupManager.GetPaths(),
|
||||||
|
NamespacePaths: make(map[configs.NamespaceType]string),
|
||||||
|
ExternalDescriptors: c.initProcess.externalDescriptors(),
|
||||||
}
|
}
|
||||||
for _, ns := range c.config.Namespaces {
|
for _, ns := range c.config.Namespaces {
|
||||||
state.NamespacePaths[ns.Type] = ns.GetPath(c.initProcess.pid())
|
state.NamespacePaths[ns.Type] = ns.GetPath(c.initProcess.pid())
|
||||||
|
|
|
@ -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",
|
Rootfs: "/mycontainer/root",
|
||||||
}
|
}
|
||||||
expectedState = &State{
|
expectedState = &State{
|
||||||
InitProcessPid: 1024,
|
BaseState: BaseState{
|
||||||
Config: *expectedConfig,
|
InitProcessPid: 1024,
|
||||||
|
Config: *expectedConfig,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
if err := os.Mkdir(filepath.Join(root, id), 0700); err != nil {
|
if err := os.Mkdir(filepath.Join(root, id), 0700); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue