Set Container Status Reason when OOM Killed

Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
This commit is contained in:
Mrunal Patel 2017-05-23 14:04:10 -07:00
parent 52b27da680
commit ea9a90abce
4 changed files with 14 additions and 4 deletions

View file

@ -460,6 +460,7 @@ func ContainerStatus(client pb.RuntimeServiceClient, ID string) error {
ftm := time.Unix(0, r.Status.FinishedAt) ftm := time.Unix(0, r.Status.FinishedAt)
fmt.Printf("Finished: %v\n", ftm) fmt.Printf("Finished: %v\n", ftm)
fmt.Printf("Exit Code: %v\n", r.Status.ExitCode) fmt.Printf("Exit Code: %v\n", r.Status.ExitCode)
fmt.Printf("Reason: %v\n", r.Status.Reason)
if r.Status.Image != nil { if r.Status.Image != nil {
fmt.Printf("Image: %v\n", r.Status.Image.Image) fmt.Printf("Image: %v\n", r.Status.Image.Image)
} }

View file

@ -38,10 +38,11 @@ type Container struct {
// ContainerState represents the status of a container. // ContainerState represents the status of a container.
type ContainerState struct { type ContainerState struct {
specs.State specs.State
Created time.Time `json:"created"` Created time.Time `json:"created"`
Started time.Time `json:"started,omitempty"` Started time.Time `json:"started,omitempty"`
Finished time.Time `json:"finished,omitempty"` Finished time.Time `json:"finished,omitempty"`
ExitCode int32 `json:"exitCode,omitempty"` ExitCode int32 `json:"exitCode,omitempty"`
OOMKilled bool `json:"oomKilled,omitempty"`
} }
// NewContainer creates a container object. // NewContainer creates a container object.

View file

@ -552,6 +552,11 @@ func (r *Runtime) UpdateStatus(c *Container) error {
} }
c.state.ExitCode = int32(statusCode) c.state.ExitCode = int32(statusCode)
} }
oomFilePath := filepath.Join(c.bundlePath, "oom")
if _, err = os.Stat(oomFilePath); err == nil {
c.state.OOMKilled = true
}
} }
return nil return nil

View file

@ -98,6 +98,9 @@ func (s *Server) ContainerStatus(ctx context.Context, req *pb.ContainerStatusReq
finished := cState.Finished.UnixNano() finished := cState.Finished.UnixNano()
resp.Status.FinishedAt = finished resp.Status.FinishedAt = finished
resp.Status.ExitCode = cState.ExitCode resp.Status.ExitCode = cState.ExitCode
if cState.OOMKilled {
resp.Status.Reason = "OOMKilled"
}
} }
resp.Status.State = rStatus resp.Status.State = rStatus