Skip to content

Commit 4350d90

Browse files
committed
Use same state object for state and list
Signed-off-by: Michael Crosby <[email protected]>
1 parent b1e602e commit 4350d90

File tree

3 files changed

+10
-28
lines changed

3 files changed

+10
-28
lines changed

list.go

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const formatOptions = `table or json`
2222
// containerState represents the platform agnostic pieces relating to a
2323
// running container's status and state
2424
type containerState struct {
25+
// Version is the OCI version for the container
26+
Version string `json:"ociVersion"`
2527
// ID is the container ID
2628
ID string `json:"id"`
2729
// InitProcessPid is the init process id in the parent namespace
@@ -30,6 +32,8 @@ type containerState struct {
3032
Status string `json:"status"`
3133
// Bundle is the path on the filesystem to the bundle
3234
Bundle string `json:"bundle"`
35+
// Rootfs is a path to a directory containing the container's root filesystem.
36+
Rootfs string `json:"rootfs"`
3337
// Created is the unix timestamp for the creation time of the container in UTC
3438
Created time.Time `json:"created"`
3539
// Annotations is the user defined annotations added to the config.
@@ -140,10 +144,12 @@ func getContainers(context *cli.Context) ([]containerState, error) {
140144
}
141145
bundle, annotations := utils.Annotations(state.Config.Labels)
142146
s = append(s, containerState{
147+
Version: state.BaseState.Config.Version,
143148
ID: state.BaseState.ID,
144149
InitProcessPid: pid,
145150
Status: containerStatus.String(),
146151
Bundle: bundle,
152+
Rootfs: state.BaseState.Config.Rootfs,
147153
Created: state.BaseState.Created,
148154
Annotations: annotations,
149155
})

state.go

+1-25
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,12 @@ package main
55
import (
66
"encoding/json"
77
"os"
8-
"time"
98

109
"github.com/opencontainers/runc/libcontainer"
1110
"github.com/opencontainers/runc/libcontainer/utils"
1211
"github.com/urfave/cli"
1312
)
1413

15-
// cState represents the platform agnostic pieces relating to a running
16-
// container's status and state. Note: The fields in this structure adhere to
17-
// the opencontainers/runtime-spec/specs-go requirement for json fields that must be returned
18-
// in a state command.
19-
type cState struct {
20-
// Version is the OCI version for the container
21-
Version string `json:"ociVersion"`
22-
// ID is the container ID
23-
ID string `json:"id"`
24-
// InitProcessPid is the init process id in the parent namespace
25-
InitProcessPid int `json:"pid"`
26-
// Bundle is the path on the filesystem to the bundle
27-
Bundle string `json:"bundlePath"`
28-
// Rootfs is a path to a directory containing the container's root filesystem.
29-
Rootfs string `json:"rootfsPath"`
30-
// Status is the current status of the container, running, paused, ...
31-
Status string `json:"status"`
32-
// Created is the unix timestamp for the creation time of the container in UTC
33-
Created time.Time `json:"created"`
34-
// Annotations is the user defined annotations added to the config.
35-
Annotations map[string]string `json:"annotations,omitempty"`
36-
}
37-
3814
var stateCommand = cli.Command{
3915
Name: "state",
4016
Usage: "output the state of a container",
@@ -61,7 +37,7 @@ instance of a container.`,
6137
pid = 0
6238
}
6339
bundle, annotations := utils.Annotations(state.Config.Labels)
64-
cs := cState{
40+
cs := containerState{
6541
Version: state.BaseState.Config.Version,
6642
ID: state.BaseState.ID,
6743
InitProcessPid: pid,

tests/integration/list.bats

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function teardown() {
4747

4848
ROOT=$HELLO_BUNDLE runc list --format json
4949
[ "$status" -eq 0 ]
50-
[[ "${lines[0]}" == [\[][\{]"\"id\""[:]"\"test_box1\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$BUSYBOX_BUNDLE*[,]"\"created\""[:]*[0-9]*[\}]* ]]
51-
[[ "${lines[0]}" == *[,][\{]"\"id\""[:]"\"test_box2\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$BUSYBOX_BUNDLE*[,]"\"created\""[:]*[0-9]*[\}]* ]]
52-
[[ "${lines[0]}" == *[,][\{]"\"id\""[:]"\"test_box3\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$BUSYBOX_BUNDLE*[,]"\"created\""[:]*[0-9]*[\}][\]] ]]
50+
[[ "${lines[0]}" == [\[][\{]"\"ociVersion\""[:]"\""*[0-9][\.]*[0-9][\.]*[0-9]*"\""[,]"\"id\""[:]"\"test_box1\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$BUSYBOX_BUNDLE*[,]"\"rootfs\""[:]"\""*"\""[,]"\"created\""[:]*[0-9]*[\}]* ]]
51+
[[ "${lines[0]}" == *[,][\{]"\"ociVersion\""[:]"\""*[0-9][\.]*[0-9][\.]*[0-9]*"\""[,]"\"id\""[:]"\"test_box2\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$BUSYBOX_BUNDLE*[,]"\"rootfs\""[:]"\""*"\""[,]"\"created\""[:]*[0-9]*[\}]* ]]
52+
[[ "${lines[0]}" == *[,][\{]"\"ociVersion\""[:]"\""*[0-9][\.]*[0-9][\.]*[0-9]*"\""[,]"\"id\""[:]"\"test_box3\""[,]"\"pid\""[:]*[0-9][,]"\"status\""[:]*"\"running\""[,]"\"bundle\""[:]*$BUSYBOX_BUNDLE*[,]"\"rootfs\""[:]"\""*"\""[,]"\"created\""[:]*[0-9]*[\}][\]] ]]
5353
}

0 commit comments

Comments
 (0)