mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 18:24:07 +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) {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user