diff --git a/pkg/registry/core/persistentvolume/strategy.go b/pkg/registry/core/persistentvolume/strategy.go index d33a3f0a925..515a9b76869 100644 --- a/pkg/registry/core/persistentvolume/strategy.go +++ b/pkg/registry/core/persistentvolume/strategy.go @@ -71,7 +71,7 @@ func (persistentvolumeStrategy) PrepareForCreate(ctx context.Context, obj runtim if utilfeature.DefaultFeatureGate.Enabled(features.PersistentVolumeLastPhaseTransitionTime) { pv.Status.Phase = api.VolumePending - now := nowFunc() + now := NowFunc() pv.Status.LastPhaseTransitionTime = &now } @@ -143,7 +143,7 @@ func (persistentvolumeStatusStrategy) GetResetFields() map[fieldpath.APIVersion] 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 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)): // phase changed and client didn't set or didn't change the transition time - now := nowFunc() + now := NowFunc() newPv.Status.LastPhaseTransitionTime = &now } } diff --git a/pkg/registry/core/persistentvolume/strategy_test.go b/pkg/registry/core/persistentvolume/strategy_test.go index e7d9794b5fe..c5ca9d07110 100644 --- a/pkg/registry/core/persistentvolume/strategy_test.go +++ b/pkg/registry/core/persistentvolume/strategy_test.go @@ -46,9 +46,9 @@ func TestStatusUpdate(t *testing.T) { now := metav1.Now() origin := metav1.NewTime(now.Add(time.Hour)) later := metav1.NewTime(now.Add(time.Hour * 2)) - nowFunc = func() metav1.Time { return now } + NowFunc = func() metav1.Time { return now } defer func() { - nowFunc = metav1.Now + NowFunc = metav1.Now }() tests := []struct { name string @@ -376,9 +376,9 @@ func TestStatusUpdate(t *testing.T) { func TestStatusCreate(t *testing.T) { now := metav1.Now() - nowFunc = func() metav1.Time { return now } + NowFunc = func() metav1.Time { return now } defer func() { - nowFunc = metav1.Now + NowFunc = metav1.Now }() tests := []struct { name string