Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
edigaryev committed Feb 16, 2021
1 parent 2f7aa4f commit a85e5ed
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,15 @@ type ContainerWaitResult struct {
}

type SystemInfo struct {
Version string
TotalCPUs int64
TotalMemoryBytes int64
}

type Version struct {
Version string
}

const (
BackendAuto = "auto"
BackendDocker = "docker"
Expand Down
1 change: 1 addition & 0 deletions internal/executor/instance/containerbackend/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ func (backend *Docker) SystemInfo(ctx context.Context) (*SystemInfo, error) {
}

return &SystemInfo{
Version: info.ServerVersion,
TotalCPUs: int64(info.NCPU),
TotalMemoryBytes: info.MemTotal,
}, nil
Expand Down
27 changes: 26 additions & 1 deletion internal/executor/instance/containerbackend/podman_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type Podman struct {
basePath string
httpClient *http.Client
cli *swagger.APIClient

usingNumericalContainerState bool
}

func NewPodman() (ContainerBackend, error) {
Expand Down Expand Up @@ -74,6 +76,15 @@ func NewPodman() (ContainerBackend, error) {
HTTPClient: podman.httpClient,
})

// Query server's version and activate bug workarounds (if applicable)
version, err := podman.SystemInfo(context.Background())
if err != nil {
return nil, err
}
if version.Version == "3.0.0" {
podman.usingNumericalContainerState = true
}

return podman, nil
}

Expand Down Expand Up @@ -416,9 +427,16 @@ func (backend *Podman) ContainerWait(ctx context.Context, id string) (<-chan Con
errChan := make(chan error)

go func() {
condition := "stopped"

if backend.usingNumericalContainerState {
// https://github.com/containers/podman/blob/v3.0.0/libpod/define/containerstate.go#L22
condition = "4"
}

// nolint:bodyclose // already closed by Swagger-generated code
resp, _, err := backend.cli.ContainersApi.LibpodWaitContainer(ctx, id, &swagger.ContainersApiLibpodWaitContainerOpts{
Condition: optional.NewString("stopped"),
Condition: optional.NewString(condition),
})

if err != nil {
Expand Down Expand Up @@ -524,7 +542,14 @@ func (backend *Podman) SystemInfo(ctx context.Context) (*SystemInfo, error) {
return nil, err
}

var version string

if info.Version != nil {
version = info.Version.Version
}

return &SystemInfo{
Version: version,
TotalCPUs: info.Host.Cpus,
TotalMemoryBytes: info.Host.MemTotal,
}, nil
Expand Down

0 comments on commit a85e5ed

Please sign in to comment.