Unverified Commit ef5d4e65 authored by Jeff Knurek's avatar Jeff Knurek Committed by Matthew Fisher

change GetPodLogs to return io.Reader instead of string

well, more specifically returns an io.ReadCloser (giving the consumer more capabilities)
Signed-off-by: 's avatarJeff Knurek <j.knurek@travelaudience.com>
parent 7f2e0c53
......@@ -31,7 +31,7 @@ import (
"k8s.io/apimachinery/pkg/api/meta"
"github.com/evanphx/json-patch"
jsonpatch "github.com/evanphx/json-patch"
appsv1 "k8s.io/api/apps/v1"
appsv1beta1 "k8s.io/api/apps/v1beta1"
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).
func (c *Client) GetPodLogs(name, ns string) (string, error) {
func (c *Client) GetPodLogs(name, ns string) (io.ReadCloser, error) {
client, err := c.KubernetesClientSet()
if err != nil {
return "", err
return nil, err
}
req := client.CoreV1().Pods(ns).GetLogs(name, &v1.PodLogOptions{})
podLogs, 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)
logReader, err := req.Stream()
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) {
......
......@@ -19,6 +19,7 @@ package releasetesting
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"sync"
"time"
......@@ -140,7 +141,12 @@ func (env *Environment) GetLogs(testManifests []string) {
continue
}
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 {
env.streamError(err.Error())
continue
......
......@@ -175,7 +175,7 @@ type KubeClient interface {
// and returns said phase (PodSucceeded or PodFailed qualify).
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
}
......@@ -258,8 +258,8 @@ func (p *PrintingKubeClient) WaitAndGetCompletedPodPhase(namespace string, reade
}
// GetPodLogs implements KubeClient GetPodLogs.
func (p *PrintingKubeClient) GetPodLogs(name, ns string) (string, error) {
return "", nil
func (p *PrintingKubeClient) GetPodLogs(name, ns string) (io.ReadCloser, error) {
return nil, nil
}
// WaitUntilCRDEstablished implements KubeClient WaitUntilCRDEstablished.
......
......@@ -78,8 +78,8 @@ func (k *mockKubeClient) WaitAndGetCompletedPodStatus(namespace string, reader i
return "", nil
}
func (k *mockKubeClient) GetPodLogs(name, namespace string) (string, error) {
return "", nil
func (k *mockKubeClient) GetPodLogs(name, namespace string) (io.ReadCloser, error) {
return nil, nil
}
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) {
return v1.PodUnknown, nil
}
func (kc *mockHooksKubeClient) GetPodLogs(name, namespace string) (string, error) {
return "", nil
func (kc *mockHooksKubeClient) GetPodLogs(name, namespace string) (io.ReadCloser, error) {
return nil, nil
}
func (kc *mockHooksKubeClient) WaitUntilCRDEstablished(reader io.Reader, timeout time.Duration) error {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment