Skip to content

Commit

Permalink
use event writer in skaffold execution (#5965)
Browse files Browse the repository at this point in the history
* use event writer in skaffold execution

* user correct artifact ids

* properly set output for deploy

* use constant to represent no subtask ID
  • Loading branch information
MarlonGamez authored Jun 16, 2021
1 parent bf5290e commit 5c2e24c
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/skaffold/build/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (l *logAggregatorImpl) GetWriter() (io.Writer, func(), error) {

writer := io.Writer(w)
if output.IsColorable(l.out) {
writer = output.NewColorWriter(writer)
writer = output.GetWriter(writer, output.DefaultColorCode, false)
}
ch := make(chan string, buffSize)
l.messages <- ch
Expand Down
2 changes: 2 additions & 0 deletions pkg/skaffold/build/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"golang.org/x/sync/errgroup"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/event"
eventV2 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/event/v2"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph"
Expand Down Expand Up @@ -107,6 +108,7 @@ func (s *scheduler) build(ctx context.Context, tags tag.ImageTags, i int) error
}
defer closeFn()

w = output.WithEventContext(w, constants.Build, strconv.Itoa(eventV2.GetArtifactID(a)), "skaffold")
finalTag, err := performBuild(ctx, w, tags, a, s.artifactBuilder)
if err != nil {
event.BuildFailed(a.ImageName, err)
Expand Down
4 changes: 4 additions & 0 deletions pkg/skaffold/deploy/deploy_mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ import (
"bytes"
"context"
"io"
"strconv"
"strings"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
eventV2 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/event/v2"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/instrumentation"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/manifest"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/log"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/output"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
)

Expand All @@ -48,6 +51,7 @@ func (m DeployerMux) Deploy(ctx context.Context, w io.Writer, as []graph.Artifac

for i, deployer := range m {
eventV2.DeployInProgress(i)
w = output.WithEventContext(w, constants.Deploy, strconv.Itoa(i), "skaffold")
ctx, endTrace := instrumentation.StartTrace(ctx, "Deploy")

namespaces, err := deployer.Deploy(ctx, w, as)
Expand Down
8 changes: 8 additions & 0 deletions pkg/skaffold/event/v2/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ func AssignArtifactIDs(artifacts []*latestV1.Artifact) {
}
}

func GetArtifactID(a *latestV1.Artifact) int {
if id, ok := artifactIDs[a.ImageName]; ok {
return id
}

return -1
}

func CacheCheckInProgress(artifact string) {
buildSubtaskEvent(artifact, Cache, InProgress, nil)
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/skaffold/event/v2/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const (
Succeeded = "Succeeded"
Terminated = "Terminated"
Canceled = "Canceled"

SubtaskIDNone = "-1"
)

var handler = newHandler()
Expand Down
3 changes: 1 addition & 2 deletions pkg/skaffold/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package output

import (
"io"
"io/ioutil"
"os"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
Expand Down Expand Up @@ -52,7 +51,7 @@ func GetWriter(out io.Writer, defaultColor int, forceColors bool) io.Writer {
return skaffoldWriter{
MainWriter: SetupColors(out, defaultColor, forceColors),
// TODO(marlongamez): Replace this once event writer is implemented
EventWriter: ioutil.Discard,
EventWriter: eventV2.NewLogger(constants.DevLoop, "-1", "skaffold"),
}
}

Expand Down
1 change: 1 addition & 0 deletions pkg/skaffold/runner/build_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func (r *Builder) GetBuilds() []graph.Artifact {
func (r *Builder) Build(ctx context.Context, out io.Writer, artifacts []*latestV1.Artifact) ([]graph.Artifact, error) {
eventV2.TaskInProgress(constants.Build, "Build Containers")
eventV2.AssignArtifactIDs(artifacts)
out = output.WithEventContext(out, constants.Build, eventV2.SubtaskIDNone, "skaffold")

// Use tags directly from the Kubernetes manifests.
if r.runCtx.DigestSource() == NoneDigestSource {
Expand Down
2 changes: 2 additions & 0 deletions pkg/skaffold/runner/v1/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ func (r *SkaffoldRunner) Deploy(ctx context.Context, out io.Writer, artifacts []
return r.Render(ctx, out, artifacts, false, r.runCtx.RenderOutput())
}

out = output.WithEventContext(out, constants.Deploy, eventV2.SubtaskIDNone, "skaffold")

output.Default.Fprintln(out, "Tags used in deployment:")

for _, artifact := range artifacts {
Expand Down

0 comments on commit 5c2e24c

Please sign in to comment.