...
1 package podman
2
3 import (
4 "encoding/json"
5 "fmt"
6 "os/exec"
7
8 "k8s.io/klog"
9 )
10
11
12 type PodInspectData struct {
13
14 ID string `json:"Id"`
15
16 Name string
17
18 Namespace string `json:"Namespace,omitempty"`
19
20 State string `json:"State"`
21
22
23 Labels map[string]string `json:"Labels,omitempty"`
24 }
25
26 func (o *PodmanCli) PodInspect(podname string) (PodInspectData, error) {
27 cmd := exec.Command(o.podmanCmd, append(o.containerRunGlobalExtraArgs, "pod", "inspect", podname, "--format", "json")...)
28 klog.V(3).Infof("executing %v", cmd.Args)
29 out, err := cmd.Output()
30 if err != nil {
31 if exiterr, ok := err.(*exec.ExitError); ok {
32 err = fmt.Errorf("%s: %s", err, string(exiterr.Stderr))
33 }
34 return PodInspectData{}, err
35 }
36
37 var result PodInspectData
38
39 err = json.Unmarshal(out, &result)
40 return result, err
41 }
42
View as plain text