Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] fix deploy logging #2987

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/skaffold/kubernetes/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func (a *LogAggregator) Start(ctx context.Context) error {
case <-cancelCtx.Done():
return
case evt, ok := <-aggregate:

if !ok {
return
}
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pkg/skaffold/kubernetes/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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,
})
Expand Down
3 changes: 2 additions & 1 deletion pkg/skaffold/runner/build_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the fix, it's a one line change. Testing it is a bit more involved, hence the rest of the PR.

}

logger := r.newLoggerForImages(out, imageNames)
Expand Down
32 changes: 32 additions & 0 deletions pkg/skaffold/runner/build_deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down