Skip to content

Commit 5149d1b

Browse files
authored
fix(cli): Split diff and non-diff output (#537)
On commands that produce diffs: diff, apply, and prune. It is desirable for some use cases to parse diff output from `kubectl diff` (e.g. secret redaction until kubernetes/kubernetes#87840 is resolved). This is a lot easier when diff and non-diff output are not combined on the same channel, stdout. This commit moves diagnostic, non-diff output for the 3 relevant subcommands to stderr.
1 parent 17684fd commit 5149d1b

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

pkg/kubernetes/client/delete.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func (k Kubectl) Delete(namespace, kind, name string, opts DeleteOpts) error {
1414
}
1515

1616
cmd := k.ctl("delete", argv...)
17-
cmd.Stdout = os.Stdout
17+
cmd.Stdout = os.Stderr
1818
cmd.Stderr = os.Stderr
1919
cmd.Stdin = os.Stdin
2020

pkg/tanka/prune.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package tanka
22

33
import (
44
"fmt"
5+
"log"
56

67
"github.com/fatih/color"
78

@@ -40,7 +41,7 @@ func Prune(baseDir string, opts PruneOpts) error {
4041
}
4142

4243
if len(orphaned) == 0 {
43-
fmt.Println("Nothing found to prune.")
44+
log.Println("Nothing found to prune.")
4445
return nil
4546
}
4647

@@ -61,12 +62,12 @@ func Prune(baseDir string, opts PruneOpts) error {
6162
}
6263
}
6364
if len(namespaces) > 0 {
64-
warning := color.New(color.FgHiYellow, color.Bold).PrintFunc()
65-
warning("WARNING: This will delete following namespaces and all resources in them:\n")
65+
warning := color.New(color.FgHiYellow, color.Bold).FprintfFunc()
66+
warning(color.Error, "WARNING: This will delete following namespaces and all resources in them:\n")
6667
for _, ns := range namespaces {
67-
fmt.Printf(" - %s\n", ns)
68+
log.Printf(" - %s\n", ns)
6869
}
69-
fmt.Println("")
70+
log.Println("")
7071
}
7172

7273
// prompt for confirm

pkg/tanka/workflow.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package tanka
22

33
import (
44
"fmt"
5+
"log"
56

67
"github.com/fatih/color"
78

@@ -45,7 +46,7 @@ func Apply(baseDir string, opts ApplyOpts) error {
4546
switch {
4647
case err != nil:
4748
// This is not fatal, the diff is not strictly required
48-
fmt.Println("Error diffing:", err)
49+
log.Println("Error diffing:", err)
4950
case diff == nil:
5051
tmp := "Warning: There are no differences. Your apply may not do anything at all."
5152
diff = &tmp

0 commit comments

Comments
 (0)