Skip to content

Commit

Permalink
feat(client): add GetPodLogs helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
Long Nguyen committed Mar 31, 2021
1 parent e88b561 commit 65dd7b3
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"crypto/tls"
"crypto/x509"
"fmt"
"io"

"net"
"net/http"
Expand Down Expand Up @@ -505,6 +506,26 @@ func (c *Client) GetJobPod(namespace, jobName string) (string, error) {
}
}

func (c *Client) GetPodLogs(namespace, podName, container string) (string, error) {
client, err := c.GetClientset()
if err != nil {
return "", err
}
podLogOptions := v1.PodLogOptions{}
if container != "" {
podLogOptions.Container = container
}
req := client.CoreV1().Pods(namespace).GetLogs(podName, &podLogOptions)
podLogs, err := req.Stream(context.TODO())
if err != nil {
return "", err
}
defer podLogs.Close()
buf := new(bytes.Buffer)
_, err = io.Copy(buf, podLogs)
return buf.String(), nil
}

func (c *Client) StreamLogs(namespace, name string) error {
client, err := c.GetClientset()
if err != nil {
Expand Down

0 comments on commit 65dd7b3

Please # to comment.