Skip to content

Commit

Permalink
Remove ugly creationTimestamp: null output
Browse files Browse the repository at this point in the history
  • Loading branch information
liggitt committed Dec 10, 2017
1 parent c8d8890 commit 95171a0
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ func Output(w io.Writer, obj runtime.Object, format string) error {
s = json.NewSerializer(json.DefaultMetaFactory, Scheme, Scheme, true)
case "yaml":
s = json.NewYAMLSerializer(json.DefaultMetaFactory, Scheme, Scheme)
// TODO: clean up "creationTimestamp: null" upstream
w = &stripCreationTimestamp{w}
default:
return fmt.Errorf("unknown format: %s", format)
}
Expand All @@ -202,3 +204,16 @@ func Output(w io.Writer, obj runtime.Object, format string) error {

return codec.Encode(obj, w)
}

type stripCreationTimestamp struct {
w io.Writer
}

func (s *stripCreationTimestamp) Write(p []byte) (n int, err error) {
p2 := strings.Replace(string(p), "\n creationTimestamp: null\n", "\n", -1)
n, err = s.w.Write([]byte(p2))
if n == len(p2) {
n = len(p)
}
return n, err
}

0 comments on commit 95171a0

Please sign in to comment.