fix(kube): watch events from a matching pod

Signed-off-by: 's avatarMatthew Fisher <matt.fisher@microsoft.com>
parent 91356c81
...@@ -935,7 +935,7 @@ func (c *Client) WaitAndGetCompletedPodPhase(namespace string, reader io.Reader, ...@@ -935,7 +935,7 @@ func (c *Client) WaitAndGetCompletedPodPhase(namespace string, reader io.Reader,
} }
func (c *Client) watchPodUntilComplete(timeout time.Duration, info *resource.Info) error { func (c *Client) watchPodUntilComplete(timeout time.Duration, info *resource.Info) error {
lw := cachetools.NewListWatchFromClient(info.Client, info.Mapping.Resource.Resource, info.Namespace, fields.Everything()) lw := cachetools.NewListWatchFromClient(info.Client, info.Mapping.Resource.Resource, info.Namespace, fields.ParseSelectorOrDie(fmt.Sprintf("metadata.name=%s", info.Name)))
c.Log("Watching pod %s for completion with timeout of %v", info.Name, timeout) c.Log("Watching pod %s for completion with timeout of %v", info.Name, timeout)
ctx, cancel := watchtools.ContextWithOptionalTimeout(context.Background(), timeout) ctx, cancel := watchtools.ContextWithOptionalTimeout(context.Background(), timeout)
......
...@@ -21,6 +21,7 @@ import ( ...@@ -21,6 +21,7 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log" "log"
"strings"
"sync" "sync"
"time" "time"
...@@ -31,6 +32,9 @@ import ( ...@@ -31,6 +32,9 @@ import (
"k8s.io/helm/pkg/tiller/environment" "k8s.io/helm/pkg/tiller/environment"
) )
// logEscaper is necessary for escaping control characters found in the log stream.
var logEscaper = strings.NewReplacer("%", "%%")
// Environment encapsulates information about where test suite executes and returns results // Environment encapsulates information about where test suite executes and returns results
type Environment struct { type Environment struct {
Namespace string Namespace string
...@@ -136,7 +140,7 @@ func (env *Environment) GetLogs(testManifests []string) { ...@@ -136,7 +140,7 @@ func (env *Environment) GetLogs(testManifests []string) {
env.streamError(err.Error()) env.streamError(err.Error())
continue continue
} }
if len(infos) < 1 { if len(infos) == 0 {
env.streamError(fmt.Sprint("Pod manifest is invalid. Unable to obtain the logs")) env.streamError(fmt.Sprint("Pod manifest is invalid. Unable to obtain the logs"))
continue continue
} }
...@@ -151,7 +155,7 @@ func (env *Environment) GetLogs(testManifests []string) { ...@@ -151,7 +155,7 @@ func (env *Environment) GetLogs(testManifests []string) {
env.streamError(err.Error()) env.streamError(err.Error())
continue continue
} }
msg := fmt.Sprintf("\nPOD LOGS: %s\n%s", podName, logs) msg := fmt.Sprintf("\nPOD LOGS: %s\n%s", podName, logEscaper.Replace(string(logs)))
env.streamMessage(msg, release.TestRun_UNKNOWN) env.streamMessage(msg, release.TestRun_RUNNING)
} }
} }
...@@ -95,6 +95,16 @@ func TestGetTestPodLogs(t *testing.T) { ...@@ -95,6 +95,16 @@ func TestGetTestPodLogs(t *testing.T) {
mockTestEnv.KubeClient = newGetLogKubeClient() mockTestEnv.KubeClient = newGetLogKubeClient()
mockTestEnv.GetLogs(mockTestSuite.TestManifests) mockTestEnv.GetLogs(mockTestSuite.TestManifests)
expectedMessage := "ERROR: Pod manifest is invalid. Unable to obtain the logs"
stream := mockTestEnv.Stream.(*mockStream)
if len(stream.messages) != 1 {
t.Errorf("Expected 1 message, got: %v", len(stream.messages))
}
if stream.messages[0].Msg != expectedMessage {
t.Errorf("Expected message '%s', got: %v", expectedMessage, stream.messages[0].Msg)
}
} }
func TestStreamMessage(t *testing.T) { func TestStreamMessage(t *testing.T) {
......
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