diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-05-21 22:08:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-21 22:08:17 +0200 |
commit | 1cf9a1bdba195fea77a002d8b51cf8f965b861fb (patch) | |
tree | 5239eb2936e7f888c5b7ebe697543ff980e572ab /libpod | |
parent | 536fd6adddd9693649457441bd4721c3a774ff0b (diff) | |
parent | 3788da93445dffda35a00366c90a9d8da6ef0702 (diff) | |
download | podman-1cf9a1bdba195fea77a002d8b51cf8f965b861fb.tar.gz podman-1cf9a1bdba195fea77a002d8b51cf8f965b861fb.tar.bz2 podman-1cf9a1bdba195fea77a002d8b51cf8f965b861fb.zip |
Merge pull request #3173 from giuseppe/use-wait-for-file
libpod: prefer WaitForFile to polling
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/container_internal.go | 19 | ||||
-rw-r--r-- | libpod/oci.go | 23 |
2 files changed, 11 insertions, 31 deletions
diff --git a/libpod/container_internal.go b/libpod/container_internal.go index fc33a1bbc..5f8dd1c72 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -25,7 +25,6 @@ import ( opentracing "github.com/opentracing/opentracing-go" "github.com/pkg/errors" "github.com/sirupsen/logrus" - kwait "k8s.io/apimachinery/pkg/util/wait" ) const ( @@ -146,20 +145,10 @@ func (c *Container) exitFilePath() string { func (c *Container) waitForExitFileAndSync() error { exitFile := c.exitFilePath() - err := kwait.ExponentialBackoff( - kwait.Backoff{ - Duration: 500 * time.Millisecond, - Factor: 1.2, - Steps: 6, - }, - func() (bool, error) { - _, err := os.Stat(exitFile) - if err != nil { - // wait longer - return false, nil - } - return true, nil - }) + chWait := make(chan error) + defer close(chWait) + + _, err := WaitForFile(exitFile, chWait, time.Second*5) if err != nil { // Exit file did not appear // Reset our state diff --git a/libpod/oci.go b/libpod/oci.go index 3dfde4f24..abc6214b9 100644 --- a/libpod/oci.go +++ b/libpod/oci.go @@ -17,7 +17,6 @@ import ( "github.com/opencontainers/selinux/go-selinux/label" "github.com/pkg/errors" "github.com/sirupsen/logrus" - kwait "k8s.io/apimachinery/pkg/util/wait" // TODO import these functions into libpod and remove the import // Trying to keep libpod from depending on CRI-O code @@ -261,21 +260,13 @@ func (r *OCIRuntime) updateContainerStatus(ctr *Container, useRuntime bool) erro // If we were, it should already be in the database if ctr.state.State == ContainerStateStopped && oldState != ContainerStateStopped { var fi os.FileInfo - err = kwait.ExponentialBackoff( - kwait.Backoff{ - Duration: 500 * time.Millisecond, - Factor: 1.2, - Steps: 6, - }, - func() (bool, error) { - var err error - fi, err = os.Stat(exitFile) - if err != nil { - // wait longer - return false, nil - } - return true, nil - }) + chWait := make(chan error) + defer close(chWait) + + _, err := WaitForFile(exitFile, chWait, time.Second*5) + if err == nil { + fi, err = os.Stat(exitFile) + } if err != nil { ctr.state.ExitCode = -1 ctr.state.FinishedTime = time.Now() |