Skip to content

Commit

Permalink
Handle more state and status for the podman driver
Browse files Browse the repository at this point in the history
  • Loading branch information
afbjorklund committed Apr 19, 2020
1 parent 401e94c commit 22aa1af
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/drivers/kic/kic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
17 changes: 17 additions & 0 deletions pkg/drivers/kic/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"fmt"
"os/exec"
"strings"
"strconv"
)

// DeleteContainersByLabel deletes all containers that have a specific label
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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}}")
Expand Down

0 comments on commit 22aa1af

Please sign in to comment.