@@ -171,8 +171,8 @@ func (o *generateOptions) run(out io.Writer) error {
171171 ExcludeGlob : []string {"*" , "!*.gomplateignore_template" },
172172 LDelim : "{{<" ,
173173 RDelim : ">}}" ,
174- DataSources : o .gomplateDataSources (defaultValuesPath ),
175- Contexts : o .gomplateContexts (),
174+ DataSources : o .gomplateDataSources (),
175+ Contexts : o .gomplateContexts (defaultValuesPath ),
176176 Templates : o .gomplateTemplates (helpersPath ),
177177 SuppressEmpty : true ,
178178 }
@@ -211,8 +211,8 @@ func (o *generateOptions) run(out io.Writer) error {
211211 OutputDir : o .outputDir ,
212212 LDelim : "{{<" ,
213213 RDelim : ">}}" ,
214- DataSources : o .gomplateDataSources (defaultValuesPath ),
215- Contexts : o .gomplateContexts (),
214+ DataSources : o .gomplateDataSources (),
215+ Contexts : o .gomplateContexts (defaultValuesPath ),
216216 Templates : o .gomplateTemplates (helpersPath ),
217217 SuppressEmpty : true ,
218218 }
@@ -228,43 +228,48 @@ func (o *generateOptions) run(out io.Writer) error {
228228}
229229
230230// build the `DataSources` for our `gomplate.Config`
231- func (o * generateOptions ) gomplateDataSources (defaultValuesPath string ) []string {
231+ func (o * generateOptions ) gomplateDataSources () []string {
232232
233233 // create DataSource for each `--values` provided by the user
234234 values := o .values
235- dataSources := make ([]string , len (values )+ 1 )
235+ dataSources := make ([]string , len (values ))
236236 for i , v := range values {
237237 dataSources [i ] = "Values_" + strconv .Itoa (i ) + "=" + v
238238 }
239239
240- // create DataSource for the default values
241- dataSources [len (dataSources )- 1 ] = "Values_default=" + defaultValuesPath
242-
243240 return dataSources
244241}
245242
246243// build the `Contexts` for our `gomplate.Config`
247- func (o * generateOptions ) gomplateContexts () []string {
244+ func (o * generateOptions ) gomplateContexts (defaultValuesPath string ) []string {
248245 var sb strings.Builder
249- sb .WriteString ("Values=merge:" )
250246
251- // add the DataSources for any user provided `--values` to the merge
247+ // merge the user-provided `--values` DataSources by placing a "|" between them
248+ // NOTE: merges happen from right to left, so we add the `--values` in reverse
249+ // order so the `--values` that were provided later take precedence
252250 values := o .values
253- for i := range values {
254- if i > 0 {
251+ for i := len ( values ) - 1 ; i >= 0 ; i -- {
252+ if sb . Len () > 0 {
255253 sb .WriteString ("|" )
256254 }
257255 sb .WriteString ("Values_" )
258256 sb .WriteString (strconv .Itoa (i ))
259257 }
260258
261- // add the DataSource for the default values to the merge
262- if len ( values ) > 0 {
259+ // add the `default_values.yaml` to the end of the merge
260+ if sb . Len ( ) > 0 {
263261 sb .WriteString ("|" )
264262 }
265- sb .WriteString ("Values_default" )
263+ sb .WriteString (defaultValuesPath )
264+
265+ // we only use `merge` if there is more than one DataSource
266+ valuesContext := "Values="
267+ if len (values ) > 0 {
268+ valuesContext += "merge:"
269+ }
270+ valuesContext += sb .String ()
266271
267- return []string {sb . String () }
272+ return []string {valuesContext }
268273}
269274
270275// build the `Templates` for our `gomplate.Config`
0 commit comments