Skip to content

Commit

Permalink
Add PodLog function to retrieve Pod log using function
Browse files Browse the repository at this point in the history
  • Loading branch information
sutaakar committed Dec 3, 2024
1 parent 96d3dd4 commit a54c87d
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions support/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,25 @@ func GetPods(t Test, namespace string, options metav1.ListOptions) []corev1.Pod
return pods.Items
}

func GetPodLogs(t Test, pod *corev1.Pod, options corev1.PodLogOptions) []byte {
t.T().Helper()
stream, err := t.Client().Core().CoreV1().Pods(pod.GetNamespace()).GetLogs(pod.GetName(), &options).Stream(t.Ctx())
t.Expect(err).NotTo(gomega.HaveOccurred())
func PodLog(t Test, namespace, name string, options corev1.PodLogOptions) func(g gomega.Gomega) string {
return func(g gomega.Gomega) string {
stream, err := t.Client().Core().CoreV1().Pods(namespace).GetLogs(name, &options).Stream(t.Ctx())
g.Expect(err).NotTo(gomega.HaveOccurred())

defer func() {
t.Expect(stream.Close()).To(gomega.Succeed())
}()
defer func() {
g.Expect(stream.Close()).To(gomega.Succeed())
}()

bytes, err := io.ReadAll(stream)
t.Expect(err).NotTo(gomega.HaveOccurred())
bytes, err := io.ReadAll(stream)
g.Expect(err).NotTo(gomega.HaveOccurred())

return bytes
return string(bytes)
}
}

func GetPodLog(t Test, namespace, name string, options corev1.PodLogOptions) string {
t.T().Helper()
return PodLog(t, namespace, name, options)(t)
}

func storeAllPodLogs(t Test, namespace *corev1.Namespace) {
Expand Down

0 comments on commit a54c87d

Please sign in to comment.