Skip to content

Commit 9517886

Browse files
committed
print manifests in rendered directory as well
1 parent cef2eda commit 9517886

File tree

1 file changed

+33
-16
lines changed

1 file changed

+33
-16
lines changed

cmd/kots/cli/template.go

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,8 @@ func TemplateCmd() *cobra.Command {
8787

8888
// render all mode, similar to helm template
8989
// we will utilize pull command to fetch and render manifests from upstream
90-
log.ActionWithSpinner("Pulling app from upstream and rendering templates...")
90+
log.Info("Pulling app from upstream and rendering templates...")
9191
err := pullAndRender(license.Spec.AppSlug, licenseFile, configFile, localPath)
92-
log.FinishSpinner()
9392

9493
if err != nil {
9594
return errors.Wrap(err, "failed to render all templates")
@@ -264,6 +263,7 @@ func pullAndRender(appSlug string, licensePath string, configPath string, localP
264263
Silent: true,
265264
ExcludeAdminConsole: true,
266265
LocalPath: ExpandDir(localPath),
266+
Downstreams: []string{"this-cluster"},
267267
}
268268

269269
upstream := pull.RewriteUpstream(appSlug)
@@ -273,25 +273,41 @@ func pullAndRender(appSlug string, licensePath string, configPath string, localP
273273
return errors.Wrap(err, "failed to pull upstream")
274274
}
275275

276-
// iterate over kotsKinds directory in tempDir and print all YAML contents
276+
// iterate over kotsKinds + rendered directory in tempDir and print all YAML contents
277277
kotsKindsDir := filepath.Join(tempDir, "kotsKinds")
278-
files, err := os.ReadDir(kotsKindsDir)
279-
if err != nil {
280-
return errors.Wrap(err, "failed to read kotsKinds directory")
281-
}
278+
renderedDir := filepath.Join(tempDir, "rendered")
279+
dirs := []string{kotsKindsDir, renderedDir}
282280

283-
manifetsToRender := make(map[string]string)
284-
for _, file := range files {
285-
if file.IsDir() {
286-
continue
287-
}
288-
content, err := os.ReadFile(filepath.Join(kotsKindsDir, file.Name()))
281+
manifestsToRender := make(map[string]string)
282+
283+
for _, dir := range dirs {
284+
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
285+
if err != nil {
286+
return err
287+
}
288+
if info.IsDir() {
289+
return nil
290+
}
291+
292+
// ignore kotsadm- manifests
293+
if strings.HasPrefix(info.Name(), "kotsadm-") {
294+
return nil
295+
}
296+
297+
content, err := os.ReadFile(path)
298+
if err != nil {
299+
return errors.Wrap(err, "failed to read file")
300+
}
301+
manifestsToRender[info.Name()] = string(content)
302+
303+
return nil
304+
})
289305
if err != nil {
290-
return errors.Wrap(err, "failed to read file")
306+
return errors.Wrap(err, "failed to walk directory to render manifests")
291307
}
292-
manifetsToRender[file.Name()] = string(content)
293308
}
294-
for k, m := range manifetsToRender {
309+
310+
for k, m := range manifestsToRender {
295311
fmt.Println("---")
296312
fmt.Printf("# Source: %s\n", k)
297313
fmt.Println(m)
@@ -300,6 +316,7 @@ func pullAndRender(appSlug string, licensePath string, configPath string, localP
300316
// also render helm charts with helm template if any
301317
helmChartsDir := filepath.Join(tempDir, "helm")
302318
if _, err := os.Stat(helmChartsDir); err == nil {
319+
logger.Info("Rendering Helm charts with helm template...")
303320
var chartPath string
304321
var valuesPath string
305322

0 commit comments

Comments
 (0)