From c0e0393bbd6a9adf60a449d6c3bf982937340432 Mon Sep 17 00:00:00 2001 From: Charlie Drage Date: Fri, 6 Oct 2023 13:34:44 -0400 Subject: [PATCH] bug: fixes bug with error out with using kompose convert with no -f (#1725) #### What type of PR is this? /kind bug Fixes a validation bug where if you do not provide a compose.yaml or docker-compose.yaml it will nil point error out rather than have an appropriate "file not found" output. #### Which issue(s) this PR fixes: Closes https://github.com/kubernetes/kompose/issues/1719 #### Special notes for your reviewer: Signed-off-by: Charlie Drage --- cmd/convert.go | 7 ++++++- pkg/app/app.go | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cmd/convert.go b/cmd/convert.go index 898227bc..f9d6d867 100644 --- a/cmd/convert.go +++ b/cmd/convert.go @@ -133,7 +133,12 @@ var convertCmd = &cobra.Command{ } app.ValidateFlags(args, cmd, &ConvertOpt) - app.ValidateComposeFile(&ConvertOpt) + + // Since ValidateComposeFiles returns an error, let's validate it and output the error appropriately if the validation fails + err := app.ValidateComposeFile(&ConvertOpt) + if err != nil { + log.Fatalf("Error validating compose file: %v", err) + } }, Run: func(cmd *cobra.Command, args []string) { diff --git a/pkg/app/app.go b/pkg/app/app.go index 918f66f9..ab3de927 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -146,18 +146,18 @@ func ValidateFlags(args []string, cmd *cobra.Command, opt *kobject.ConvertOption // ValidateComposeFile validates the compose file provided for conversion func ValidateComposeFile(opt *kobject.ConvertOptions) error { if len(opt.InputFiles) == 0 { + // Go through a range of "default" file names to see if tany ofthem exist in the current directory for _, name := range DefaultComposeFiles { _, err := os.Stat(name) if err != nil { log.Debugf("'%s' not found: %v", name, err) - return err } else { opt.InputFiles = []string{name} return nil } } - - log.Fatal("No 'docker-compose' file found") + // Return an error message that no compose or docker-compose yaml files were found + return fmt.Errorf("No compose or docker-compose yaml file found in the current directory") } return nil }