From 9517886b297a9536ec96e66cddd862806a732238 Mon Sep 17 00:00:00 2001 From: Gerard Nguyen Date: Mon, 8 Apr 2024 13:18:50 +1000 Subject: [PATCH] print manifests in rendered directory as well --- cmd/kots/cli/template.go | 49 +++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/cmd/kots/cli/template.go b/cmd/kots/cli/template.go index 31ce2490b0..b6957b6a84 100644 --- a/cmd/kots/cli/template.go +++ b/cmd/kots/cli/template.go @@ -87,9 +87,8 @@ func TemplateCmd() *cobra.Command { // render all mode, similar to helm template // we will utilize pull command to fetch and render manifests from upstream - log.ActionWithSpinner("Pulling app from upstream and rendering templates...") + log.Info("Pulling app from upstream and rendering templates...") err := pullAndRender(license.Spec.AppSlug, licenseFile, configFile, localPath) - log.FinishSpinner() if err != nil { return errors.Wrap(err, "failed to render all templates") @@ -264,6 +263,7 @@ func pullAndRender(appSlug string, licensePath string, configPath string, localP Silent: true, ExcludeAdminConsole: true, LocalPath: ExpandDir(localPath), + Downstreams: []string{"this-cluster"}, } upstream := pull.RewriteUpstream(appSlug) @@ -273,25 +273,41 @@ func pullAndRender(appSlug string, licensePath string, configPath string, localP return errors.Wrap(err, "failed to pull upstream") } - // iterate over kotsKinds directory in tempDir and print all YAML contents + // iterate over kotsKinds + rendered directory in tempDir and print all YAML contents kotsKindsDir := filepath.Join(tempDir, "kotsKinds") - files, err := os.ReadDir(kotsKindsDir) - if err != nil { - return errors.Wrap(err, "failed to read kotsKinds directory") - } + renderedDir := filepath.Join(tempDir, "rendered") + dirs := []string{kotsKindsDir, renderedDir} - manifetsToRender := make(map[string]string) - for _, file := range files { - if file.IsDir() { - continue - } - content, err := os.ReadFile(filepath.Join(kotsKindsDir, file.Name())) + manifestsToRender := make(map[string]string) + + for _, dir := range dirs { + err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + if info.IsDir() { + return nil + } + + // ignore kotsadm- manifests + if strings.HasPrefix(info.Name(), "kotsadm-") { + return nil + } + + content, err := os.ReadFile(path) + if err != nil { + return errors.Wrap(err, "failed to read file") + } + manifestsToRender[info.Name()] = string(content) + + return nil + }) if err != nil { - return errors.Wrap(err, "failed to read file") + return errors.Wrap(err, "failed to walk directory to render manifests") } - manifetsToRender[file.Name()] = string(content) } - for k, m := range manifetsToRender { + + for k, m := range manifestsToRender { fmt.Println("---") fmt.Printf("# Source: %s\n", k) fmt.Println(m) @@ -300,6 +316,7 @@ func pullAndRender(appSlug string, licensePath string, configPath string, localP // also render helm charts with helm template if any helmChartsDir := filepath.Join(tempDir, "helm") if _, err := os.Stat(helmChartsDir); err == nil { + logger.Info("Rendering Helm charts with helm template...") var chartPath string var valuesPath string