Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Remove managed fields from yaml/json output
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Jun 25, 2022
1 parent 6d344c7 commit 6b0dc60
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions pkg/cli/builder/table/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,32 @@ func FormatCreated(data metav1.Time) string {
}

func FormatJSON(data interface{}) (string, error) {
bytes, err := json.MarshalIndent(data, "", " ")
bytes, err := json.MarshalIndent(cleanFields(data), "", " ")
return string(bytes) + "\n", err
}

func FormatJSONCompact(data interface{}) (string, error) {
bytes, err := json.Marshal(data)
bytes, err := json.Marshal(cleanFields(data))
return string(bytes) + "\n", err
}

func cleanFields(obj interface{}) interface{} {
ro, ok := obj.(kclient.Object)
if !ok {
newObj := reflect.New(reflect.TypeOf(obj))
newObj.Elem().Set(reflect.ValueOf(obj))
ro, ok = newObj.Interface().(kclient.Object)
}
if ok {
ro.SetManagedFields(nil)
return ro
}
return obj

}

func FormatYAML(data interface{}) (string, error) {
bytes, err := yaml.Marshal(data)
bytes, err := yaml.Marshal(cleanFields(data))
return string(bytes) + "\n", err
}

Expand Down

0 comments on commit 6b0dc60

Please sign in to comment.