Skip to content

Commit

Permalink
output empty creationTimestamp as null
Browse files Browse the repository at this point in the history
  • Loading branch information
juanvallejo committed Oct 9, 2017
1 parent 33f911c commit 465edb2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@ func (u *Unstructured) GetCreationTimestamp() metav1.Time {

func (u *Unstructured) SetCreationTimestamp(timestamp metav1.Time) {
ts, _ := timestamp.MarshalQueryParameter()
if len(ts) == 0 {
u.setNestedField(nil, "metadata", "creationTimestamp")
return
}
u.setNestedField(ts, "metadata", "creationTimestamp")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,14 @@ func TestNilDeletionTimestamp(t *testing.T) {
t.Errorf("unexpected deletion timestamp field: %q", deletionTimestamp)
}
}

func TestNilCreationTimestamp(t *testing.T) {
var u Unstructured
u.SetCreationTimestamp(u.GetCreationTimestamp())

metadata := u.Object["metadata"].(map[string]interface{})
creationTimestamp := metadata["creationTimestamp"]
if creationTimestamp != nil {
t.Errorf("unexpected creation timestamp field: %q", creationTimestamp)
}
}

0 comments on commit 465edb2

Please sign in to comment.