Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we could add a way (this or other PR) to pass this and any other additional arguments to Helm, something like additionalArgs="--debug --other=x" 🤷

BTW, you could also set HELM_DEBUG to enable debugging 🤷

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, two great points!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@d1egoaz - I'll work on getting additionalHelmArgs added 👍

flag.Parse()

// Runs the command in the specified directory
Expand All @@ -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)
Expand Down
17 changes: 11 additions & 6 deletions pkg/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) ([]byte, debug bool, error) {

chartPath := strings.Split(helmInfo.Spec.Source.Path, "/")
chart := fmt.Sprint("../" + chartPath[len(chartPath)-1])
Expand All @@ -118,8 +118,7 @@ func template(helmInfo *v1alpha1.Application, skipRenderKey string, ignoreValueF
tmpFile = dataFile
}

cmd := exec.Command(
"helm",
args := []string{
"template",
chart,
"--set",
Expand All @@ -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"))
Expand Down Expand Up @@ -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",
Expand Down
21 changes: 21 additions & 0 deletions pkg/helm/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,27 @@ func TestTemplate(t *testing.T) {
}
}

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)
}

manifest, err := template(crdSpec, "", "", true)
if err != nil {
log.Println(err)
t.Error("Template failed to render a template with debug")
}

if !strings.Contains(string(manifest), "---\n# Source:") {
t.Error("Expected debug information not found in rendered manifest")
}
}

func TestTemplateContent(t *testing.T) {
data, err := Read("pkg/helm/test_files/crdData_testfile.yaml")
if err != nil {
Expand Down