Files
odo/pkg/podman/inspect.go
Armel Soro 6241a66129 Allow passing extra flags to Podman/Docker (#6785)
* Allow passing extra build flags to Podman/Docker

This is supported via 2 new env vars:
- ODO_IMAGE_BUILD_ARGS: passed when building images via Podman/Docker
- ODO_CONTAINER_RUN_ARGS: passed when running odo dev on Podman

Those are comma-separated list of options
that can be passed to either Podman or Docker
(depending on the PODMAN_CMD env var).

* Refactor 'build-images' tests to make it easier to add additional tests

* Add integration tests for passing build extra args

* Add integration tests for passing global extra args to Podman

* Distinguish between global options passed to Podman and specific options for 'podman play kube'

Previously, we were handling 'ODO_CONTAINER_RUN_ARGS' as global options for Podman,
but this turns our not being that useful if we want to pass dedicated options to 'podman play kube'.
This commit introduces a new 'ODO_CONTAINER_BACKEND_GLOBAL_ARGS' env var,
which will be used as global options passed to every Podman command we execute.

This paves the way to isolating our Podman-related tests further
using the '--root' and '--runroot' global options.

* Use `ODO_IMAGE_BUILD_ARGS` in the Advanced Guides

* Use a semicolon as delimiter for extra flags

Doing so because some of the options of Podman/Docker can actually be either repeated or comma-separated.
2023-05-04 04:59:18 -04:00

42 lines
1.1 KiB
Go

package podman
import (
"encoding/json"
"fmt"
"os/exec"
"k8s.io/klog"
)
// PodInspectData originates from From https://github.com/containers/podman/blob/main/libpod/define/pod_inspect.go
type PodInspectData struct {
// ID is the ID of the pod.
ID string `json:"Id"`
// Name is the name of the pod.
Name string
// Namespace is the Libpod namespace the pod is placed in.
Namespace string `json:"Namespace,omitempty"`
// State represents the current state of the pod.
State string `json:"State"`
// Labels is a set of key-value labels that have been applied to the
// pod.
Labels map[string]string `json:"Labels,omitempty"`
}
func (o *PodmanCli) PodInspect(podname string) (PodInspectData, error) {
cmd := exec.Command(o.podmanCmd, append(o.containerRunGlobalExtraArgs, "pod", "inspect", podname, "--format", "json")...)
klog.V(3).Infof("executing %v", cmd.Args)
out, err := cmd.Output()
if err != nil {
if exiterr, ok := err.(*exec.ExitError); ok {
err = fmt.Errorf("%s: %s", err, string(exiterr.Stderr))
}
return PodInspectData{}, err
}
var result PodInspectData
err = json.Unmarshal(out, &result)
return result, err
}