mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-07 03:03:59 +00:00
export time function
NowFunc() has to be exported so it is available for testing in other packages.
This commit is contained in:
parent
9cfd96dbb5
commit
071a67d8c2
@ -71,7 +71,7 @@ func (persistentvolumeStrategy) PrepareForCreate(ctx context.Context, obj runtim
|
|||||||
|
|
||||||
if utilfeature.DefaultFeatureGate.Enabled(features.PersistentVolumeLastPhaseTransitionTime) {
|
if utilfeature.DefaultFeatureGate.Enabled(features.PersistentVolumeLastPhaseTransitionTime) {
|
||||||
pv.Status.Phase = api.VolumePending
|
pv.Status.Phase = api.VolumePending
|
||||||
now := nowFunc()
|
now := NowFunc()
|
||||||
pv.Status.LastPhaseTransitionTime = &now
|
pv.Status.LastPhaseTransitionTime = &now
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,7 +143,7 @@ func (persistentvolumeStatusStrategy) GetResetFields() map[fieldpath.APIVersion]
|
|||||||
return fields
|
return fields
|
||||||
}
|
}
|
||||||
|
|
||||||
var nowFunc = metav1.Now
|
var NowFunc = metav1.Now
|
||||||
|
|
||||||
// PrepareForUpdate sets the Spec field which is not allowed to be changed when updating a PV's Status
|
// PrepareForUpdate sets the Spec field which is not allowed to be changed when updating a PV's Status
|
||||||
func (persistentvolumeStatusStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
|
func (persistentvolumeStatusStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
|
||||||
@ -159,7 +159,7 @@ func (persistentvolumeStatusStrategy) PrepareForUpdate(ctx context.Context, obj,
|
|||||||
|
|
||||||
case oldPv.Status.Phase != newPv.Status.Phase && (newPv.Status.LastPhaseTransitionTime == nil || newPv.Status.LastPhaseTransitionTime.Equal(oldPv.Status.LastPhaseTransitionTime)):
|
case oldPv.Status.Phase != newPv.Status.Phase && (newPv.Status.LastPhaseTransitionTime == nil || newPv.Status.LastPhaseTransitionTime.Equal(oldPv.Status.LastPhaseTransitionTime)):
|
||||||
// phase changed and client didn't set or didn't change the transition time
|
// phase changed and client didn't set or didn't change the transition time
|
||||||
now := nowFunc()
|
now := NowFunc()
|
||||||
newPv.Status.LastPhaseTransitionTime = &now
|
newPv.Status.LastPhaseTransitionTime = &now
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,9 +46,9 @@ func TestStatusUpdate(t *testing.T) {
|
|||||||
now := metav1.Now()
|
now := metav1.Now()
|
||||||
origin := metav1.NewTime(now.Add(time.Hour))
|
origin := metav1.NewTime(now.Add(time.Hour))
|
||||||
later := metav1.NewTime(now.Add(time.Hour * 2))
|
later := metav1.NewTime(now.Add(time.Hour * 2))
|
||||||
nowFunc = func() metav1.Time { return now }
|
NowFunc = func() metav1.Time { return now }
|
||||||
defer func() {
|
defer func() {
|
||||||
nowFunc = metav1.Now
|
NowFunc = metav1.Now
|
||||||
}()
|
}()
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@ -376,9 +376,9 @@ func TestStatusUpdate(t *testing.T) {
|
|||||||
|
|
||||||
func TestStatusCreate(t *testing.T) {
|
func TestStatusCreate(t *testing.T) {
|
||||||
now := metav1.Now()
|
now := metav1.Now()
|
||||||
nowFunc = func() metav1.Time { return now }
|
NowFunc = func() metav1.Time { return now }
|
||||||
defer func() {
|
defer func() {
|
||||||
nowFunc = metav1.Now
|
NowFunc = metav1.Now
|
||||||
}()
|
}()
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
|
Loading…
Reference in New Issue
Block a user