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

Add logrus.Logger return type on WithEventContext() #6309

Merged
merged 2 commits into from
Jul 28, 2021
Merged
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: 1 addition & 1 deletion pkg/skaffold/build/cache/retrieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (c *cache) Build(ctx context.Context, out io.Writer, tags tag.ImageTags, ar
var alreadyBuilt []graph.Artifact
for i, artifact := range artifacts {
eventV2.CacheCheckInProgress(artifact.ImageName)
out := output.WithEventContext(out, constants.Build, artifact.ImageName)
out, _ := output.WithEventContext(out, constants.Build, artifact.ImageName)
output.Default.Fprintf(out, " - %s: ", artifact.ImageName)

result := results[i]
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/build/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (s *scheduler) build(ctx context.Context, tags tag.ImageTags, i int) error
}
defer closeFn()

w = output.WithEventContext(w, constants.Build, a.ImageName)
w, _ = output.WithEventContext(w, constants.Build, a.ImageName)
finalTag, err := performBuild(ctx, w, tags, a, s.artifactBuilder)
if err != nil {
event.BuildFailed(a.ImageName, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/deploy/deploy_mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (m DeployerMux) RegisterLocalImages(images []graph.Artifact) {
func (m DeployerMux) Deploy(ctx context.Context, w io.Writer, as []graph.Artifact) error {
for i, deployer := range m.deployers {
eventV2.DeployInProgress(i)
w = output.WithEventContext(w, constants.Deploy, strconv.Itoa(i))
w, _ = output.WithEventContext(w, constants.Deploy, strconv.Itoa(i))
ctx, endTrace := instrumentation.StartTrace(ctx, "Deploy")

if err := deployer.Deploy(ctx, w, as); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/kubernetes/portforward/entry_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func NewEntryManager(entryForwarder EntryForwarder) *EntryManager {
}

func (b *EntryManager) forwardPortForwardEntry(ctx context.Context, out io.Writer, entry *portForwardEntry) {
out = output.WithEventContext(out, constants.PortForward, fmt.Sprintf("%s/%s", entry.resource.Type, entry.resource.Name))
out, _ = output.WithEventContext(out, constants.PortForward, fmt.Sprintf("%s/%s", entry.resource.Type, entry.resource.Name))

// Check if this resource has already been forwarded
if _, ok := b.forwardedResources.Load(entry.key()); ok {
Expand Down
4 changes: 2 additions & 2 deletions pkg/skaffold/kubernetes/status/status_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func (s *Monitor) printStatusCheckSummary(out io.Writer, r *resource.Deployment,
}
event.ResourceStatusCheckEventCompleted(r.String(), ae)
eventV2.ResourceStatusCheckEventCompleted(r.String(), sErrors.V2fromV1(ae))
out = output.WithEventContext(out, constants.Deploy, r.String())
out, _ = output.WithEventContext(out, constants.Deploy, r.String())
status := fmt.Sprintf("%s %s", tabHeader, r)
if ae.ErrCode != proto.StatusCode_STATUSCHECK_SUCCESS {
if str := r.ReportSinceLastUpdated(s.muteLogs); str != "" {
Expand Down Expand Up @@ -333,7 +333,7 @@ func (s *Monitor) printStatus(deployments []*resource.Deployment, out io.Writer)
ae := r.Status().ActionableError()
event.ResourceStatusCheckEventUpdated(r.String(), ae)
eventV2.ResourceStatusCheckEventUpdated(r.String(), sErrors.V2fromV1(ae))
out := output.WithEventContext(out, constants.Deploy, r.String())
out, _ := output.WithEventContext(out, constants.Deploy, r.String())
fmt.Fprintln(out, trimNewLine(str))
}
}
Expand Down
8 changes: 5 additions & 3 deletions pkg/skaffold/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"os"
"time"

"github.com/sirupsen/logrus"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
eventV2 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/event/v2"
)
Expand Down Expand Up @@ -99,14 +101,14 @@ func GetUnderlyingWriter(out io.Writer) io.Writer {

// WithEventContext will return a new skaffoldWriter with the given parameters to be used for the event writer.
// If the passed io.Writer is not a skaffoldWriter, then it is simply returned.
func WithEventContext(out io.Writer, phase constants.Phase, subtaskID string) io.Writer {
func WithEventContext(out io.Writer, phase constants.Phase, subtaskID string) (io.Writer, *logrus.Logger) {
if sw, isSW := out.(skaffoldWriter); isSW {
return skaffoldWriter{
MainWriter: sw.MainWriter,
EventWriter: eventV2.NewLogger(phase, subtaskID),
timestamps: sw.timestamps,
}
}, nil
}

return out
return out, nil
}
2 changes: 1 addition & 1 deletion pkg/skaffold/output/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func TestWithEventContext(t *testing.T) {

for _, test := range tests {
testutil.Run(t, test.name, func(t *testutil.T) {
got := WithEventContext(test.writer, test.phase, test.subtaskID)
got, _ := WithEventContext(test.writer, test.phase, test.subtaskID)
t.CheckDeepEqual(test.expected, got, cmpopts.IgnoreTypes(false))
})
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/skaffold/runner/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (r *Builder) GetBuilds() []graph.Artifact {
// Build builds a list of artifacts.
func (r *Builder) Build(ctx context.Context, out io.Writer, artifacts []*latestV1.Artifact) ([]graph.Artifact, error) {
eventV2.TaskInProgress(constants.Build, "Build containers")
out = output.WithEventContext(out, constants.Build, eventV2.SubtaskIDNone)
out, _ = output.WithEventContext(out, constants.Build, eventV2.SubtaskIDNone)

// Use tags directly from the Kubernetes manifests.
if r.runCtx.DigestSource() == NoneDigestSource {
Expand Down Expand Up @@ -172,7 +172,7 @@ func (r *Builder) imageTags(ctx context.Context, out io.Writer, artifacts []*lat

for i, artifact := range artifacts {
imageName := artifact.ImageName
out := output.WithEventContext(out, constants.Build, imageName)
out, _ := output.WithEventContext(out, constants.Build, imageName)
output.Default.Fprintf(out, " - %s -> ", imageName)

select {
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/runner/v1/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (r *SkaffoldRunner) Deploy(ctx context.Context, out io.Writer, artifacts []
}
defer r.deployer.GetStatusMonitor().Reset()

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

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

Expand Down