Skip to content
This repository has been archived by the owner on Dec 21, 2019. It is now read-only.

Commit

Permalink
fix templater: Insert additional resource separators
Browse files Browse the repository at this point in the history
In cases where users have multiple resource sets, or a single resource
set that contains multiple YAML files they may run into issues if they
forget to start their resource files with `---`.

This fix inserts an additional `---` at the beginning of each YAML
template.

In cases where the user started their file YAML file "properly" this
will result in an empty resource being templated / passed to kubectl,
however that does not seem to cause any issues.

This fixes #51
  • Loading branch information
tazjin committed May 23, 2017
1 parent 9923b1e commit 8ce1bb2
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions templater/templater.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ func templateFile(c *context.Context, rs *context.ResourceSet, filename string)
}

var b bytes.Buffer
// For YAML-formatted templates an additional resource separator ('---') will be inserted at the beginning
// of the YAML file.
// This prevents an error-case in which resources spread out over multiple files may not be recognised as such
// if the user forgets to insert a separator manually.
if strings.HasSuffix(filename, "yaml") || strings.HasSuffix(filename, "yml") {
b.WriteString("---\n")
}

rs.Values = *util.Merge(&c.Global, &rs.Values)

Expand Down

0 comments on commit 8ce1bb2

Please sign in to comment.