Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use util.Time consistently in types.go #2833

Merged
merged 1 commit into from
Dec 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 0 additions & 9 deletions pkg/api/serialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"reflect"
"strconv"
"testing"
"time"

"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 3 additions & 5 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ limitations under the License.
package api

import (
"time"

"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
)
Expand Down Expand Up @@ -373,16 +371,16 @@ type ContainerStateWaiting struct {
}

type ContainerStateRunning struct {
StartedAt time.Time `json:"startedAt,omitempty"`
StartedAt util.Time `json:"startedAt,omitempty"`
}

type ContainerStateTerminated struct {
ExitCode int `json:"exitCode"`
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.
Expand Down
19 changes: 7 additions & 12 deletions pkg/api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ limitations under the License.
package v1beta1

import (
"time"

"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
)
Expand Down Expand Up @@ -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.
Expand Down
19 changes: 7 additions & 12 deletions pkg/api/v1beta2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ limitations under the License.
package v1beta2

import (
"time"

"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
)
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 3 additions & 5 deletions pkg/api/v1beta3/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ limitations under the License.
package v1beta3

import (
"time"

"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
)
Expand Down Expand Up @@ -393,16 +391,16 @@ type ContainerStateWaiting struct {
}

type ContainerStateRunning struct {
StartedAt time.Time `json:"startedAt,omitempty"`
StartedAt util.Time `json:"startedAt,omitempty"`
}

type ContainerStateTerminated struct {
ExitCode int `json:"exitCode"`
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.
Expand Down
6 changes: 3 additions & 3 deletions pkg/kubelet/dockertools/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/pod/rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ func TestFillPodInfo(t *testing.T) {
"net": {
State: api.ContainerState{
Running: &api.ContainerStateRunning{
StartedAt: expectedTime,
StartedAt: util.NewTime(expectedTime),
},
},
RestartCount: 1,
Expand Down
5 changes: 5 additions & 0 deletions pkg/util/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down