mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-11 21:12:07 +00:00
Merge pull request #120627 from RomanBednar/pv-phase-transition-time-beta
graduate PersistentVolumeLastPhaseTransitionTime to beta in v1.29
This commit is contained in:
commit
6a4f08e7e6
@ -1047,7 +1047,7 @@ var defaultKubernetesFeatureGates = map[featuregate.Feature]featuregate.FeatureS
|
|||||||
|
|
||||||
PDBUnhealthyPodEvictionPolicy: {Default: true, PreRelease: featuregate.Beta},
|
PDBUnhealthyPodEvictionPolicy: {Default: true, PreRelease: featuregate.Beta},
|
||||||
|
|
||||||
PersistentVolumeLastPhaseTransitionTime: {Default: false, PreRelease: featuregate.Alpha},
|
PersistentVolumeLastPhaseTransitionTime: {Default: true, PreRelease: featuregate.Beta},
|
||||||
|
|
||||||
PodAndContainerStatsFromCRI: {Default: false, PreRelease: featuregate.Alpha},
|
PodAndContainerStatsFromCRI: {Default: false, PreRelease: featuregate.Alpha},
|
||||||
|
|
||||||
|
@ -17,8 +17,12 @@ limitations under the License.
|
|||||||
package storage
|
package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||||
|
featuregatetesting "k8s.io/component-base/featuregate/testing"
|
||||||
|
"k8s.io/kubernetes/pkg/features"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"context"
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
@ -32,6 +36,7 @@ import (
|
|||||||
"k8s.io/apiserver/pkg/registry/rest"
|
"k8s.io/apiserver/pkg/registry/rest"
|
||||||
etcd3testing "k8s.io/apiserver/pkg/storage/etcd3/testing"
|
etcd3testing "k8s.io/apiserver/pkg/storage/etcd3/testing"
|
||||||
api "k8s.io/kubernetes/pkg/apis/core"
|
api "k8s.io/kubernetes/pkg/apis/core"
|
||||||
|
"k8s.io/kubernetes/pkg/registry/core/persistentvolume"
|
||||||
"k8s.io/kubernetes/pkg/registry/registrytest"
|
"k8s.io/kubernetes/pkg/registry/registrytest"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -57,6 +62,7 @@ func newHostPathType(pathType string) *api.HostPathType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func validNewPersistentVolume(name string) *api.PersistentVolume {
|
func validNewPersistentVolume(name string) *api.PersistentVolume {
|
||||||
|
now := persistentvolume.NowFunc()
|
||||||
pv := &api.PersistentVolume{
|
pv := &api.PersistentVolume{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: name,
|
Name: name,
|
||||||
@ -72,9 +78,10 @@ func validNewPersistentVolume(name string) *api.PersistentVolume {
|
|||||||
PersistentVolumeReclaimPolicy: api.PersistentVolumeReclaimRetain,
|
PersistentVolumeReclaimPolicy: api.PersistentVolumeReclaimRetain,
|
||||||
},
|
},
|
||||||
Status: api.PersistentVolumeStatus{
|
Status: api.PersistentVolumeStatus{
|
||||||
Phase: api.VolumePending,
|
Phase: api.VolumePending,
|
||||||
Message: "bar",
|
Message: "bar",
|
||||||
Reason: "foo",
|
Reason: "foo",
|
||||||
|
LastPhaseTransitionTime: &now,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return pv
|
return pv
|
||||||
@ -166,6 +173,7 @@ func TestWatch(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateStatus(t *testing.T) {
|
func TestUpdateStatus(t *testing.T) {
|
||||||
|
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PersistentVolumeLastPhaseTransitionTime, true)()
|
||||||
storage, statusStorage, server := newStorage(t)
|
storage, statusStorage, server := newStorage(t)
|
||||||
defer server.Terminate(t)
|
defer server.Terminate(t)
|
||||||
defer storage.Store.DestroyFunc()
|
defer storage.Store.DestroyFunc()
|
||||||
@ -177,12 +185,19 @@ func TestUpdateStatus(t *testing.T) {
|
|||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pvStartTimestamp, err := getPhaseTranstitionTime(ctx, pvStart.Name, storage)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
pvIn := &api.PersistentVolume{
|
pvIn := &api.PersistentVolume{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
},
|
},
|
||||||
Status: api.PersistentVolumeStatus{
|
Status: api.PersistentVolumeStatus{
|
||||||
Phase: api.VolumeBound,
|
Phase: api.VolumeBound,
|
||||||
|
// Set the same timestamp as original PV so this won't get updated on phase change breaking DeepEqual() later in test.
|
||||||
|
LastPhaseTransitionTime: pvStartTimestamp,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,6 +216,14 @@ func TestUpdateStatus(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getPhaseTranstitionTime(ctx context.Context, pvName string, storage *REST) (*metav1.Time, error) {
|
||||||
|
obj, err := storage.Get(ctx, pvName, &metav1.GetOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return obj.(*api.PersistentVolume).Status.LastPhaseTransitionTime, nil
|
||||||
|
}
|
||||||
|
|
||||||
func TestShortNames(t *testing.T) {
|
func TestShortNames(t *testing.T) {
|
||||||
storage, _, server := newStorage(t)
|
storage, _, server := newStorage(t)
|
||||||
defer server.Terminate(t)
|
defer server.Terminate(t)
|
||||||
|
@ -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