Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keep consistent on result dir #2162

Merged
merged 4 commits into from
Jun 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 3 additions & 6 deletions internal/cmdrender/cmd.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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