diff --git a/main.go b/main.go index 212c071..58bbaa6 100644 --- a/main.go +++ b/main.go @@ -226,6 +226,7 @@ func main() { skipRenderKey := flag.String("skip-render-key", "do-not-render", "Key to not render") ignoreValueFile := flag.String("ignore-value-file", "overrides-to-ignore", "Override file to ignore based on filename") postRenderer := flag.String("post-renderer", "", "When provided, binary will be called after an application is rendered.") + debug := flag.Bool("debug", false, "When true provides additional logs.") flag.Parse() // Runs the command in the specified directory @@ -247,7 +248,7 @@ func main() { w := &Walker{ CopySource: CopySource, HelmTemplate: func(application *v1alpha1.Application, output string) error { - return helm.Run(application, output, *skipRenderKey, *ignoreValueFile) + return helm.Run(application, output, *skipRenderKey, *ignoreValueFile, *debug) }, GenerateHash: func(application *v1alpha1.Application) (string, error) { return helm.GenerateHash(application, *ignoreValueFile) diff --git a/pkg/helm/helm.go b/pkg/helm/helm.go index 86f4a77..b1d0f94 100644 --- a/pkg/helm/helm.go +++ b/pkg/helm/helm.go @@ -101,7 +101,7 @@ func installDependencies(chartDirectory string) error { } -func template(helmInfo *v1alpha1.Application, skipRenderKey string, ignoreValueFile string) ([]byte, error) { +func template(helmInfo *v1alpha1.Application, skipRenderKey string, ignoreValueFile string, debug bool) ([]byte, error) { chartPath := strings.Split(helmInfo.Spec.Source.Path, "/") chart := fmt.Sprint("../" + chartPath[len(chartPath)-1]) @@ -118,8 +118,7 @@ func template(helmInfo *v1alpha1.Application, skipRenderKey string, ignoreValueF tmpFile = dataFile } - cmd := exec.Command( - "helm", + args := []string{ "template", chart, "--set", @@ -130,7 +129,13 @@ func template(helmInfo *v1alpha1.Application, skipRenderKey string, ignoreValueF tmpFile, "-n", helmInfo.Spec.Destination.Namespace, - ) + } + + if debug { + args = append(args, "--debug") + } + + cmd := exec.Command("helm", args...) if skipRenderKey != "" { cmd.Args = append(cmd.Args, "--set", fmt.Sprintf("%s=%s", skipRenderKey, "CONSCIOUSLY_NOT_RENDERED")) @@ -393,8 +398,8 @@ func generateHashOnCrd(crd *v1alpha1.Application) (string, error) { return hex.EncodeToString(sum), nil } -func Run(crd *v1alpha1.Application, output string, skipRenderKey string, ignoreValueFile string) error { - manifest, err := template(crd, skipRenderKey, ignoreValueFile) +func Run(crd *v1alpha1.Application, output string, skipRenderKey string, ignoreValueFile string, debug bool) error { + manifest, err := template(crd, skipRenderKey, ignoreValueFile, debug) if err != nil { log.Printf( "error generating manifest for %s error: %v\n", diff --git a/pkg/helm/helm_test.go b/pkg/helm/helm_test.go index ed7ee7c..620bc85 100644 --- a/pkg/helm/helm_test.go +++ b/pkg/helm/helm_test.go @@ -142,13 +142,30 @@ func TestTemplate(t *testing.T) { if err := os.Chdir("../../"); err != nil { t.Error(err) } - _, err = template(crdSpec, "", "") + _, err = template(crdSpec, "", "", false) if err != nil { log.Println(err) t.Error("Template failed to render a template") } } +func TestTemplateWithDebug(t *testing.T) { + data, err := Read("test_files/crdData_testfile.yaml") + if err != nil { + t.Error(err) + } + crdSpec := data[0] + if err := os.Chdir("../../"); err != nil { + t.Error(err) + } + + _, err = template(crdSpec, "", "", true) + if err != nil { + log.Println(err) + t.Error("Template failed to render a template with debug") + } +} + func TestTemplateContent(t *testing.T) { data, err := Read("pkg/helm/test_files/crdData_testfile.yaml") if err != nil { @@ -162,7 +179,7 @@ apiVersion: argoproj.io/v1alpha1 kind: Application ` - manifest, _ := template(crdSpec, "", "") + manifest, _ := template(crdSpec, "", "", false) if strings.Contains(string(manifest), comparisonString) != true { t.Error("Template failed to render a template with expected content") } @@ -176,7 +193,7 @@ func TestTemplateContentSkipRenderKey(t *testing.T) { app := data[0] // Call template with a key to override - manifest, _ := template(app, "appTag", "") + manifest, _ := template(app, "appTag", "", false) // Verify the rendered manifest contains the override if !strings.Contains(string(manifest), "appTag: CONSCIOUSLY_NOT_RENDERED") {