Skip to content

Commit

Permalink
keep consistent on result dir (#2162)
Browse files Browse the repository at this point in the history
* keep consistent on result dir

* update reference
  • Loading branch information
Shell32-Natsu committed Jun 5, 2021
1 parent 7d765c3 commit 312cba6
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 24 deletions.
9 changes: 3 additions & 6 deletions internal/cmdrender/cmd.go
Expand Up @@ -23,7 +23,6 @@ import (
"os"

docs "github.com/GoogleContainerTools/kpt/internal/docs/generated/fndocs"
"github.com/GoogleContainerTools/kpt/internal/errors"
"github.com/GoogleContainerTools/kpt/internal/util/cmdutil"
"github.com/GoogleContainerTools/kpt/internal/util/pkgutil"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -79,11 +78,9 @@ func (r *Runner) preRunE(c *cobra.Command, args []string) error {
r.pkgPath = args[0]
}
if r.resultsDirPath != "" {
if _, err := os.Stat(r.resultsDirPath); err != nil {
if errors.Is(err, os.ErrNotExist) {
return fmt.Errorf("results-dir %q must exist", r.resultsDirPath)
}
return fmt.Errorf("results-dir %q check failed: %w", r.resultsDirPath, err)
err := os.MkdirAll(r.resultsDirPath, 0755)
if err != nil {
return fmt.Errorf("cannot read or create results dir %q: %w", r.resultsDirPath, err)
}
}
return cmdutil.ValidateImagePullPolicyValue(r.imagePullPolicy)
Expand Down
8 changes: 4 additions & 4 deletions internal/docs/generated/fndocs/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions pkg/test/runner/runner.go
Expand Up @@ -141,12 +141,7 @@ func (r *Runner) runFnEval() error {
var resultsDir, destDir string

if r.IsFnResultExpected() {
// create result dir
resultsDir = filepath.Join(tmpDir, "results")
err = os.Mkdir(resultsDir, 0755)
if err != nil {
return fmt.Errorf("failed to create results dir %s: %w", resultsDir, err)
}
}

if r.IsOutOfPlace() {
Expand Down Expand Up @@ -281,12 +276,7 @@ func (r *Runner) runFnRender() error {
var resultsDir, destDir string

if r.IsFnResultExpected() {
// create result dir
resultsDir = filepath.Join(tmpDir, "results")
err = os.Mkdir(resultsDir, 0755)
if err != nil {
return fmt.Errorf("failed to create results dir %s: %w", resultsDir, err)
}
}

if r.IsOutOfPlace() {
Expand Down
4 changes: 2 additions & 2 deletions site/reference/cli/fn/eval/README.md
Expand Up @@ -114,8 +114,8 @@ fn-args:
3. OUT_DIR_PATH: output resources are written to provided directory, the directory is created if it doesn't already exist.
--results-dir:
Path to a directory to write structured results. Directory must exist.
Structured results emitted by the functions are aggregated and saved
Path to a directory to write structured results. Directory will be created if
it doesn't exist. Structured results emitted by the functions are aggregated and saved
to `results.yaml` file in the specified directory.
If not specified, no result files are written to the local filesystem.
```
Expand Down
4 changes: 2 additions & 2 deletions site/reference/cli/fn/render/README.md
Expand Up @@ -62,8 +62,8 @@ PKG_PATH:
3. OUT_DIR_PATH: output resources are written to provided directory, the directory is created if it doesn't already exist.
--results-dir:
Path to a directory to write structured results. Directory must exist.
Structured results emitted by the functions are aggregated and saved
Path to a directory to write structured results. Directory will be created if
it doesn't exist. Structured results emitted by the functions are aggregated and saved
to `results.yaml` file in the specified directory.
If not specified, no result files are written to the local filesystem.
```
Expand Down
6 changes: 6 additions & 0 deletions thirdparty/cmdconfig/commands/cmdeval/cmdeval.go
Expand Up @@ -236,6 +236,12 @@ func (r *EvalFnRunner) preRunE(c *cobra.Command, args []string) error {
if err := cmdutil.ValidateImagePullPolicyValue(r.ImagePullPolicy); err != nil {
return err
}
if r.ResultsDir != "" {
err := os.MkdirAll(r.ResultsDir, 0755)
if err != nil {
return fmt.Errorf("cannot read or create results dir %q: %w", r.ResultsDir, err)
}
}
var dataItems []string
if c.ArgsLenAtDash() >= 0 {
dataItems = append(dataItems, args[c.ArgsLenAtDash():]...)
Expand Down

0 comments on commit 312cba6

Please sign in to comment.