From f4e92a09c53d836fb7ae6b987947ae263e2096db Mon Sep 17 00:00:00 2001 From: Eric Stroczynski Date: Tue, 2 Apr 2019 15:08:39 -0700 Subject: [PATCH] Backport: commands/.../generate: verbose codegen by default (#1271) (#1279) * cmd/.../genutil: verbose codegen by default * test/e2e: remove explicit setting of verbosity * CHANGELOG.md: add generate verbosity change --- CHANGELOG.md | 2 ++ .../cmd/generate/internal/genutil.go | 1 + commands/operator-sdk/cmd/generate/k8s.go | 19 ++----------------- commands/operator-sdk/cmd/generate/openapi.go | 9 +-------- test/e2e/memcached_test.go | 4 ---- 5 files changed, 6 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a26b5cba446..a11a8715d47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ### Changed +- Subcommands of [`operator-sdk generate`](https://github.com/operator-framework/operator-sdk/blob/master/doc/sdk-cli-reference.md#generate) are now verbose by default. ([#1271](https://github.com/operator-framework/operator-sdk/pull/1271)) + ### Deprecated ### Removed diff --git a/commands/operator-sdk/cmd/generate/internal/genutil.go b/commands/operator-sdk/cmd/generate/internal/genutil.go index a98aadd5489..ec9b6c1a1f7 100644 --- a/commands/operator-sdk/cmd/generate/internal/genutil.go +++ b/commands/operator-sdk/cmd/generate/internal/genutil.go @@ -44,6 +44,7 @@ func runGoBuildCodegen(binDir, repoDir, genDir string) error { cmd.Env = append(os.Environ(), projutil.GoFlagsEnv+"="+gf) } + // Only print binary build info if verbosity is explicitly set. if projutil.IsGoVerbose() { return projutil.ExecCmd(cmd) } diff --git a/commands/operator-sdk/cmd/generate/k8s.go b/commands/operator-sdk/cmd/generate/k8s.go index bb965c8180b..1dca76e271c 100644 --- a/commands/operator-sdk/cmd/generate/k8s.go +++ b/commands/operator-sdk/cmd/generate/k8s.go @@ -16,7 +16,6 @@ package generate import ( "fmt" - "io/ioutil" "os/exec" "path/filepath" "strings" @@ -118,14 +117,7 @@ func deepcopyGen(binDir, repoPkg string, gvMap map[string][]string) (err error) "--bounding-dirs", apisPkg, } cmd := exec.Command(filepath.Join(binDir, "deepcopy-gen"), args...) - if projutil.IsGoVerbose() { - err = projutil.ExecCmd(cmd) - } else { - cmd.Stdout = ioutil.Discard - cmd.Stderr = ioutil.Discard - err = cmd.Run() - } - if err != nil { + if err = projutil.ExecCmd(cmd); err != nil { return fmt.Errorf("failed to perform deepcopy code-generation: %v", err) } return nil @@ -138,14 +130,7 @@ func defaulterGen(binDir, repoPkg string, gvMap map[string][]string) (err error) "--output-file-base", "zz_generated.defaults", } cmd := exec.Command(filepath.Join(binDir, "defaulter-gen"), args...) - if projutil.IsGoVerbose() { - err = projutil.ExecCmd(cmd) - } else { - cmd.Stdout = ioutil.Discard - cmd.Stderr = ioutil.Discard - err = cmd.Run() - } - if err != nil { + if err = projutil.ExecCmd(cmd); err != nil { return fmt.Errorf("failed to perform defaulter code-generation: %v", err) } return nil diff --git a/commands/operator-sdk/cmd/generate/openapi.go b/commands/operator-sdk/cmd/generate/openapi.go index 98bc00e80eb..244179908a9 100644 --- a/commands/operator-sdk/cmd/generate/openapi.go +++ b/commands/operator-sdk/cmd/generate/openapi.go @@ -167,14 +167,7 @@ func openAPIGen(binDir string, fqApis []string) (err error) { "--go-header-file", headerFile, } cmd := exec.Command(cgPath, args...) - if projutil.IsGoVerbose() { - err = projutil.ExecCmd(cmd) - } else { - cmd.Stdout = ioutil.Discard - cmd.Stderr = ioutil.Discard - err = cmd.Run() - } - if err != nil { + if err = projutil.ExecCmd(cmd); err != nil { return fmt.Errorf("failed to perform openapi code-generation: %v", err) } } diff --git a/test/e2e/memcached_test.go b/test/e2e/memcached_test.go index 931bbf302e3..165be5182bf 100644 --- a/test/e2e/memcached_test.go +++ b/test/e2e/memcached_test.go @@ -161,10 +161,6 @@ func TestMemcached(t *testing.T) { "api", "--api-version=cache.example.com/v1alpha1", "--kind=Memcached") - // Generators will print errors if -v is set. - if !projutil.IsGoVerbose() { - os.Setenv(projutil.GoFlagsEnv, os.Getenv(projutil.GoFlagsEnv)+" -v") - } cmd.Env = os.Environ() cmdOut, err = cmd.CombinedOutput() if err != nil {