diff options
Diffstat (limited to 'context/context.go')
-rw-r--r-- | context/context.go | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/context/context.go b/context/context.go index 314fc3584545..262e8c948035 100644 --- a/context/context.go +++ b/context/context.go @@ -77,7 +77,7 @@ func LoadContext(filename string, explicitVars *[]string) (*Context, error) { ctx.BaseDir = path.Dir(filename) // Prepare the resource sets by resolving parents etc. - ctx.ResourceSets = flattenPrepareResourceSetPaths(&ctx.ResourceSets) + ctx.ResourceSets = flattenPrepareResourceSetPaths(&ctx.BaseDir, &ctx.ResourceSets) // Add variables explicitly specified on the command line ctx.ExplicitVars, err = loadExplicitVars(explicitVars) @@ -136,7 +136,7 @@ func (ctx *Context) loadImportedVariables() (map[string]interface{}, error) { // collections, i.e. resource sets that themselves have an additional 'include' field set. // Those will be regarded as a short-hand for including multiple resource sets from a subfolder. // See https://github.com/tazjin/kontemplate/issues/9 for more information. -func flattenPrepareResourceSetPaths(rs *[]ResourceSet) []ResourceSet { +func flattenPrepareResourceSetPaths(baseDir *string, rs *[]ResourceSet) []ResourceSet { flattened := make([]ResourceSet, 0) for _, r := range *rs { @@ -146,6 +146,12 @@ func flattenPrepareResourceSetPaths(rs *[]ResourceSet) []ResourceSet { r.Path = r.Name } + // Paths are made absolute by resolving them relative to the context base, + // unless absolute paths were specified. + if !path.IsAbs(r.Path) { + r.Path = path.Join(*baseDir, r.Path) + } + if len(r.Include) == 0 { flattened = append(flattened, r) } else { @@ -225,7 +231,7 @@ func loadDefaultValues(rs *ResourceSet, c *Context) *map[string]interface{} { var defaultVars map[string]interface{} for _, filename := range util.DefaultFilenames { - err := util.LoadData(path.Join(c.BaseDir, rs.Path, filename), &defaultVars) + err := util.LoadData(path.Join(rs.Path, filename), &defaultVars) if err == nil { return &defaultVars } |