Skip to content

Commit 178b427

Browse files
committed
api/types/container: nice enum values for status
Signed-off-by: Stephen J Day <stephen.day@docker.com>
1 parent 0dbe46d commit 178b427

File tree

5 files changed

+72
-65
lines changed

5 files changed

+72
-65
lines changed

api/types/container/container.pb.go

Lines changed: 49 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/types/container/container.proto

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ import "gogoproto/gogo.proto";
77
import "google/protobuf/timestamp.proto";
88

99
enum Status {
10-
UNKNOWN = 0;
11-
CREATED = 1;
12-
RUNNING = 2;
13-
STOPPED = 3;
14-
PAUSED = 4;
10+
option (gogoproto.goproto_enum_prefix) = false;
11+
option (gogoproto.enum_customname) = "Status";
12+
13+
UNKNOWN = 0 [(gogoproto.enumvalue_customname) = "StatusUnknown"];
14+
CREATED = 1 [(gogoproto.enumvalue_customname) = "StatusCreated"];
15+
RUNNING = 2 [(gogoproto.enumvalue_customname) = "StatusRunning"];
16+
STOPPED = 3 [(gogoproto.enumvalue_customname) = "StatusStopped"];
17+
PAUSED = 4 [(gogoproto.enumvalue_customname) = "StatusPaused"];
1518
}
1619

1720
message Container {

linux/container.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ func (c *Container) State(ctx context.Context) (plugin.State, error) {
5757
}
5858
var status plugin.Status
5959
switch response.Status {
60-
case container.Status_CREATED:
60+
case container.StatusCreated:
6161
status = plugin.CreatedStatus
62-
case container.Status_RUNNING:
62+
case container.StatusRunning:
6363
status = plugin.RunningStatus
64-
case container.Status_STOPPED:
64+
case container.StatusStopped:
6565
status = plugin.StoppedStatus
66-
case container.Status_PAUSED:
66+
case container.StatusPaused:
6767
status = plugin.PausedStatus
6868
// TODO: containerd.DeletedStatus
6969
}

linux/shim/service.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,16 @@ func (s *Service) State(ctx context.Context, r *shimapi.StateRequest) (*shimapi.
160160
if err != nil {
161161
return nil, err
162162
}
163-
status := container.Status_UNKNOWN
163+
status := container.StatusUnknown
164164
switch st {
165165
case "created":
166-
status = container.Status_CREATED
166+
status = container.StatusCreated
167167
case "running":
168-
status = container.Status_RUNNING
168+
status = container.StatusRunning
169169
case "stopped":
170-
status = container.Status_STOPPED
170+
status = container.StatusStopped
171171
case "paused":
172-
status = container.Status_PAUSED
172+
status = container.StatusPaused
173173
}
174174
o := &shimapi.StateResponse{
175175
ID: s.id,
@@ -181,12 +181,12 @@ func (s *Service) State(ctx context.Context, r *shimapi.StateRequest) (*shimapi.
181181
s.mu.Lock()
182182
defer s.mu.Unlock()
183183
for _, p := range s.processes {
184-
status := container.Status_RUNNING
184+
status := container.StatusRunning
185185
if err := unix.Kill(p.Pid(), 0); err != nil {
186186
if err != syscall.ESRCH {
187187
return nil, err
188188
}
189-
status = container.Status_STOPPED
189+
status = container.StatusStopped
190190
}
191191
o.Processes = append(o.Processes, &container.Process{
192192
Pid: uint32(p.Pid()),

services/execution/service.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,13 @@ func containerFromContainerd(ctx context.Context, c plugin.Container) (*containe
150150
var status container.Status
151151
switch state.Status() {
152152
case plugin.CreatedStatus:
153-
status = container.Status_CREATED
153+
status = container.StatusCreated
154154
case plugin.RunningStatus:
155-
status = container.Status_RUNNING
155+
status = container.StatusRunning
156156
case plugin.StoppedStatus:
157-
status = container.Status_STOPPED
157+
status = container.StatusStopped
158158
case plugin.PausedStatus:
159-
status = container.Status_PAUSED
159+
status = container.StatusPaused
160160
default:
161161
log.G(ctx).WithField("status", state.Status()).Warn("unknown status")
162162
}

0 commit comments

Comments
 (0)