mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-29 16:57:18 +00:00
api: add sandbox StatusContainer API
It retrieves container status from sandbox. Signed-off-by: Peng Tao <bergwolf@gmail.com>
This commit is contained in:
parent
4b30446217
commit
b3d9683743
@ -17,4 +17,5 @@ var (
|
||||
errNeedFile = errors.New("File cannot be empty")
|
||||
errNeedState = errors.New("State cannot be empty")
|
||||
errInvalidResource = errors.New("Invalid sandbox resource")
|
||||
errNoSuchContainer = errors.New("Container does not exist")
|
||||
)
|
||||
|
@ -53,6 +53,7 @@ type VCSandbox interface {
|
||||
CreateContainer(contConfig ContainerConfig) (VCContainer, error)
|
||||
DeleteContainer(contID string) (VCContainer, error)
|
||||
StartContainer(containerID string) (VCContainer, error)
|
||||
StatusContainer(containerID string) (ContainerStatus, error)
|
||||
}
|
||||
|
||||
// VCContainer is the Container interface
|
||||
|
@ -84,3 +84,8 @@ func (p *Sandbox) DeleteContainer(contID string) (vc.VCContainer, error) {
|
||||
func (p *Sandbox) StartContainer(contID string) (vc.VCContainer, error) {
|
||||
return &Container{}, nil
|
||||
}
|
||||
|
||||
// StatusContainer implements the VCSandbox function of the same name.
|
||||
func (p *Sandbox) StatusContainer(contID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{}, nil
|
||||
}
|
||||
|
@ -946,6 +946,29 @@ func (s *Sandbox) DeleteContainer(containerID string) (VCContainer, error) {
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// StatusContainer gets the status of a container
|
||||
// TODO: update container status properly, see kata-containers/runtime#253
|
||||
func (s *Sandbox) StatusContainer(containerID string) (ContainerStatus, error) {
|
||||
if containerID == "" {
|
||||
return ContainerStatus{}, errNeedContainerID
|
||||
}
|
||||
|
||||
for _, c := range s.containers {
|
||||
if c.id == containerID {
|
||||
return ContainerStatus{
|
||||
ID: c.id,
|
||||
State: c.state,
|
||||
PID: c.process.Pid,
|
||||
StartTime: c.process.StartTime,
|
||||
RootFs: c.config.RootFs,
|
||||
Annotations: c.config.Annotations,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
return ContainerStatus{}, errNoSuchContainer
|
||||
}
|
||||
|
||||
// createContainers registers all containers to the proxy, create the
|
||||
// containers in the guest and starts one shim per container.
|
||||
func (s *Sandbox) createContainers() error {
|
||||
|
@ -1336,3 +1336,23 @@ func TestStartContainer(t *testing.T) {
|
||||
_, err = s.StartContainer(contID)
|
||||
assert.Nil(t, err, "Start container failed: %v", err)
|
||||
}
|
||||
|
||||
func TestStatusContainer(t *testing.T) {
|
||||
s, err := testCreateSandbox(t, testSandboxID, MockHypervisor, newHypervisorConfig(nil, nil), NoopAgentType, NoopNetworkModel, NetworkConfig{}, nil, nil)
|
||||
assert.Nil(t, err, "VirtContainers should not allow empty sandboxes")
|
||||
defer cleanUp()
|
||||
|
||||
contID := "999"
|
||||
_, err = s.StatusContainer(contID)
|
||||
assert.NotNil(t, err, "Status non-existing container should fail")
|
||||
|
||||
contConfig := newTestContainerConfigNoop(contID)
|
||||
_, err = s.CreateContainer(contConfig)
|
||||
assert.Nil(t, err, "Failed to create container %+v in sandbox %+v: %v", contConfig, s, err)
|
||||
|
||||
_, err = s.StatusContainer(contID)
|
||||
assert.Nil(t, err, "Status container failed: %v", err)
|
||||
|
||||
_, err = s.DeleteContainer(contID)
|
||||
assert.Nil(t, err, "Failed to delete container %s in sandbox %s: %v", contID, s.ID(), err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user