4
4
"fmt"
5
5
"io"
6
6
"os"
7
+ "os/exec"
7
8
"path/filepath"
8
9
"strings"
9
10
@@ -79,16 +80,20 @@ func TemplateCmd() *cobra.Command {
79
80
if err != nil {
80
81
return errors .Wrap (err , "failed to render raw template" )
81
82
}
82
- fmt . Println (rendered )
83
+ log . Info (rendered )
83
84
return nil
84
85
}
85
86
86
87
// render all mode, similar to helm template
87
88
// we will utilize pull command to fetch and render manifests from upstream
89
+ log .ActionWithSpinner ("Pulling app from upstream and rendering templates..." )
88
90
err := pullAndRender (license .Spec .AppSlug , licenseFile , configFile )
91
+ log .FinishSpinner ()
92
+
89
93
if err != nil {
90
94
return errors .Wrap (err , "failed to render all templates" )
91
95
}
96
+
92
97
return nil
93
98
}
94
99
@@ -118,7 +123,7 @@ func TemplateCmd() *cobra.Command {
118
123
return errors .Wrap (err , "failed to render template" )
119
124
}
120
125
121
- fmt . Print (rendered )
126
+ log . Info (rendered )
122
127
123
128
return nil
124
129
},
@@ -272,7 +277,7 @@ func pullAndRender(appSlug string, licensePath string, configPath string) error
272
277
return errors .Wrap (err , "failed to read kotsKinds directory" )
273
278
}
274
279
275
- var manifetsToRender [ ]string
280
+ manifetsToRender := make ( map [ string ]string )
276
281
for _ , file := range files {
277
282
if file .IsDir () {
278
283
continue
@@ -281,10 +286,53 @@ func pullAndRender(appSlug string, licensePath string, configPath string) error
281
286
if err != nil {
282
287
return errors .Wrap (err , "failed to read file" )
283
288
}
284
- manifetsToRender = append (manifetsToRender , string (content ))
289
+ manifetsToRender [file .Name ()] = string (content )
290
+ }
291
+ for k , m := range manifetsToRender {
292
+ fmt .Println ("---" )
293
+ fmt .Printf ("# Source: %s\n " , k )
294
+ fmt .Println (m )
285
295
}
286
- for _ , m := range manifetsToRender {
287
- fmt .Printf ("---\n %s\n " , m )
296
+
297
+ // also render helm charts with helm template if any
298
+ helmChartsDir := filepath .Join (tempDir , "helm" )
299
+ if _ , err := os .Stat (helmChartsDir ); err == nil {
300
+ var chartPath string
301
+ var valuesPath string
302
+
303
+ err := filepath .Walk (helmChartsDir , func (path string , info os.FileInfo , err error ) error {
304
+ if err != nil {
305
+ return err
306
+ }
307
+
308
+ if info .IsDir () {
309
+ return nil
310
+ }
311
+
312
+ if filepath .Ext (path ) == ".tgz" {
313
+ chartPath = path
314
+ }
315
+
316
+ if info .Name () == "values.yaml" {
317
+ valuesPath = path
318
+ }
319
+
320
+ return nil
321
+ })
322
+
323
+ if err != nil {
324
+ return errors .Wrap (err , "failed to walk helm charts directory" )
325
+ }
326
+
327
+ if chartPath != "" && valuesPath != "" {
328
+ args := []string {"template" , "tmp-release" , chartPath , "--values" , valuesPath }
329
+ cmd := exec .Command ("helm" , args ... )
330
+ output , err := cmd .CombinedOutput ()
331
+ if err != nil {
332
+ return errors .Wrap (err , "failed to run helm template" )
333
+ }
334
+ fmt .Println (string (output ))
335
+ }
288
336
}
289
337
290
338
return nil
0 commit comments