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

Refactor to use new SkaffoldWriter type #5894

Merged

Conversation

MarlonGamez
Copy link
Contributor

@MarlonGamez MarlonGamez commented May 21, 2021

Related: #5370

Description
Introduces a new type, SkaffoldWriter. This replaces colorableWriter as the top level io.Writer type used by skaffold. It holds one main writer, which will most commonly be a colorableWriter, and a secondary writer, which will be used to write output out as events through skaffold API V2. The case for using this over io.MultiWriter is that this will allow us to implement functions that perform manipulations on the underlying writers that will be necessary for future implementation of API V2.

Follow-up Work (remove if N/A)
Implement event writer type and use in this struct.

@MarlonGamez MarlonGamez requested a review from a team as a code owner May 21, 2021 21:57
@MarlonGamez MarlonGamez requested a review from tejal29 May 21, 2021 21:57
@google-cla google-cla bot added the cla: yes label May 21, 2021
@sampath
Copy link

sampath commented May 21, 2021

great PR! Can't wait for API v2!

@codecov
Copy link

codecov bot commented May 21, 2021

Codecov Report

Merging #5894 (bbdbd67) into master (efabcc0) will decrease coverage by 0.06%.
The diff coverage is 71.42%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5894      +/-   ##
==========================================
- Coverage   70.90%   70.84%   -0.07%     
==========================================
  Files         447      452       +5     
  Lines       16909    17321     +412     
==========================================
+ Hits        11990    12271     +281     
- Misses       4029     4146     +117     
- Partials      890      904      +14     
Impacted Files Coverage Δ
cmd/skaffold/skaffold.go 0.00% <0.00%> (ø)
pkg/skaffold/build/result.go 83.33% <0.00%> (ø)
pkg/skaffold/output/color.go 90.90% <50.00%> (-5.10%) ⬇️
pkg/skaffold/output/output.go 76.92% <76.92%> (ø)
cmd/skaffold/app/cmd/cmd.go 68.39% <100.00%> (ø)
pkg/skaffold/build/buildpacks/lifecycle.go 82.35% <100.00%> (ø)
pkg/skaffold/build/docker/docker.go 84.61% <100.00%> (+1.63%) ⬆️
pkg/skaffold/instrumentation/export.go 63.45% <0.00%> (-9.66%) ⬇️
pkg/skaffold/build/gcb/docker.go 82.60% <0.00%> (-5.28%) ⬇️
pkg/skaffold/build/cache/retrieve.go 61.81% <0.00%> (-3.81%) ⬇️
... and 33 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update efabcc0...bbdbd67. Read the comment docs.

Comment on lines 36 to 38
if n < len(p) {
return n, io.ErrShortWrite
}
Copy link
Member

Choose a reason for hiding this comment

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

So n < |p| isn't an error: it happens pretty often when writing to a network stream.

Copy link
Contributor Author

@MarlonGamez MarlonGamez May 26, 2021

Choose a reason for hiding this comment

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

Do you think I should be handling this case at all then? ErrShortWrite means that a write accepted fewer bytes than requested but failed to return an explicit error. according to docs, so I thought I should handle it. It seems that most standard lib writers handle this case in the same way (although with !=, not <). If you think I shouldn't handle the case, i'll remove it, but if otherwise I'll change the condition to match the standard lib

pkg/skaffold/output/output.go Outdated Show resolved Hide resolved
pkg/skaffold/output/output.go Outdated Show resolved Hide resolved
pkg/skaffold/output/output.go Outdated Show resolved Hide resolved
pkg/skaffold/output/output_test.go Show resolved Hide resolved
pkg/skaffold/output/output_test.go Show resolved Hide resolved
@MarlonGamez MarlonGamez enabled auto-merge (squash) May 26, 2021 22:34
@@ -91,7 +91,7 @@ func (b *Builder) build(ctx context.Context, out io.Writer, a *latestV1.Artifact

builderImage, runImage, pullPolicy := resolveDependencyImages(artifact, b.artifacts, a.Dependencies, b.pushImages)

if err := runPackBuildFunc(ctx, output.GetWriter(out), b.localDocker, pack.BuildOptions{
if err := runPackBuildFunc(ctx, output.GetUnderlyingWriter(out), b.localDocker, pack.BuildOptions{
Copy link
Member

Choose a reason for hiding this comment

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

So doesn't this mean the output from this command won't go through our event logging?

Maybe we do this if there is no event writer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was actually curious as to why we did this, and was going to address this in a follow up, as I believe we should be able to use our writer here. I'll probably need to make some more changes to the output setup that's happening in these functions

Copy link
Member

Choose a reason for hiding this comment

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

The other thing to look at is the https://github.com/creack/pty package

pkg/skaffold/output/output.go Show resolved Hide resolved
@@ -48,7 +48,7 @@ func (b *Builder) Build(ctx context.Context, out io.Writer, a *latestV1.Artifact
var imageID string

if b.useCLI || b.useBuildKit {
imageID, err = b.dockerCLIBuild(ctx, output.GetWriter(out), a.Workspace, dockerfile, a.ArtifactType.DockerArtifact, opts)
imageID, err = b.dockerCLIBuild(ctx, output.GetUnderlyingWriter(out), a.Workspace, dockerfile, a.ArtifactType.DockerArtifact, opts)
Copy link
Member

Choose a reason for hiding this comment

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

Same as the pack run case

@MarlonGamez MarlonGamez merged commit 642ed91 into GoogleContainerTools:master Jun 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants