bug: fixes bug with error out with using kompose convert with no -f (#1725)

#### What type of PR is this?

<!--
Add one of the following kinds:
/kind cleanup
/kind documentation
/kind feature
-->

/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:
<!--
*Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
-->

Closes https://github.com/kubernetes/kompose/issues/1719

#### Special notes for your reviewer:

Signed-off-by: Charlie Drage <charlie@charliedrage.com>
This commit is contained in:
Charlie Drage
2023-10-06 13:34:44 -04:00
committed by GitHub
parent a04ecdb9e8
commit c0e0393bbd
2 changed files with 9 additions and 4 deletions
+3 -3
View File
@@ -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
}