...

Source file src/github.com/redhat-developer/odo/pkg/podman/inspect.go

Documentation: github.com/redhat-developer/odo/pkg/podman

     1  package podman
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"os/exec"
     7  
     8  	"k8s.io/klog"
     9  )
    10  
    11  // PodInspectData originates from From https://github.com/containers/podman/blob/main/libpod/define/pod_inspect.go
    12  type PodInspectData struct {
    13  	// ID is the ID of the pod.
    14  	ID string `json:"Id"`
    15  	// Name is the name of the pod.
    16  	Name string
    17  	// Namespace is the Libpod namespace the pod is placed in.
    18  	Namespace string `json:"Namespace,omitempty"`
    19  	// State represents the current state of the pod.
    20  	State string `json:"State"`
    21  	// Labels is a set of key-value labels that have been applied to the
    22  	// pod.
    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