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 ( ...@@ -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 ...@@ -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 ...@@ -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) { ...@@ -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 { ...@@ -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 ...@@ -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 ...@@ -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 { ...@@ -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 {
......
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