From 22aa1aff228a11036110ed1893c487ca4b8c43ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Mon, 13 Apr 2020 13:43:45 +0200 Subject: [PATCH] Handle more state and status for the podman driver --- pkg/drivers/kic/kic.go | 2 ++ pkg/drivers/kic/oci/oci.go | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/pkg/drivers/kic/kic.go b/pkg/drivers/kic/kic.go index cd7dae2803a3..89ff735e8616 100644 --- a/pkg/drivers/kic/kic.go +++ b/pkg/drivers/kic/kic.go @@ -244,6 +244,8 @@ func (d *Driver) GetState() (state.State, error) { o := strings.TrimSpace(string(out)) switch o { + case "configured": + return state.Stopped, nil case "running": return state.Running, nil case "exited": diff --git a/pkg/drivers/kic/oci/oci.go b/pkg/drivers/kic/oci/oci.go index cf3ebe15c2b7..0edd983af8f0 100644 --- a/pkg/drivers/kic/oci/oci.go +++ b/pkg/drivers/kic/oci/oci.go @@ -36,6 +36,7 @@ import ( "fmt" "os/exec" "strings" + "strconv" ) // DeleteContainersByLabel deletes all containers that have a specific label @@ -168,6 +169,13 @@ func CreateContainerNode(p CreateParams) error { } checkRunning := func() error { + r, err := ContainerRunning(p.OCIPrefix, p.OCIBinary, p.Name) + if err != nil { + return fmt.Errorf("temporary error checking running for %q : %v", p.Name, err) + } + if !r { + return fmt.Errorf("temporary error created container %q is not running yet", p.Name) + } s, err := ContainerStatus(p.OCIPrefix, p.OCIBinary, p.Name) if err != nil { return fmt.Errorf("temporary error checking status for %q : %v", p.Name, err) @@ -488,6 +496,15 @@ func PointToHostDockerDaemon() error { return nil } +// ContainerRunning returns running state of a container +func ContainerRunning(prefix string, ociBin string, name string) (bool, error) { + out, err := WarnIfSlow(prefix, ociBin, "inspect", name, "--format={{.State.Running}}") + if err != nil { + return false, err + } + return strconv.ParseBool(strings.TrimSpace(string(out))) +} + // ContainerStatus returns status of a container running,exited,... func ContainerStatus(prefix string, ociBin string, name string) (state.State, error) { out, err := WarnIfSlow(prefix, ociBin, "inspect", name, "--format={{.State.Status}}")