From 11fc0e55401a21a88c90a2fa646f2624541711fe Mon Sep 17 00:00:00 2001
From: Aditya Rajan <arajan@redhat.com>
Date: Fri, 3 Sep 2021 11:54:56 +0530
Subject: kube: Add support for podman pod logs

Following PR adds support for `kubectl` like `pod logs` to podman.
Usage `podman pod logs <podIDorName` gives a stream of logs for all
the containers within the pod with **containername** as a field.

Just like **`kubectl`** also supports `podman pod logs -c ctrIDorName podIDorName`
to limit the log stream to any of the specificied container which belongs to pod.

Signed-off-by: Aditya Rajan <arajan@redhat.com>
---
 test/e2e/play_kube_test.go | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

(limited to 'test/e2e')

diff --git a/test/e2e/play_kube_test.go b/test/e2e/play_kube_test.go
index ab496f0eb..5d875effd 100644
--- a/test/e2e/play_kube_test.go
+++ b/test/e2e/play_kube_test.go
@@ -1289,6 +1289,40 @@ var _ = Describe("Podman play kube", func() {
 		Expect(logs.OutputToString()).To(ContainSubstring("hello world"))
 	})
 
+	It("podman pod logs test", func() {
+		SkipIfRemote("podman-remote pod logs -c is mandatory for remote machine")
+		p := getPod(withCtr(getCtr(withCmd([]string{"echo", "hello"}), withArg([]string{"world"}))))
+
+		err := generateKubeYaml("pod", p, kubeYaml)
+		Expect(err).To(BeNil())
+
+		kube := podmanTest.Podman([]string{"play", "kube", kubeYaml})
+		kube.WaitWithDefaultTimeout()
+		Expect(kube).Should(Exit(0))
+
+		logs := podmanTest.Podman([]string{"pod", "logs", p.Name})
+		logs.WaitWithDefaultTimeout()
+		Expect(logs).Should(Exit(0))
+		Expect(logs.OutputToString()).To(ContainSubstring("hello world"))
+	})
+
+	It("podman-remote pod logs test", func() {
+		// -c or --container is required in podman-remote due to api limitation.
+		p := getPod(withCtr(getCtr(withCmd([]string{"echo", "hello"}), withArg([]string{"world"}))))
+
+		err := generateKubeYaml("pod", p, kubeYaml)
+		Expect(err).To(BeNil())
+
+		kube := podmanTest.Podman([]string{"play", "kube", kubeYaml})
+		kube.WaitWithDefaultTimeout()
+		Expect(kube).Should(Exit(0))
+
+		logs := podmanTest.Podman([]string{"pod", "logs", "-c", getCtrNameInPod(p), p.Name})
+		logs.WaitWithDefaultTimeout()
+		Expect(logs).Should(Exit(0))
+		Expect(logs.OutputToString()).To(ContainSubstring("hello world"))
+	})
+
 	It("podman play kube test restartPolicy", func() {
 		// podName,  set,  expect
 		testSli := [][]string{
-- 
cgit v1.2.3-54-g00ecf