From d679da0645225992b68fbf4dbecec440330e4af7 Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Tue, 14 Mar 2017 16:39:09 -0400 Subject: [PATCH] If the container exit file is missing default exit code to -1 If I create a sandbox pod and then restart the ocid service, the pod ends up in a stopped state without an exit file. Whether this is a bug in ocid or not we should handle this case where a container exits so that we can clean up the container. This change just defaults to exit code to -1 if the container is not running and does not have an exit file. Signed-off-by: Daniel J Walsh --- oci/oci.go | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/oci/oci.go b/oci/oci.go index 7189f1ac..869e7444 100644 --- a/oci/oci.go +++ b/oci/oci.go @@ -429,20 +429,22 @@ func (r *Runtime) UpdateStatus(c *Container) error { exitFilePath := filepath.Join(c.bundlePath, "exit") fi, err := os.Stat(exitFilePath) if err != nil { - return fmt.Errorf("failed to find container exit file: %v", err) - } - st := fi.Sys().(*syscall.Stat_t) - c.state.Finished = time.Unix(st.Ctim.Sec, st.Ctim.Nsec) + logrus.Warnf("failed to find container exit file: %v", err) + c.state.ExitCode = -1 + } else { + st := fi.Sys().(*syscall.Stat_t) + c.state.Finished = time.Unix(st.Ctim.Sec, st.Ctim.Nsec) - statusCodeStr, err := ioutil.ReadFile(exitFilePath) - if err != nil { - return fmt.Errorf("failed to read exit file: %v", err) + statusCodeStr, err := ioutil.ReadFile(exitFilePath) + if err != nil { + return fmt.Errorf("failed to read exit file: %v", err) + } + statusCode, err := strconv.Atoi(string(statusCodeStr)) + if err != nil { + return fmt.Errorf("status code conversion failed: %v", err) + } + c.state.ExitCode = int32(statusCode) } - statusCode, err := strconv.Atoi(string(statusCodeStr)) - if err != nil { - return fmt.Errorf("status code conversion failed: %v", err) - } - c.state.ExitCode = int32(statusCode) } return nil