From 51bfb506988ec7eb7d1db711481cd5068fc9e473 Mon Sep 17 00:00:00 2001 From: Jordan Liggitt Date: Wed, 10 Dec 2014 17:00:41 -0500 Subject: [PATCH] Use util.Time consistently in types.go --- pkg/api/serialization_test.go | 9 --------- pkg/api/types.go | 8 +++----- pkg/api/v1beta1/types.go | 19 +++++++------------ pkg/api/v1beta2/types.go | 19 +++++++------------ pkg/api/v1beta3/types.go | 8 +++----- pkg/kubelet/dockertools/docker.go | 6 +++--- pkg/registry/pod/rest_test.go | 2 +- pkg/util/time.go | 5 +++++ 8 files changed, 29 insertions(+), 47 deletions(-) diff --git a/pkg/api/serialization_test.go b/pkg/api/serialization_test.go index e65bffe1270..1f193621c9f 100644 --- a/pkg/api/serialization_test.go +++ b/pkg/api/serialization_test.go @@ -23,7 +23,6 @@ import ( "reflect" "strconv" "testing" - "time" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest" @@ -137,14 +136,6 @@ var apiObjectFuzzer = fuzz.New().NilChance(.5).NumElements(1, 1).Funcs( c.RandString(): c.RandString(), } }, - func(t *time.Time, c fuzz.Continue) { - // This is necessary because the standard fuzzed time.Time object is - // completely nil, but when JSON unmarshals dates it fills in the - // unexported loc field with the time.UTC object, resulting in - // reflect.DeepEqual returning false in the round trip tests. We solve it - // by using a date that will be identical to the one JSON unmarshals. - *t = time.Date(2000, 1, 1, 1, 1, 1, 0, time.UTC) - }, ) func runTest(t *testing.T, codec runtime.Codec, source runtime.Object) { diff --git a/pkg/api/types.go b/pkg/api/types.go index 2b719218b63..69bd0f765d5 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -17,8 +17,6 @@ limitations under the License. package api import ( - "time" - "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" ) @@ -373,7 +371,7 @@ type ContainerStateWaiting struct { } type ContainerStateRunning struct { - StartedAt time.Time `json:"startedAt,omitempty"` + StartedAt util.Time `json:"startedAt,omitempty"` } type ContainerStateTerminated struct { @@ -381,8 +379,8 @@ type ContainerStateTerminated struct { Signal int `json:"signal,omitempty"` Reason string `json:"reason,omitempty"` Message string `json:"message,omitempty"` - StartedAt time.Time `json:"startedAt,omitempty"` - FinishedAt time.Time `json:"finishedAt,omitempty"` + StartedAt util.Time `json:"startedAt,omitempty"` + FinishedAt util.Time `json:"finishedAt,omitempty"` } // ContainerState holds a possible state of container. diff --git a/pkg/api/v1beta1/types.go b/pkg/api/v1beta1/types.go index c575a1d6be4..c300ce04c48 100644 --- a/pkg/api/v1beta1/types.go +++ b/pkg/api/v1beta1/types.go @@ -17,8 +17,6 @@ limitations under the License. package v1beta1 import ( - "time" - "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" ) @@ -329,19 +327,16 @@ type ContainerStateWaiting struct { } type ContainerStateRunning struct { - // TODO: change to util.Time - StartedAt time.Time `json:"startedAt,omitempty" description:"time at which the container was last (re-)started"` + StartedAt util.Time `json:"startedAt,omitempty" description:"time at which the container was last (re-)started"` } type ContainerStateTerminated struct { - ExitCode int `json:"exitCode" description:"exit status from the last termination of the container"` - Signal int `json:"signal,omitempty" description:"signal from the last termination of the container"` - Reason string `json:"reason,omitempty" description:"(brief) reason from the last termination of the container"` - Message string `json:"message,omitempty" description:"message regarding the last termination of the container"` - // TODO: change to util.Time - StartedAt time.Time `json:"startedAt,omitempty" description:"time at which previous execution of the container started"` - // TODO: change to util.Time - FinishedAt time.Time `json:"finishedAt,omitempty" description:"time at which the container last terminated"` + ExitCode int `json:"exitCode" description:"exit status from the last termination of the container"` + Signal int `json:"signal,omitempty" description:"signal from the last termination of the container"` + Reason string `json:"reason,omitempty" description:"(brief) reason from the last termination of the container"` + Message string `json:"message,omitempty" description:"message regarding the last termination of the container"` + StartedAt util.Time `json:"startedAt,omitempty" description:"time at which previous execution of the container started"` + FinishedAt util.Time `json:"finishedAt,omitempty" description:"time at which the container last terminated"` } // ContainerState holds a possible state of container. diff --git a/pkg/api/v1beta2/types.go b/pkg/api/v1beta2/types.go index 9931943d1fc..327de0ac002 100644 --- a/pkg/api/v1beta2/types.go +++ b/pkg/api/v1beta2/types.go @@ -17,8 +17,6 @@ limitations under the License. package v1beta2 import ( - "time" - "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" ) @@ -294,19 +292,16 @@ type ContainerStateWaiting struct { } type ContainerStateRunning struct { - // TODO: change to util.Time - StartedAt time.Time `json:"startedAt,omitempty" description:"time at which the container was last (re-)started"` + StartedAt util.Time `json:"startedAt,omitempty" description:"time at which the container was last (re-)started"` } type ContainerStateTerminated struct { - ExitCode int `json:"exitCode" description:"exit status from the last termination of the container"` - Signal int `json:"signal,omitempty" description:"signal from the last termination of the container"` - Reason string `json:"reason,omitempty" description:"(brief) reason from the last termination of the container"` - Message string `json:"message,omitempty" description:"message regarding the last termination of the container"` - // TODO: change to util.Time - StartedAt time.Time `json:"startedAt,omitempty" description:"time at which previous execution of the container started"` - // TODO: change to util.Time - FinishedAt time.Time `json:"finishedAt,omitempty" description:"time at which the container last terminated"` + ExitCode int `json:"exitCode" description:"exit status from the last termination of the container"` + Signal int `json:"signal,omitempty" description:"signal from the last termination of the container"` + Reason string `json:"reason,omitempty" description:"(brief) reason from the last termination of the container"` + Message string `json:"message,omitempty" description:"message regarding the last termination of the container"` + StartedAt util.Time `json:"startedAt,omitempty" description:"time at which previous execution of the container started"` + FinishedAt util.Time `json:"finishedAt,omitempty" description:"time at which the container last terminated"` } // ContainerState holds a possible state of container. diff --git a/pkg/api/v1beta3/types.go b/pkg/api/v1beta3/types.go index bfbafbdee96..a0dae1981d0 100644 --- a/pkg/api/v1beta3/types.go +++ b/pkg/api/v1beta3/types.go @@ -17,8 +17,6 @@ limitations under the License. package v1beta3 import ( - "time" - "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" ) @@ -393,7 +391,7 @@ type ContainerStateWaiting struct { } type ContainerStateRunning struct { - StartedAt time.Time `json:"startedAt,omitempty"` + StartedAt util.Time `json:"startedAt,omitempty"` } type ContainerStateTerminated struct { @@ -401,8 +399,8 @@ type ContainerStateTerminated struct { Signal int `json:"signal,omitempty"` Reason string `json:"reason,omitempty"` Message string `json:"message,omitempty"` - StartedAt time.Time `json:"startedAt,omitempty"` - FinishedAt time.Time `json:"finishedAt,omitempty"` + StartedAt util.Time `json:"startedAt,omitempty"` + FinishedAt util.Time `json:"finishedAt,omitempty"` } // ContainerState holds a possible state of container. diff --git a/pkg/kubelet/dockertools/docker.go b/pkg/kubelet/dockertools/docker.go index b69cf0ae10c..1593db7c2bf 100644 --- a/pkg/kubelet/dockertools/docker.go +++ b/pkg/kubelet/dockertools/docker.go @@ -396,7 +396,7 @@ func inspectContainer(client DockerInterface, dockerID, containerName, tPath str waiting := true if inspectResult.State.Running { containerStatus.State.Running = &api.ContainerStateRunning{ - StartedAt: inspectResult.State.StartedAt, + StartedAt: util.NewTime(inspectResult.State.StartedAt), } if containerName == "net" && inspectResult.NetworkSettings != nil { containerStatus.PodIP = inspectResult.NetworkSettings.IPAddress @@ -407,8 +407,8 @@ func inspectContainer(client DockerInterface, dockerID, containerName, tPath str containerStatus.State.Termination = &api.ContainerStateTerminated{ ExitCode: inspectResult.State.ExitCode, Reason: "", - StartedAt: inspectResult.State.StartedAt, - FinishedAt: inspectResult.State.FinishedAt, + StartedAt: util.NewTime(inspectResult.State.StartedAt), + FinishedAt: util.NewTime(inspectResult.State.FinishedAt), } if tPath != "" { path, found := inspectResult.Volumes[tPath] diff --git a/pkg/registry/pod/rest_test.go b/pkg/registry/pod/rest_test.go index ac2faeea627..3aea5a43002 100644 --- a/pkg/registry/pod/rest_test.go +++ b/pkg/registry/pod/rest_test.go @@ -578,7 +578,7 @@ func TestFillPodInfo(t *testing.T) { "net": { State: api.ContainerState{ Running: &api.ContainerStateRunning{ - StartedAt: expectedTime, + StartedAt: util.NewTime(expectedTime), }, }, RestartCount: 1, diff --git a/pkg/util/time.go b/pkg/util/time.go index 0b9bed866a8..470e9781c7f 100644 --- a/pkg/util/time.go +++ b/pkg/util/time.go @@ -28,6 +28,11 @@ type Time struct { time.Time } +// NewTime returns a wrapped instance of the provided time +func NewTime(time time.Time) Time { + return Time{time} +} + // Date returns the Time corresponding to the supplied parameters // by wrapping time.Date. func Date(year int, month time.Month, day, hour, min, sec, nsec int, loc *time.Location) Time {