Skip to content

Commit

Permalink
Add logs displaying podman commands executed
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy committed Dec 5, 2022
1 parent 961dc84 commit 0c69883
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
10 changes: 6 additions & 4 deletions pkg/podman/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ type ListPodsReport struct {
}

func (o *PodmanCli) ListAllComponents() ([]api.ComponentAbstract, error) {
out, err := exec.Command(o.podmanCmd, "pod", "ps", "--format", "json", "--filter", "status=running").Output()
cmd := exec.Command(o.podmanCmd, "pod", "ps", "--format", "json", "--filter", "status=running")
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))
Expand All @@ -32,10 +34,10 @@ func (o *PodmanCli) ListAllComponents() ([]api.ComponentAbstract, error) {
}

for _, pod := range list {
klog.V(5).Infof("\npod name: %s\n", pod.Name)
klog.V(5).Infof("labels:\n")
klog.V(5).Infof("\npod name: %s", pod.Name)
klog.V(5).Infof("labels:")
for k, v := range pod.Labels {
klog.V(5).Infof(" - %s: %s\n", k, v)
klog.V(5).Infof(" - %s: %s", k, v)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/podman/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ func (o *PodmanCli) ExecCMDInContainer(containerName, podName string, cmd []stri
args = append(args, cmd...)

command := exec.Command(o.podmanCmd, args...)
klog.V(3).Infof("executing %v", command.Args)
command.Stdin = stdin

klog.V(4).Infof("exec %s %v\n", o.podmanCmd, args)
out, err := command.Output()
if err != nil {
return err
Expand Down
17 changes: 13 additions & 4 deletions pkg/podman/podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func (o *PodmanCli) PlayKube(pod *corev1.Pod) error {
)

cmd := exec.Command(o.podmanCmd, "play", "kube", "-")
klog.V(3).Infof("executing %v", cmd.Args)
stdin, err := cmd.StdinPipe()
if err != nil {
return err
Expand Down Expand Up @@ -89,7 +90,9 @@ func (o *PodmanCli) PlayKube(pod *corev1.Pod) error {
}

func (o *PodmanCli) PodStop(podname string) error {
out, err := exec.Command(o.podmanCmd, "pod", "stop", podname).Output()
cmd := exec.Command(o.podmanCmd, "pod", "stop", podname)
out, err := cmd.Output()
klog.V(3).Infof("executing %v", cmd.Args)
if err != nil {
if exiterr, ok := err.(*exec.ExitError); ok {
err = fmt.Errorf("%s: %s", err, string(exiterr.Stderr))
Expand All @@ -101,7 +104,9 @@ func (o *PodmanCli) PodStop(podname string) error {
}

func (o *PodmanCli) PodRm(podname string) error {
out, err := exec.Command(o.podmanCmd, "pod", "rm", podname).Output()
cmd := exec.Command(o.podmanCmd, "pod", "rm", podname)
out, err := cmd.Output()
klog.V(3).Infof("executing %v", cmd.Args)
if err != nil {
if exiterr, ok := err.(*exec.ExitError); ok {
err = fmt.Errorf("%s: %s", err, string(exiterr.Stderr))
Expand All @@ -113,7 +118,9 @@ func (o *PodmanCli) PodRm(podname string) error {
}

func (o *PodmanCli) VolumeRm(volumeName string) error {
out, err := exec.Command(o.podmanCmd, "volume", "rm", volumeName).Output()
cmd := exec.Command(o.podmanCmd, "volume", "rm", volumeName)
out, err := cmd.Output()
klog.V(3).Infof("executing %v", cmd.Args)
if err != nil {
if exiterr, ok := err.(*exec.ExitError); ok {
err = fmt.Errorf("%s: %s", err, string(exiterr.Stderr))
Expand All @@ -125,7 +132,9 @@ func (o *PodmanCli) VolumeRm(volumeName string) error {
}

func (o *PodmanCli) VolumeLs() (map[string]bool, error) {
out, err := exec.Command(o.podmanCmd, "volume", "ls", "--format", "{{.Name}}", "--noheading").Output()
cmd := exec.Command(o.podmanCmd, "volume", "ls", "--format", "{{.Name}}", "--noheading")
out, err := cmd.Output()
klog.V(3).Infof("executing %v", cmd.Args)
if err != nil {
if exiterr, ok := err.(*exec.ExitError); ok {
err = fmt.Errorf("%s: %s", err, string(exiterr.Stderr))
Expand Down
6 changes: 5 additions & 1 deletion pkg/podman/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"encoding/json"
"fmt"
"os/exec"

"k8s.io/klog"
)

type Version struct {
Expand All @@ -22,7 +24,9 @@ type SystemVersionReport struct {
}

func (o *PodmanCli) Version() (SystemVersionReport, error) {
out, err := exec.Command(o.podmanCmd, "version", "--format", "json").Output()
cmd := exec.Command(o.podmanCmd, "version", "--format", "json")
out, err := cmd.Output()
klog.V(3).Infof("executing %v", cmd.Args)
if err != nil {
if exiterr, ok := err.(*exec.ExitError); ok {
err = fmt.Errorf("%s: %s", err, string(exiterr.Stderr))
Expand Down

0 comments on commit 0c69883

Please sign in to comment.