Skip to content

Commit

Permalink
Move pkg/util.Time to pkg/api/unversioned.Time
Browse files Browse the repository at this point in the history
Along with our time.Duration wrapper, as suggested by @lavalamp.
  • Loading branch information
mvdan committed Sep 18, 2015
1 parent 21c7dd4 commit 586cb91
Show file tree
Hide file tree
Showing 79 changed files with 412 additions and 387 deletions.
1 change: 1 addition & 0 deletions contrib/mesos/pkg/scheduler/fcfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package scheduler

import (
"fmt"

log "github.com/golang/glog"

"k8s.io/kubernetes/contrib/mesos/pkg/offers"
Expand Down
3 changes: 1 addition & 2 deletions contrib/mesos/pkg/scheduler/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"k8s.io/kubernetes/pkg/client/cache"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/runtime"
kutil "k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/watch"

log "github.com/golang/glog"
Expand Down Expand Up @@ -273,7 +272,7 @@ func (o *EventObserver) Event(object runtime.Object, reason, message string) {
func (o *EventObserver) Eventf(object runtime.Object, reason, messageFmt string, args ...interface{}) {
o.fifo <- Event{Object: object, Reason: reason, Message: fmt.Sprintf(messageFmt, args...)}
}
func (o *EventObserver) PastEventf(object runtime.Object, timestamp kutil.Time, reason, messageFmt string, args ...interface{}) {
func (o *EventObserver) PastEventf(object runtime.Object, timestamp unversioned.Time, reason, messageFmt string, args ...interface{}) {
o.fifo <- Event{Object: object, Reason: reason, Message: fmt.Sprintf(messageFmt, args...)}
}

Expand Down
4 changes: 2 additions & 2 deletions docs/design/event_compression.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ Event compression should be best effort (not guaranteed). Meaning, in the worst
## Design

Instead of a single Timestamp, each event object [contains](http://releases.k8s.io/HEAD/pkg/api/types.go#L1111) the following fields:
* `FirstTimestamp util.Time`
* `FirstTimestamp unversioned.Time`
* The date/time of the first occurrence of the event.
* `LastTimestamp util.Time`
* `LastTimestamp unversioned.Time`
* The date/time of the most recent occurrence of the event.
* On first occurrence, this is equal to the FirstTimestamp.
* `Count int`
Expand Down
2 changes: 1 addition & 1 deletion docs/design/expansion.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ type ObjectEventRecorder interface {
Eventf(reason, messageFmt string, args ...interface{})

// PastEventf is just like Eventf, but with an option to specify the event's 'timestamp' field.
PastEventf(timestamp util.Time, reason, messageFmt string, args ...interface{})
PastEventf(timestamp unversioned.Time, reason, messageFmt string, args ...interface{})
}
```

Expand Down
4 changes: 2 additions & 2 deletions docs/devel/api-conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ The `FooCondition` type for some resource type `Foo` may include a subset of the
```golang
Type FooConditionType `json:"type" description:"type of Foo condition"`
Status ConditionStatus `json:"status" description:"status of the condition, one of True, False, Unknown"`
LastHeartbeatTime util.Time `json:"lastHeartbeatTime,omitempty" description:"last time we got an update on a given condition"`
LastTransitionTime util.Time `json:"lastTransitionTime,omitempty" description:"last time the condition transit from one status to another"`
LastHeartbeatTime unversioned.Time `json:"lastHeartbeatTime,omitempty" description:"last time we got an update on a given condition"`
LastTransitionTime unversioned.Time `json:"lastTransitionTime,omitempty" description:"last time the condition transit from one status to another"`
Reason string `json:"reason,omitempty" description:"one-word CamelCase reason for the condition's last transition"`
Message string `json:"message,omitempty" description:"human-readable message indicating details about last transition"`
```
Expand Down
2 changes: 1 addition & 1 deletion docs/proposals/compute-resource-metrics-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ type MetricsWindows map[time.Duration]DerivedMetrics

type DerivedMetrics struct {
// End time of all the time windows in Metrics
EndTime util.Time `json:"endtime"`
EndTime unversioned.Time `json:"endtime"`

Mean ResourceUsage `json:"mean"`
Max ResourceUsage `json:"max"`
Expand Down
2 changes: 1 addition & 1 deletion docs/proposals/horizontal-pod-autoscaler.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ type HorizontalPodAutoscalerStatus struct {

// LastScaleTimestamp is the last time the HorizontalPodAutoscaler scaled the number of pods.
// This is used by the autoscaler to control how often the number of pods is changed.
LastScaleTimestamp *util.Time
LastScaleTimestamp *unversioned.Time
}

// ResourceConsumption is an object for specifying average resource consumption of a particular resource.
Expand Down
10 changes: 5 additions & 5 deletions docs/proposals/job.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ type JobStatus struct {
Conditions []JobCondition

// CreationTime represents time when the job was created
CreationTime util.Time
CreationTime unversioned.Time

// StartTime represents time when the job was started
StartTime util.Time
StartTime unversioned.Time

// CompletionTime represents time when the job was completed
CompletionTime util.Time
CompletionTime unversioned.Time

// Active is the number of actively running pods.
Active int
Expand All @@ -162,8 +162,8 @@ const (
type JobCondition struct {
Type JobConditionType
Status ConditionStatus
LastHeartbeatTime util.Time
LastTransitionTime util.Time
LastHeartbeatTime unversioned.Time
LastTransitionTime unversioned.Time
Reason string
Message string
}
Expand Down
3 changes: 2 additions & 1 deletion examples/https-nginx/make_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ import (
"flag"
"fmt"
"io/ioutil"
"log"

"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/latest"
"k8s.io/kubernetes/pkg/runtime"
"log"
)

// TODO:
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ package api

import (
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/conversion"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
)

// Codec is the identity codec for this package - it can only convert itself
Expand All @@ -46,7 +46,7 @@ func init() {
},
)
Scheme.AddConversionFuncs(
func(in *util.Time, out *util.Time, s conversion.Scope) error {
func(in *unversioned.Time, out *unversioned.Time, s conversion.Scope) error {
// Cannot deep copy these, because time.Time has unexported fields.
*out = *in
return nil
Expand Down
44 changes: 22 additions & 22 deletions pkg/api/deep_copy_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func deepCopy_api_ContainerState(in ContainerState, out *ContainerState, c *conv
}

func deepCopy_api_ContainerStateRunning(in ContainerStateRunning, out *ContainerStateRunning, c *conversion.Cloner) error {
if err := deepCopy_util_Time(in.StartedAt, &out.StartedAt, c); err != nil {
if err := deepCopy_unversioned_Time(in.StartedAt, &out.StartedAt, c); err != nil {
return err
}
return nil
Expand All @@ -291,10 +291,10 @@ func deepCopy_api_ContainerStateTerminated(in ContainerStateTerminated, out *Con
out.Signal = in.Signal
out.Reason = in.Reason
out.Message = in.Message
if err := deepCopy_util_Time(in.StartedAt, &out.StartedAt, c); err != nil {
if err := deepCopy_unversioned_Time(in.StartedAt, &out.StartedAt, c); err != nil {
return err
}
if err := deepCopy_util_Time(in.FinishedAt, &out.FinishedAt, c); err != nil {
if err := deepCopy_unversioned_Time(in.FinishedAt, &out.FinishedAt, c); err != nil {
return err
}
out.ContainerID = in.ContainerID
Expand Down Expand Up @@ -503,10 +503,10 @@ func deepCopy_api_Event(in Event, out *Event, c *conversion.Cloner) error {
if err := deepCopy_api_EventSource(in.Source, &out.Source, c); err != nil {
return err
}
if err := deepCopy_util_Time(in.FirstTimestamp, &out.FirstTimestamp, c); err != nil {
if err := deepCopy_unversioned_Time(in.FirstTimestamp, &out.FirstTimestamp, c); err != nil {
return err
}
if err := deepCopy_util_Time(in.LastTimestamp, &out.LastTimestamp, c); err != nil {
if err := deepCopy_unversioned_Time(in.LastTimestamp, &out.LastTimestamp, c); err != nil {
return err
}
out.Count = in.Count
Expand Down Expand Up @@ -913,10 +913,10 @@ func deepCopy_api_NodeAddress(in NodeAddress, out *NodeAddress, c *conversion.Cl
func deepCopy_api_NodeCondition(in NodeCondition, out *NodeCondition, c *conversion.Cloner) error {
out.Type = in.Type
out.Status = in.Status
if err := deepCopy_util_Time(in.LastHeartbeatTime, &out.LastHeartbeatTime, c); err != nil {
if err := deepCopy_unversioned_Time(in.LastHeartbeatTime, &out.LastHeartbeatTime, c); err != nil {
return err
}
if err := deepCopy_util_Time(in.LastTransitionTime, &out.LastTransitionTime, c); err != nil {
if err := deepCopy_unversioned_Time(in.LastTransitionTime, &out.LastTransitionTime, c); err != nil {
return err
}
out.Reason = in.Reason
Expand Down Expand Up @@ -1028,12 +1028,12 @@ func deepCopy_api_ObjectMeta(in ObjectMeta, out *ObjectMeta, c *conversion.Clone
out.UID = in.UID
out.ResourceVersion = in.ResourceVersion
out.Generation = in.Generation
if err := deepCopy_util_Time(in.CreationTimestamp, &out.CreationTimestamp, c); err != nil {
if err := deepCopy_unversioned_Time(in.CreationTimestamp, &out.CreationTimestamp, c); err != nil {
return err
}
if in.DeletionTimestamp != nil {
out.DeletionTimestamp = new(util.Time)
if err := deepCopy_util_Time(*in.DeletionTimestamp, out.DeletionTimestamp, c); err != nil {
out.DeletionTimestamp = new(unversioned.Time)
if err := deepCopy_unversioned_Time(*in.DeletionTimestamp, out.DeletionTimestamp, c); err != nil {
return err
}
} else {
Expand Down Expand Up @@ -1482,8 +1482,8 @@ func deepCopy_api_PodStatus(in PodStatus, out *PodStatus, c *conversion.Cloner)
out.HostIP = in.HostIP
out.PodIP = in.PodIP
if in.StartTime != nil {
out.StartTime = new(util.Time)
if err := deepCopy_util_Time(*in.StartTime, out.StartTime, c); err != nil {
out.StartTime = new(unversioned.Time)
if err := deepCopy_unversioned_Time(*in.StartTime, out.StartTime, c); err != nil {
return err
}
} else {
Expand Down Expand Up @@ -2180,6 +2180,15 @@ func deepCopy_unversioned_ListMeta(in unversioned.ListMeta, out *unversioned.Lis
return nil
}

func deepCopy_unversioned_Time(in unversioned.Time, out *unversioned.Time, c *conversion.Cloner) error {
if newVal, err := c.DeepCopy(in.Time); err != nil {
return err
} else {
out.Time = newVal.(time.Time)
}
return nil
}

func deepCopy_unversioned_TypeMeta(in unversioned.TypeMeta, out *unversioned.TypeMeta, c *conversion.Cloner) error {
out.Kind = in.Kind
out.APIVersion = in.APIVersion
Expand All @@ -2193,15 +2202,6 @@ func deepCopy_util_IntOrString(in util.IntOrString, out *util.IntOrString, c *co
return nil
}

func deepCopy_util_Time(in util.Time, out *util.Time, c *conversion.Cloner) error {
if newVal, err := c.DeepCopy(in.Time); err != nil {
return err
} else {
out.Time = newVal.(time.Time)
}
return nil
}

func init() {
err := Scheme.AddGeneratedDeepCopyFuncs(
deepCopy_api_AWSElasticBlockStoreVolumeSource,
Expand Down Expand Up @@ -2322,9 +2322,9 @@ func init() {
deepCopy_api_VolumeSource,
deepCopy_resource_Quantity,
deepCopy_unversioned_ListMeta,
deepCopy_unversioned_Time,
deepCopy_unversioned_TypeMeta,
deepCopy_util_IntOrString,
deepCopy_util_Time,
)
if err != nil {
// if one of the deep copy functions is malformed, detect it immediately.
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import (
"strings"

"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/conversion"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/sets"

"github.com/davecgh/go-spew/spew"
Expand Down Expand Up @@ -67,7 +67,7 @@ var Semantic = conversion.EqualitiesOrDie(
}
return a.Amount.Cmp(b.Amount) == 0
},
func(a, b util.Time) bool {
func(a, b unversioned.Time) bool {
return a.UTC() == b.UTC()
},
func(a, b labels.Selector) bool {
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

// FillObjectMetaSystemFields populates fields that are managed by the system on ObjectMeta.
func FillObjectMetaSystemFields(ctx Context, meta *ObjectMeta) {
meta.CreationTimestamp = util.Now()
meta.CreationTimestamp = unversioned.Now()
meta.UID = util.NewUUID()
meta.SelfLink = ""
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/api/meta/meta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"reflect"
"testing"

"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
)

func TestGenericTypeMeta(t *testing.T) {
Expand All @@ -31,7 +31,7 @@ func TestGenericTypeMeta(t *testing.T) {
Name string `json:"name,omitempty"`
GenerateName string `json:"generateName,omitempty"`
UID string `json:"uid,omitempty"`
CreationTimestamp util.Time `json:"creationTimestamp,omitempty"`
CreationTimestamp unversioned.Time `json:"creationTimestamp,omitempty"`
SelfLink string `json:"selfLink,omitempty"`
ResourceVersion string `json:"resourceVersion,omitempty"`
APIVersion string `json:"apiVersion,omitempty"`
Expand Down Expand Up @@ -146,7 +146,7 @@ type InternalTypeMeta struct {
Name string `json:"name,omitempty"`
GenerateName string `json:"generateName,omitempty"`
UID string `json:"uid,omitempty"`
CreationTimestamp util.Time `json:"creationTimestamp,omitempty"`
CreationTimestamp unversioned.Time `json:"creationTimestamp,omitempty"`
SelfLink string `json:"selfLink,omitempty"`
ResourceVersion string `json:"resourceVersion,omitempty"`
APIVersion string `json:"apiVersion,omitempty"`
Expand Down Expand Up @@ -321,7 +321,7 @@ func TestGenericObjectMeta(t *testing.T) {
Name string `json:"name,omitempty"`
GenerateName string `json:"generateName,omitempty"`
UID string `json:"uid,omitempty"`
CreationTimestamp util.Time `json:"creationTimestamp,omitempty"`
CreationTimestamp unversioned.Time `json:"creationTimestamp,omitempty"`
SelfLink string `json:"selfLink,omitempty"`
ResourceVersion string `json:"resourceVersion,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/rest/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"time"

"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
)

// RESTDeleteStrategy defines deletion behavior on an object that follows Kubernetes
Expand Down Expand Up @@ -62,7 +62,7 @@ func BeforeDelete(strategy RESTDeleteStrategy, ctx api.Context, obj runtime.Obje
if period > *objectMeta.DeletionGracePeriodSeconds {
return false, true, nil
}
now := util.NewTime(util.Now().Add(time.Second * time.Duration(*options.GracePeriodSeconds)))
now := unversioned.NewTime(unversioned.Now().Add(time.Second * time.Duration(*options.GracePeriodSeconds)))
objectMeta.DeletionTimestamp = &now
objectMeta.DeletionGracePeriodSeconds = &period
options.GracePeriodSeconds = &period
Expand All @@ -76,7 +76,7 @@ func BeforeDelete(strategy RESTDeleteStrategy, ctx api.Context, obj runtime.Obje
if !strategy.CheckGracefulDelete(obj, options) {
return false, false, nil
}
now := util.NewTime(util.Now().Add(time.Second * time.Duration(*options.GracePeriodSeconds)))
now := unversioned.NewTime(unversioned.Now().Add(time.Second * time.Duration(*options.GracePeriodSeconds)))
objectMeta.DeletionTimestamp = &now
objectMeta.DeletionGracePeriodSeconds = options.GracePeriodSeconds
return true, false, nil
Expand Down
3 changes: 1 addition & 2 deletions pkg/api/rest/resttest/resttest.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/tools"
"k8s.io/kubernetes/pkg/util"
)

type Tester struct {
Expand Down Expand Up @@ -370,7 +369,7 @@ func (t *Tester) testCreateRejectsMismatchedNamespace(valid runtime.Object) {

func (t *Tester) testCreateResetsUserData(valid runtime.Object) {
objectMeta := t.getObjectMetaOrFail(valid)
now := util.Now()
now := unversioned.Now()
objectMeta.UID = "bad-uid"
objectMeta.CreationTimestamp = now

Expand Down
2 changes: 1 addition & 1 deletion pkg/api/testing/fuzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func FuzzerFor(t *testing.T, version string, src rand.Source) *fuzz.Fuzzer {
var sec, nsec int64
c.Fuzz(&sec)
c.Fuzz(&nsec)
j.CreationTimestamp = util.Unix(sec, nsec).Rfc3339Copy()
j.CreationTimestamp = unversioned.Unix(sec, nsec).Rfc3339Copy()
},
func(j *api.ObjectReference, c fuzz.Continue) {
// We have to customize the randomization of TypeMetas because their
Expand Down
Loading

0 comments on commit 586cb91

Please sign in to comment.