Use util.Time consistently in types.go

This commit is contained in:
Jordan Liggitt 2014-12-10 17:00:41 -05:00
parent a299287ae8
commit 51bfb50698
8 changed files with 29 additions and 47 deletions

View File

@ -23,7 +23,6 @@ import (
"reflect" "reflect"
"strconv" "strconv"
"testing" "testing"
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest" "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(), 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) { func runTest(t *testing.T, codec runtime.Codec, source runtime.Object) {

View File

@ -17,8 +17,6 @@ limitations under the License.
package api package api
import ( import (
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util"
) )
@ -373,7 +371,7 @@ type ContainerStateWaiting struct {
} }
type ContainerStateRunning struct { type ContainerStateRunning struct {
StartedAt time.Time `json:"startedAt,omitempty"` StartedAt util.Time `json:"startedAt,omitempty"`
} }
type ContainerStateTerminated struct { type ContainerStateTerminated struct {
@ -381,8 +379,8 @@ type ContainerStateTerminated struct {
Signal int `json:"signal,omitempty"` Signal int `json:"signal,omitempty"`
Reason string `json:"reason,omitempty"` Reason string `json:"reason,omitempty"`
Message string `json:"message,omitempty"` Message string `json:"message,omitempty"`
StartedAt time.Time `json:"startedAt,omitempty"` StartedAt util.Time `json:"startedAt,omitempty"`
FinishedAt time.Time `json:"finishedAt,omitempty"` FinishedAt util.Time `json:"finishedAt,omitempty"`
} }
// ContainerState holds a possible state of container. // ContainerState holds a possible state of container.

View File

@ -17,8 +17,6 @@ limitations under the License.
package v1beta1 package v1beta1
import ( import (
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util"
) )
@ -329,8 +327,7 @@ type ContainerStateWaiting struct {
} }
type ContainerStateRunning struct { type ContainerStateRunning struct {
// TODO: change to util.Time StartedAt util.Time `json:"startedAt,omitempty" description:"time at which the container was last (re-)started"`
StartedAt time.Time `json:"startedAt,omitempty" description:"time at which the container was last (re-)started"`
} }
type ContainerStateTerminated struct { type ContainerStateTerminated struct {
@ -338,10 +335,8 @@ type ContainerStateTerminated struct {
Signal int `json:"signal,omitempty" description:"signal 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"` 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"` Message string `json:"message,omitempty" description:"message regarding the last termination of the container"`
// TODO: change to util.Time StartedAt util.Time `json:"startedAt,omitempty" description:"time at which previous execution of the container started"`
StartedAt time.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"`
// TODO: change to util.Time
FinishedAt time.Time `json:"finishedAt,omitempty" description:"time at which the container last terminated"`
} }
// ContainerState holds a possible state of container. // ContainerState holds a possible state of container.

View File

@ -17,8 +17,6 @@ limitations under the License.
package v1beta2 package v1beta2
import ( import (
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util"
) )
@ -294,8 +292,7 @@ type ContainerStateWaiting struct {
} }
type ContainerStateRunning struct { type ContainerStateRunning struct {
// TODO: change to util.Time StartedAt util.Time `json:"startedAt,omitempty" description:"time at which the container was last (re-)started"`
StartedAt time.Time `json:"startedAt,omitempty" description:"time at which the container was last (re-)started"`
} }
type ContainerStateTerminated struct { type ContainerStateTerminated struct {
@ -303,10 +300,8 @@ type ContainerStateTerminated struct {
Signal int `json:"signal,omitempty" description:"signal 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"` 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"` Message string `json:"message,omitempty" description:"message regarding the last termination of the container"`
// TODO: change to util.Time StartedAt util.Time `json:"startedAt,omitempty" description:"time at which previous execution of the container started"`
StartedAt time.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"`
// TODO: change to util.Time
FinishedAt time.Time `json:"finishedAt,omitempty" description:"time at which the container last terminated"`
} }
// ContainerState holds a possible state of container. // ContainerState holds a possible state of container.

View File

@ -17,8 +17,6 @@ limitations under the License.
package v1beta3 package v1beta3
import ( import (
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util"
) )
@ -393,7 +391,7 @@ type ContainerStateWaiting struct {
} }
type ContainerStateRunning struct { type ContainerStateRunning struct {
StartedAt time.Time `json:"startedAt,omitempty"` StartedAt util.Time `json:"startedAt,omitempty"`
} }
type ContainerStateTerminated struct { type ContainerStateTerminated struct {
@ -401,8 +399,8 @@ type ContainerStateTerminated struct {
Signal int `json:"signal,omitempty"` Signal int `json:"signal,omitempty"`
Reason string `json:"reason,omitempty"` Reason string `json:"reason,omitempty"`
Message string `json:"message,omitempty"` Message string `json:"message,omitempty"`
StartedAt time.Time `json:"startedAt,omitempty"` StartedAt util.Time `json:"startedAt,omitempty"`
FinishedAt time.Time `json:"finishedAt,omitempty"` FinishedAt util.Time `json:"finishedAt,omitempty"`
} }
// ContainerState holds a possible state of container. // ContainerState holds a possible state of container.

View File

@ -396,7 +396,7 @@ func inspectContainer(client DockerInterface, dockerID, containerName, tPath str
waiting := true waiting := true
if inspectResult.State.Running { if inspectResult.State.Running {
containerStatus.State.Running = &api.ContainerStateRunning{ containerStatus.State.Running = &api.ContainerStateRunning{
StartedAt: inspectResult.State.StartedAt, StartedAt: util.NewTime(inspectResult.State.StartedAt),
} }
if containerName == "net" && inspectResult.NetworkSettings != nil { if containerName == "net" && inspectResult.NetworkSettings != nil {
containerStatus.PodIP = inspectResult.NetworkSettings.IPAddress containerStatus.PodIP = inspectResult.NetworkSettings.IPAddress
@ -407,8 +407,8 @@ func inspectContainer(client DockerInterface, dockerID, containerName, tPath str
containerStatus.State.Termination = &api.ContainerStateTerminated{ containerStatus.State.Termination = &api.ContainerStateTerminated{
ExitCode: inspectResult.State.ExitCode, ExitCode: inspectResult.State.ExitCode,
Reason: "", Reason: "",
StartedAt: inspectResult.State.StartedAt, StartedAt: util.NewTime(inspectResult.State.StartedAt),
FinishedAt: inspectResult.State.FinishedAt, FinishedAt: util.NewTime(inspectResult.State.FinishedAt),
} }
if tPath != "" { if tPath != "" {
path, found := inspectResult.Volumes[tPath] path, found := inspectResult.Volumes[tPath]

View File

@ -578,7 +578,7 @@ func TestFillPodInfo(t *testing.T) {
"net": { "net": {
State: api.ContainerState{ State: api.ContainerState{
Running: &api.ContainerStateRunning{ Running: &api.ContainerStateRunning{
StartedAt: expectedTime, StartedAt: util.NewTime(expectedTime),
}, },
}, },
RestartCount: 1, RestartCount: 1,

View File

@ -28,6 +28,11 @@ type Time struct {
time.Time 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 // Date returns the Time corresponding to the supplied parameters
// by wrapping time.Date. // by wrapping time.Date.
func Date(year int, month time.Month, day, hour, min, sec, nsec int, loc *time.Location) Time { func Date(year int, month time.Month, day, hour, min, sec, nsec int, loc *time.Location) Time {