Make metav1.(Micro)?Time functions take pointers

pull/6/head
gmarek 2017-08-04 17:04:14 +02:00
parent 402e48b072
commit 0504cfbc25
23 changed files with 64 additions and 59 deletions

View File

@ -468,12 +468,12 @@ func (fjc *FederationJobController) reconcileJob(key string) (reconciliationStat
for _, condition := range currentLjob.Status.Conditions {
if condition.Type == batchv1.JobComplete {
if fedStatusCompleteCondition == nil ||
fedStatusCompleteCondition.LastTransitionTime.Before(condition.LastTransitionTime) {
fedStatusCompleteCondition.LastTransitionTime.Before(&condition.LastTransitionTime) {
fedStatusCompleteCondition = &condition
}
} else if condition.Type == batchv1.JobFailed {
if fedStatusFailedCondition == nil ||
fedStatusFailedCondition.LastTransitionTime.Before(condition.LastTransitionTime) {
fedStatusFailedCondition.LastTransitionTime.Before(&condition.LastTransitionTime) {
fedStatusFailedCondition = &condition
}
}
@ -484,7 +484,7 @@ func (fjc *FederationJobController) reconcileJob(key string) (reconciliationStat
}
}
if currentLjob.Status.CompletionTime != nil {
if fedStatus.CompletionTime == nil || fedStatus.CompletionTime.Before(*currentLjob.Status.CompletionTime) {
if fedStatus.CompletionTime == nil || fedStatus.CompletionTime.Before(currentLjob.Status.CompletionTime) {
fedStatus.CompletionTime = currentLjob.Status.CompletionTime
}
}

View File

@ -218,8 +218,8 @@ func UpdatePodCondition(status *api.PodStatus, condition *api.PodCondition) bool
isEqual := condition.Status == oldCondition.Status &&
condition.Reason == oldCondition.Reason &&
condition.Message == oldCondition.Message &&
condition.LastProbeTime.Equal(oldCondition.LastProbeTime) &&
condition.LastTransitionTime.Equal(oldCondition.LastTransitionTime)
condition.LastProbeTime.Equal(&oldCondition.LastProbeTime) &&
condition.LastTransitionTime.Equal(&oldCondition.LastTransitionTime)
status.Conditions[conditionIndex] = *condition
// Return true if one of the fields have changed.

View File

@ -348,8 +348,8 @@ func UpdatePodCondition(status *v1.PodStatus, condition *v1.PodCondition) bool {
isEqual := condition.Status == oldCondition.Status &&
condition.Reason == oldCondition.Reason &&
condition.Message == oldCondition.Message &&
condition.LastProbeTime.Equal(oldCondition.LastProbeTime) &&
condition.LastTransitionTime.Equal(oldCondition.LastTransitionTime)
condition.LastProbeTime.Equal(&oldCondition.LastProbeTime) &&
condition.LastTransitionTime.Equal(&oldCondition.LastTransitionTime)
status.Conditions[conditionIndex] = *condition
// Return true if one of the fields have changed.

View File

@ -711,8 +711,8 @@ func (s ByLogging) Less(i, j int) bool {
return maxContainerRestarts(s[i]) > maxContainerRestarts(s[j])
}
// 6. older pods < newer pods < empty timestamp pods
if !s[i].CreationTimestamp.Equal(s[j].CreationTimestamp) {
return afterOrZero(s[j].CreationTimestamp, s[i].CreationTimestamp)
if !s[i].CreationTimestamp.Equal(&s[j].CreationTimestamp) {
return afterOrZero(&s[j].CreationTimestamp, &s[i].CreationTimestamp)
}
return false
}
@ -751,31 +751,31 @@ func (s ActivePods) Less(i, j int) bool {
return maxContainerRestarts(s[i]) > maxContainerRestarts(s[j])
}
// 6. Empty creation time pods < newer pods < older pods
if !s[i].CreationTimestamp.Equal(s[j].CreationTimestamp) {
return afterOrZero(s[i].CreationTimestamp, s[j].CreationTimestamp)
if !s[i].CreationTimestamp.Equal(&s[j].CreationTimestamp) {
return afterOrZero(&s[i].CreationTimestamp, &s[j].CreationTimestamp)
}
return false
}
// afterOrZero checks if time t1 is after time t2; if one of them
// is zero, the zero time is seen as after non-zero time.
func afterOrZero(t1, t2 metav1.Time) bool {
func afterOrZero(t1, t2 *metav1.Time) bool {
if t1.Time.IsZero() || t2.Time.IsZero() {
return t1.Time.IsZero()
}
return t1.After(t2.Time)
}
func podReadyTime(pod *v1.Pod) metav1.Time {
func podReadyTime(pod *v1.Pod) *metav1.Time {
if podutil.IsPodReady(pod) {
for _, c := range pod.Status.Conditions {
// we only care about pod ready conditions
if c.Type == v1.PodReady && c.Status == v1.ConditionTrue {
return c.LastTransitionTime
return &c.LastTransitionTime
}
}
}
return metav1.Time{}
return &metav1.Time{}
}
func maxContainerRestarts(pod *v1.Pod) int {
@ -841,10 +841,10 @@ type ControllersByCreationTimestamp []*v1.ReplicationController
func (o ControllersByCreationTimestamp) Len() int { return len(o) }
func (o ControllersByCreationTimestamp) Swap(i, j int) { o[i], o[j] = o[j], o[i] }
func (o ControllersByCreationTimestamp) Less(i, j int) bool {
if o[i].CreationTimestamp.Equal(o[j].CreationTimestamp) {
if o[i].CreationTimestamp.Equal(&o[j].CreationTimestamp) {
return o[i].Name < o[j].Name
}
return o[i].CreationTimestamp.Before(o[j].CreationTimestamp)
return o[i].CreationTimestamp.Before(&o[j].CreationTimestamp)
}
// ReplicaSetsByCreationTimestamp sorts a list of ReplicaSet by creation timestamp, using their names as a tie breaker.
@ -853,10 +853,10 @@ type ReplicaSetsByCreationTimestamp []*extensions.ReplicaSet
func (o ReplicaSetsByCreationTimestamp) Len() int { return len(o) }
func (o ReplicaSetsByCreationTimestamp) Swap(i, j int) { o[i], o[j] = o[j], o[i] }
func (o ReplicaSetsByCreationTimestamp) Less(i, j int) bool {
if o[i].CreationTimestamp.Equal(o[j].CreationTimestamp) {
if o[i].CreationTimestamp.Equal(&o[j].CreationTimestamp) {
return o[i].Name < o[j].Name
}
return o[i].CreationTimestamp.Before(o[j].CreationTimestamp)
return o[i].CreationTimestamp.Before(&o[j].CreationTimestamp)
}
// ReplicaSetsBySizeOlder sorts a list of ReplicaSet by size in descending order, using their creation timestamp or name as a tie breaker.

View File

@ -251,9 +251,9 @@ func (o byJobStartTime) Less(i, j int) bool {
return o[i].Status.StartTime != nil
}
if (*o[i].Status.StartTime).Equal(*o[j].Status.StartTime) {
if o[i].Status.StartTime.Equal(o[j].Status.StartTime) {
return o[i].Name < o[j].Name
}
return (*o[i].Status.StartTime).Before(*o[j].Status.StartTime)
return o[i].Status.StartTime.Before(o[j].Status.StartTime)
}

View File

@ -1366,10 +1366,10 @@ func (o byCreationTimestamp) Len() int { return len(o) }
func (o byCreationTimestamp) Swap(i, j int) { o[i], o[j] = o[j], o[i] }
func (o byCreationTimestamp) Less(i, j int) bool {
if o[i].CreationTimestamp.Equal(o[j].CreationTimestamp) {
if o[i].CreationTimestamp.Equal(&o[j].CreationTimestamp) {
return o[i].Name < o[j].Name
}
return o[i].CreationTimestamp.Before(o[j].CreationTimestamp)
return o[i].CreationTimestamp.Before(&o[j].CreationTimestamp)
}
type podByCreationTimestamp []*v1.Pod
@ -1378,8 +1378,8 @@ func (o podByCreationTimestamp) Len() int { return len(o) }
func (o podByCreationTimestamp) Swap(i, j int) { o[i], o[j] = o[j], o[i] }
func (o podByCreationTimestamp) Less(i, j int) bool {
if o[i].CreationTimestamp.Equal(o[j].CreationTimestamp) {
if o[i].CreationTimestamp.Equal(&o[j].CreationTimestamp) {
return o[i].Name < o[j].Name
}
return o[i].CreationTimestamp.Before(o[j].CreationTimestamp)
return o[i].CreationTimestamp.Before(&o[j].CreationTimestamp)
}

View File

@ -685,8 +685,8 @@ func (o byCreationTimestamp) Len() int { return len(o) }
func (o byCreationTimestamp) Swap(i, j int) { o[i], o[j] = o[j], o[i] }
func (o byCreationTimestamp) Less(i, j int) bool {
if o[i].CreationTimestamp.Equal(o[j].CreationTimestamp) {
if o[i].CreationTimestamp.Equal(&o[j].CreationTimestamp) {
return o[i].Name < o[j].Name
}
return o[i].CreationTimestamp.Before(o[j].CreationTimestamp)
return o[i].CreationTimestamp.Before(&o[j].CreationTimestamp)
}

View File

@ -193,8 +193,8 @@ func (o byCreationTimestamp) Len() int { return len(o) }
func (o byCreationTimestamp) Swap(i, j int) { o[i], o[j] = o[j], o[i] }
func (o byCreationTimestamp) Less(i, j int) bool {
if o[i].CreationTimestamp.Equal(o[j].CreationTimestamp) {
if o[i].CreationTimestamp.Equal(&o[j].CreationTimestamp) {
return o[i].Name < o[j].Name
}
return o[i].CreationTimestamp.Before(o[j].CreationTimestamp)
return o[i].CreationTimestamp.Before(&o[j].CreationTimestamp)
}

View File

@ -86,10 +86,10 @@ func (o OverlappingControllers) Len() int { return len(o) }
func (o OverlappingControllers) Swap(i, j int) { o[i], o[j] = o[j], o[i] }
func (o OverlappingControllers) Less(i, j int) bool {
if o[i].CreationTimestamp.Equal(o[j].CreationTimestamp) {
if o[i].CreationTimestamp.Equal(&o[j].CreationTimestamp) {
return o[i].Name < o[j].Name
}
return o[i].CreationTimestamp.Before(o[j].CreationTimestamp)
return o[i].CreationTimestamp.Before(&o[j].CreationTimestamp)
}
func calculateStatus(rc *v1.ReplicationController, filteredPods []*v1.Pod, manageReplicasErr error) v1.ReplicationControllerStatus {

View File

@ -50,10 +50,10 @@ func (o overlappingStatefulSets) Len() int { return len(o) }
func (o overlappingStatefulSets) Swap(i, j int) { o[i], o[j] = o[j], o[i] }
func (o overlappingStatefulSets) Less(i, j int) bool {
if o[i].CreationTimestamp.Equal(o[j].CreationTimestamp) {
if o[i].CreationTimestamp.Equal(&o[j].CreationTimestamp) {
return o[i].Name < o[j].Name
}
return o[i].CreationTimestamp.Before(o[j].CreationTimestamp)
return o[i].CreationTimestamp.Before(&o[j].CreationTimestamp)
}
// statefulPodRegex is a regular expression that extracts the parent StatefulSet and ordinal from the Name of a Pod

View File

@ -188,7 +188,8 @@ func isLess(i, j reflect.Value) (bool, error) {
// sort metav1.Time
in := i.Interface()
if t, ok := in.(metav1.Time); ok {
return t.Before(j.Interface().(metav1.Time)), nil
time := j.Interface().(metav1.Time)
return t.Before(&time), nil
}
// fallback to the fields comparison
for idx := 0; idx < i.NumField(); idx++ {

View File

@ -214,7 +214,7 @@ func TestChangedStatusKeepsStartTime(t *testing.T) {
t.Errorf("StartTime should not be zero")
}
expected := now.Rfc3339Copy()
if !finalStatus.StartTime.Equal(expected) {
if !finalStatus.StartTime.Equal(&expected) {
t.Errorf("Expected %v, but got %v", expected, finalStatus.StartTime)
}
}
@ -244,7 +244,7 @@ func TestChangedStatusUpdatesLastTransitionTime(t *testing.T) {
if newReadyCondition.LastTransitionTime.IsZero() {
t.Errorf("Unexpected: last transition time not set")
}
if newReadyCondition.LastTransitionTime.Before(oldReadyCondition.LastTransitionTime) {
if newReadyCondition.LastTransitionTime.Before(&oldReadyCondition.LastTransitionTime) {
t.Errorf("Unexpected: new transition time %s, is before old transition time %s", newReadyCondition.LastTransitionTime, oldReadyCondition.LastTransitionTime)
}
}
@ -283,7 +283,7 @@ func TestUnchangedStatusPreservesLastTransitionTime(t *testing.T) {
if newReadyCondition.LastTransitionTime.IsZero() {
t.Errorf("Unexpected: last transition time not set")
}
if !oldReadyCondition.LastTransitionTime.Equal(newReadyCondition.LastTransitionTime) {
if !oldReadyCondition.LastTransitionTime.Equal(&newReadyCondition.LastTransitionTime) {
t.Errorf("Unexpected: new transition time %s, is not equal to old transition time %s", newReadyCondition.LastTransitionTime, oldReadyCondition.LastTransitionTime)
}
}

View File

@ -44,7 +44,7 @@ func (s PodsByCreationTime) Swap(i, j int) {
}
func (s PodsByCreationTime) Less(i, j int) bool {
return s[i].CreationTimestamp.Before(s[j].CreationTimestamp)
return s[i].CreationTimestamp.Before(&s[j].CreationTimestamp)
}
// ByImageSize makes an array of images sortable by their size in descending

View File

@ -288,7 +288,7 @@ func ValidateObjectMetaAccessorUpdate(newMeta, oldMeta metav1.Object, fldPath *f
if newMeta.GetDeletionGracePeriodSeconds() != nil && (oldMeta.GetDeletionGracePeriodSeconds() == nil || *newMeta.GetDeletionGracePeriodSeconds() != *oldMeta.GetDeletionGracePeriodSeconds()) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("deletionGracePeriodSeconds"), newMeta.GetDeletionGracePeriodSeconds(), "field is immutable; may only be changed via deletion"))
}
if newMeta.GetDeletionTimestamp() != nil && (oldMeta.GetDeletionTimestamp() == nil || !newMeta.GetDeletionTimestamp().Equal(*oldMeta.GetDeletionTimestamp())) {
if newMeta.GetDeletionTimestamp() != nil && (oldMeta.GetDeletionTimestamp() == nil || !newMeta.GetDeletionTimestamp().Equal(oldMeta.GetDeletionTimestamp())) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("deletionTimestamp"), newMeta.GetDeletionTimestamp(), "field is immutable; may only be changed via deletion"))
}

View File

@ -40,8 +40,8 @@ type MicroTime struct {
// DeepCopy returns a deep-copy of the MicroTime value. The underlying time.Time
// type is effectively immutable in the time API, so it is safe to
// copy-by-assign, despite the presence of (unexported) Pointer fields.
func (t MicroTime) DeepCopy() MicroTime {
return t
func (t *MicroTime) DeepCopyInto(out *MicroTime) {
*out = *t
}
// String returns the representation of the time.
@ -74,22 +74,22 @@ func (t *MicroTime) IsZero() bool {
}
// Before reports whether the time instant t is before u.
func (t MicroTime) Before(u MicroTime) bool {
func (t *MicroTime) Before(u *MicroTime) bool {
return t.Time.Before(u.Time)
}
// Equal reports whether the time instant t is equal to u.
func (t MicroTime) Equal(u MicroTime) bool {
func (t *MicroTime) Equal(u *MicroTime) bool {
return t.Time.Equal(u.Time)
}
// BeforeTime reports whether the time instant t is before second-lever precision u.
func (t MicroTime) BeforeTime(u Time) bool {
func (t *MicroTime) BeforeTime(u *Time) bool {
return t.Time.Before(u.Time)
}
// EqualTime reports whether the time instant t is equal to second-lever precision u.
func (t MicroTime) EqualTime(u Time) bool {
func (t *MicroTime) EqualTime(u *Time) bool {
return t.Time.Equal(u.Time)
}

View File

@ -74,12 +74,12 @@ func (t *Time) IsZero() bool {
}
// Before reports whether the time instant t is before u.
func (t Time) Before(u Time) bool {
func (t *Time) Before(u *Time) bool {
return t.Time.Before(u.Time)
}
// Equal reports whether the time instant t is equal to u.
func (t Time) Equal(u Time) bool {
func (t *Time) Equal(u *Time) bool {
return t.Time.Equal(u.Time)
}

View File

@ -778,10 +778,14 @@ func (in *ListOptions) DeepCopyObject() runtime.Object {
}
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *MicroTime) DeepCopyInto(out *MicroTime) {
*out = in.DeepCopy()
return
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MicroTime.
func (in *MicroTime) DeepCopy() *MicroTime {
if in == nil {
return nil
}
out := new(MicroTime)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

View File

@ -206,11 +206,11 @@ func TestUnstructuredGetters(t *testing.T) {
t.Errorf("GetSelfLink() = %s, want %s", got, want)
}
if got, want := unstruct.GetCreationTimestamp(), metav1.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC); !got.Equal(want) {
if got, want := unstruct.GetCreationTimestamp(), metav1.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC); !got.Equal(&want) {
t.Errorf("GetCreationTimestamp() = %s, want %s", got, want)
}
if got, want := unstruct.GetDeletionTimestamp(), metav1.Date(2010, time.November, 10, 23, 0, 0, 0, time.UTC); got == nil || !got.Equal(want) {
if got, want := unstruct.GetDeletionTimestamp(), metav1.Date(2010, time.November, 10, 23, 0, 0, 0, time.UTC); got == nil || !got.Equal(&want) {
t.Errorf("GetDeletionTimestamp() = %s, want %s", got, want)
}

View File

@ -1044,7 +1044,7 @@ func (t *Tester) testDeleteGracefulShorten(obj runtime.Object, createFn CreateFu
}
objectMeta = t.getObjectMetaOrFail(object)
if objectMeta.GetDeletionTimestamp() == nil || objectMeta.GetDeletionGracePeriodSeconds() == nil ||
*objectMeta.GetDeletionGracePeriodSeconds() != expectedGrace || !objectMeta.GetDeletionTimestamp().Before(deletionTimestamp) {
*objectMeta.GetDeletionGracePeriodSeconds() != expectedGrace || !objectMeta.GetDeletionTimestamp().Before(&deletionTimestamp) {
t.Errorf("unexpected deleted meta: %#v", objectMeta)
}
}

View File

@ -102,7 +102,7 @@ func validateEvent(messagePrefix string, actualEvent *v1.Event, expectedEvent *v
}
actualFirstTimestamp := recvEvent.FirstTimestamp
actualLastTimestamp := recvEvent.LastTimestamp
if actualFirstTimestamp.Equal(actualLastTimestamp) {
if actualFirstTimestamp.Equal(&actualLastTimestamp) {
if expectCompression {
t.Errorf("%v - FirstTimestamp (%q) and LastTimestamp (%q) must be different to indicate event compression happened, but were the same. Actual Event: %#v", messagePrefix, actualFirstTimestamp, actualLastTimestamp, recvEvent)
}

View File

@ -618,7 +618,7 @@ func (r *resourceCollector) collectStats(oldStatsMap map[string]*stats.Container
}
if oldStats, ok := oldStatsMap[name]; ok {
if oldStats.CPU.Time.Equal(cStats.CPU.Time) {
if oldStats.CPU.Time.Equal(&cStats.CPU.Time) {
// No change -> skip this stat.
continue
}

View File

@ -2282,10 +2282,10 @@ func (o byFirstTimestamp) Len() int { return len(o) }
func (o byFirstTimestamp) Swap(i, j int) { o[i], o[j] = o[j], o[i] }
func (o byFirstTimestamp) Less(i, j int) bool {
if o[i].FirstTimestamp.Equal(o[j].FirstTimestamp) {
if o[i].FirstTimestamp.Equal(&o[j].FirstTimestamp) {
return o[i].InvolvedObject.Name < o[j].InvolvedObject.Name
}
return o[i].FirstTimestamp.Before(o[j].FirstTimestamp)
return o[i].FirstTimestamp.Before(&o[j].FirstTimestamp)
}
func dumpAllPodInfo(c clientset.Interface) {

View File

@ -582,7 +582,7 @@ var _ = SIGDescribe("Density", func() {
var startTime metav1.Time
for _, cs := range p.Status.ContainerStatuses {
if cs.State.Running != nil {
if startTime.Before(cs.State.Running.StartedAt) {
if startTime.Before(&cs.State.Running.StartedAt) {
startTime = cs.State.Running.StartedAt
}
}