mirror of
https://github.com/rkt/rkt.git
synced 2026-03-13 09:40:21 +08:00
Merge pull request #3800 from kinvolk/iaguis/relax-exit-code
lib: don't error out if we can't get the app exit code
This commit is contained in:
23
lib/app.go
23
lib/app.go
@@ -16,7 +16,6 @@ package rkt
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/appc/spec/schema"
|
||||
@@ -184,11 +183,14 @@ func appStateInMutablePod(app *v1.App, pod *pkgPod.Pod) error {
|
||||
finishedAt := fi.ModTime().UnixNano()
|
||||
app.FinishedAt = &finishedAt
|
||||
|
||||
// Read exit code.
|
||||
exitCode, err := readExitCode(appStatusFile)
|
||||
code, err := pod.AppExitCode(app.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
// if we can't get the exit code (e.g. we didn't have time to write it
|
||||
// after a pod dies) let's continue instead of erroring out, the exit code
|
||||
// will be a generic 1 and we'll let callers handle it.
|
||||
code = 1
|
||||
}
|
||||
exitCode := int32(code)
|
||||
app.ExitCode = &exitCode
|
||||
|
||||
return nil
|
||||
@@ -248,16 +250,3 @@ func appStateFromPod(pod *pkgPod.Pod) v1.AppState {
|
||||
return v1.AppStateUnknown
|
||||
}
|
||||
}
|
||||
|
||||
func readExitCode(path string) (int32, error) {
|
||||
var exitCode int32
|
||||
|
||||
b, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
return -1, fmt.Errorf("cannot read app exited file: %v", err)
|
||||
}
|
||||
if _, err := fmt.Sscanf(string(b), "%d", &exitCode); err != nil {
|
||||
return -1, fmt.Errorf("cannot parse exit code: %v", err)
|
||||
}
|
||||
return exitCode, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user