diff --git a/pkg/skaffold/kubernetes/log.go b/pkg/skaffold/kubernetes/log.go index a0d1e5130fc..ce61b2f53f8 100644 --- a/pkg/skaffold/kubernetes/log.go +++ b/pkg/skaffold/kubernetes/log.go @@ -88,6 +88,7 @@ func (a *LogAggregator) Start(ctx context.Context) error { case <-cancelCtx.Done(): return case evt, ok := <-aggregate: + if !ok { return } @@ -96,6 +97,7 @@ func (a *LogAggregator) Start(ctx context.Context) error { if !ok { continue } + logrus.Tracef("logger saw a pod event: %s - %s - watch: %t \n\n", pod.Name, pod.Status.Phase, a.podSelector.Select(pod)) if !a.podSelector.Select(pod) { continue diff --git a/pkg/skaffold/kubernetes/watcher.go b/pkg/skaffold/kubernetes/watcher.go index ce3eb1988f3..2bd3046bc65 100644 --- a/pkg/skaffold/kubernetes/watcher.go +++ b/pkg/skaffold/kubernetes/watcher.go @@ -18,6 +18,7 @@ package kubernetes import ( "github.com/pkg/errors" + "github.com/sirupsen/logrus" meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/watch" ) @@ -39,6 +40,7 @@ func AggregatePodWatcher(namespaces []string, aggregate chan<- watch.Event) (fun var forever int64 = 3600 * 24 * 365 * 100 for _, ns := range namespaces { + logrus.Tracef("starting pod watcher in namespace '%s'", ns) watcher, err := kubeclient.CoreV1().Pods(ns).Watch(meta_v1.ListOptions{ TimeoutSeconds: &forever, }) diff --git a/pkg/skaffold/runner/build_deploy.go b/pkg/skaffold/runner/build_deploy.go index 4e609af2a72..9fe330699dd 100644 --- a/pkg/skaffold/runner/build_deploy.go +++ b/pkg/skaffold/runner/build_deploy.go @@ -60,7 +60,7 @@ func (r *SkaffoldRunner) BuildAndTest(ctx context.Context, out io.Writer, artifa return nil, err } - // Update which images are logged. + // Update which images are logged and portforwarded. for _, build := range bRes { r.podSelector.Add(build.Tag) } @@ -92,6 +92,7 @@ func (r *SkaffoldRunner) DeployAndLog(ctx context.Context, out io.Writer, artifa var imageNames []string for _, artifact := range artifacts { imageNames = append(imageNames, artifact.ImageName) + r.podSelector.Add(artifact.Tag) } logger := r.newLoggerForImages(out, imageNames) diff --git a/pkg/skaffold/runner/build_deploy_test.go b/pkg/skaffold/runner/build_deploy_test.go index 79383686a79..1a1a93d3e9e 100644 --- a/pkg/skaffold/runner/build_deploy_test.go +++ b/pkg/skaffold/runner/build_deploy_test.go @@ -21,12 +21,44 @@ import ( "io/ioutil" "testing" + v1 "k8s.io/api/core/v1" + + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/build" + "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" "github.com/GoogleContainerTools/skaffold/testutil" "github.com/pkg/errors" "k8s.io/client-go/tools/clientcmd/api" ) +func TestDeployLogging(t *testing.T) { + testutil.Run(t, "should list pods for logging", func(t *testutil.T) { + t.SetupFakeKubernetesContext(api.Config{CurrentContext: "cluster1"}) + + ctx := context.Background() + artifacts := []build.Artifact{{ + ImageName: "img", + Tag: "img:1", + }} + + bench := &TestBench{} + runner := createRunner(t, bench, nil) + runner.runCtx.Opts.Tail = true + + err := runner.DeployAndLog(ctx, ioutil.Discard, artifacts) + + t.CheckErrorAndDeepEqual(false, err, []Actions{{Deployed: []string{"img:1"}}}, bench.Actions()) + t.CheckDeepEqual(true, runner.podSelector.Select(&v1.Pod{ + Spec: v1.PodSpec{ + Containers: []v1.Container{ + { + Image: "img:1", + }, + }, + }, + })) + }) +} func TestBuildTestDeploy(t *testing.T) { tests := []struct { description string