change GetPodLogs to return io.Reader instead of string

well, more specifically returns an io.ReadCloser (giving the consumer more capabilities)

Signed-off-by: Jeff Knurek <j.knurek@travelaudience.com>
pull/6612/head
Jeff Knurek 6 years ago committed by Matthew Fisher
parent 7f2e0c535c
commit ef5d4e652c
No known key found for this signature in database
GPG Key ID: 92AA783CBAAE8E3B

@ -31,7 +31,7 @@ import (
"k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/api/meta"
"github.com/evanphx/json-patch" jsonpatch "github.com/evanphx/json-patch"
appsv1 "k8s.io/api/apps/v1" appsv1 "k8s.io/api/apps/v1"
appsv1beta1 "k8s.io/api/apps/v1beta1" appsv1beta1 "k8s.io/api/apps/v1beta1"
appsv1beta2 "k8s.io/api/apps/v1beta2" appsv1beta2 "k8s.io/api/apps/v1beta2"
@ -948,24 +948,17 @@ func (c *Client) watchPodUntilComplete(timeout time.Duration, info *resource.Inf
} }
// GetPodLogs takes pod name and namespace and returns the current logs (streaming is NOT enabled). // GetPodLogs takes pod name and namespace and returns the current logs (streaming is NOT enabled).
func (c *Client) GetPodLogs(name, ns string) (string, error) { func (c *Client) GetPodLogs(name, ns string) (io.ReadCloser, error) {
client, err := c.KubernetesClientSet() client, err := c.KubernetesClientSet()
if err != nil { if err != nil {
return "", err return nil, err
} }
req := client.CoreV1().Pods(ns).GetLogs(name, &v1.PodLogOptions{}) req := client.CoreV1().Pods(ns).GetLogs(name, &v1.PodLogOptions{})
podLogs, err := req.Stream() logReader, err := req.Stream()
if err != nil {
return "", fmt.Errorf("error in opening log stream, got: %s", err)
}
defer podLogs.Close()
buf := new(bytes.Buffer)
_, err = io.Copy(buf, podLogs)
if err != nil { if err != nil {
return "", fmt.Errorf("error in copy information from log stream to buf, got: %s", err) return nil, fmt.Errorf("error in opening log stream, got: %s", err)
} }
return buf.String(), nil return logReader, nil
} }
func isPodComplete(event watch.Event) (bool, error) { func isPodComplete(event watch.Event) (bool, error) {

@ -19,6 +19,7 @@ package releasetesting
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"sync" "sync"
"time" "time"
@ -140,7 +141,12 @@ func (env *Environment) GetLogs(testManifests []string) {
continue continue
} }
podName := infos[0].Object.(*v1.Pod).Name podName := infos[0].Object.(*v1.Pod).Name
logs, err := env.KubeClient.GetPodLogs(podName, env.Namespace) lr, err := env.KubeClient.GetPodLogs(podName, env.Namespace)
if err != nil {
env.streamError(err.Error())
continue
}
logs, err := ioutil.ReadAll(lr)
if err != nil { if err != nil {
env.streamError(err.Error()) env.streamError(err.Error())
continue continue

@ -175,7 +175,7 @@ type KubeClient interface {
// and returns said phase (PodSucceeded or PodFailed qualify). // and returns said phase (PodSucceeded or PodFailed qualify).
WaitAndGetCompletedPodPhase(namespace string, reader io.Reader, timeout time.Duration) (v1.PodPhase, error) WaitAndGetCompletedPodPhase(namespace string, reader io.Reader, timeout time.Duration) (v1.PodPhase, error)
GetPodLogs(name, namespace string) (string, error) GetPodLogs(name, namespace string) (io.ReadCloser, error)
WaitUntilCRDEstablished(reader io.Reader, timeout time.Duration) error WaitUntilCRDEstablished(reader io.Reader, timeout time.Duration) error
} }
@ -258,8 +258,8 @@ func (p *PrintingKubeClient) WaitAndGetCompletedPodPhase(namespace string, reade
} }
// GetPodLogs implements KubeClient GetPodLogs. // GetPodLogs implements KubeClient GetPodLogs.
func (p *PrintingKubeClient) GetPodLogs(name, ns string) (string, error) { func (p *PrintingKubeClient) GetPodLogs(name, ns string) (io.ReadCloser, error) {
return "", nil return nil, nil
} }
// WaitUntilCRDEstablished implements KubeClient WaitUntilCRDEstablished. // WaitUntilCRDEstablished implements KubeClient WaitUntilCRDEstablished.

@ -78,8 +78,8 @@ func (k *mockKubeClient) WaitAndGetCompletedPodStatus(namespace string, reader i
return "", nil return "", nil
} }
func (k *mockKubeClient) GetPodLogs(name, namespace string) (string, error) { func (k *mockKubeClient) GetPodLogs(name, namespace string) (io.ReadCloser, error) {
return "", nil return nil, nil
} }
func (k *mockKubeClient) WaitUntilCRDEstablished(reader io.Reader, timeout time.Duration) error { func (k *mockKubeClient) WaitUntilCRDEstablished(reader io.Reader, timeout time.Duration) error {

@ -679,8 +679,8 @@ func (kc *mockHooksKubeClient) Validate(ns string, reader io.Reader) error {
func (kc *mockHooksKubeClient) WaitAndGetCompletedPodPhase(namespace string, reader io.Reader, timeout time.Duration) (v1.PodPhase, error) { func (kc *mockHooksKubeClient) WaitAndGetCompletedPodPhase(namespace string, reader io.Reader, timeout time.Duration) (v1.PodPhase, error) {
return v1.PodUnknown, nil return v1.PodUnknown, nil
} }
func (kc *mockHooksKubeClient) GetPodLogs(name, namespace string) (string, error) { func (kc *mockHooksKubeClient) GetPodLogs(name, namespace string) (io.ReadCloser, error) {
return "", nil return nil, nil
} }
func (kc *mockHooksKubeClient) WaitUntilCRDEstablished(reader io.Reader, timeout time.Duration) error { func (kc *mockHooksKubeClient) WaitUntilCRDEstablished(reader io.Reader, timeout time.Duration) error {

Loading…
Cancel
Save