Skip to content

Commit

Permalink
Fix render not fully overwriting output files (#4323)
Browse files Browse the repository at this point in the history
If the output file already existed, it was not being truncated to the
new output. If the existing content was larger than the new output, the
remainder of the existing output was left in the file corrupting the
contents.
  • Loading branch information
alewis001 committed Jun 17, 2020
1 parent e0f949b commit 6f2e834
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 14 deletions.
14 changes: 1 addition & 13 deletions pkg/skaffold/deploy/kustomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,19 +210,7 @@ func (k *KustomizeDeployer) Render(ctx context.Context, out io.Writer, builds []
return err
}

manifestOut := out
if filepath != "" {
f, err := os.OpenFile(filepath, os.O_RDWR|os.O_CREATE, 0666)
if err != nil {
return fmt.Errorf("opening file for writing manifests: %w", err)
}
defer f.Close()
f.WriteString(manifests.String() + "\n")
return nil
}

fmt.Fprintln(manifestOut, manifests.String())
return nil
return outputRenderedManifests(manifests.String(), filepath, out)
}

// UnmarshalYAML implements JSON unmarshalling by reading an inline yaml fragment.
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/deploy/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func outputRenderedManifests(renderedManifests string, output string, manifestOu
}

func dumpToFile(renderedManifests string, filepath string) error {
f, err := os.OpenFile(filepath, os.O_RDWR|os.O_CREATE, 0666)
f, err := os.Create(filepath)
if err != nil {
return fmt.Errorf("opening file for writing manifests: %w", err)
}
Expand Down

0 comments on commit 6f2e834

Please sign in to comment.