mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 23:47:50 +00:00
feat: cleanup PodPriority features gate
This commit is contained in:
@@ -712,122 +712,6 @@ func TestDropProcMount(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDropPodPriority(t *testing.T) {
|
||||
podPriority := int32(1000)
|
||||
podWithoutPriority := func() *api.Pod {
|
||||
return &api.Pod{
|
||||
Spec: api.PodSpec{
|
||||
Priority: nil,
|
||||
PriorityClassName: "",
|
||||
},
|
||||
}
|
||||
}
|
||||
podWithPriority := func() *api.Pod {
|
||||
return &api.Pod{
|
||||
Spec: api.PodSpec{
|
||||
Priority: &podPriority,
|
||||
PriorityClassName: "",
|
||||
},
|
||||
}
|
||||
}
|
||||
podWithPriorityClassOnly := func() *api.Pod {
|
||||
return &api.Pod{
|
||||
Spec: api.PodSpec{
|
||||
Priority: nil,
|
||||
PriorityClassName: "HighPriorityClass",
|
||||
},
|
||||
}
|
||||
}
|
||||
podWithBothPriorityFields := func() *api.Pod {
|
||||
return &api.Pod{
|
||||
Spec: api.PodSpec{
|
||||
Priority: &podPriority,
|
||||
PriorityClassName: "HighPriorityClass",
|
||||
},
|
||||
}
|
||||
}
|
||||
podInfo := []struct {
|
||||
description string
|
||||
hasPodPriority bool
|
||||
pod func() *api.Pod
|
||||
}{
|
||||
{
|
||||
description: "pod With no PodPriority fields set",
|
||||
hasPodPriority: false,
|
||||
pod: podWithoutPriority,
|
||||
},
|
||||
{
|
||||
description: "feature disabled and pod With PodPriority field set but class name not set",
|
||||
hasPodPriority: true,
|
||||
pod: podWithPriority,
|
||||
},
|
||||
{
|
||||
description: "feature disabled and pod With PodPriority ClassName field set but PortPriority not set",
|
||||
hasPodPriority: true,
|
||||
pod: podWithPriorityClassOnly,
|
||||
},
|
||||
{
|
||||
description: "feature disabled and pod With both PodPriority ClassName and PodPriority fields set",
|
||||
hasPodPriority: true,
|
||||
pod: podWithBothPriorityFields,
|
||||
},
|
||||
{
|
||||
description: "is nil",
|
||||
hasPodPriority: false,
|
||||
pod: func() *api.Pod { return nil },
|
||||
},
|
||||
}
|
||||
|
||||
for _, enabled := range []bool{true, false} {
|
||||
for _, oldPodInfo := range podInfo {
|
||||
for _, newPodInfo := range podInfo {
|
||||
oldPodHasPodPriority, oldPod := oldPodInfo.hasPodPriority, oldPodInfo.pod()
|
||||
newPodHasPodPriority, newPod := newPodInfo.hasPodPriority, newPodInfo.pod()
|
||||
if newPod == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
t.Run(fmt.Sprintf("feature enabled=%v, old pod %v, new pod %v", enabled, oldPodInfo.description, newPodInfo.description), func(t *testing.T) {
|
||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodPriority, enabled)()
|
||||
|
||||
var oldPodSpec *api.PodSpec
|
||||
if oldPod != nil {
|
||||
oldPodSpec = &oldPod.Spec
|
||||
}
|
||||
dropDisabledFields(&newPod.Spec, nil, oldPodSpec, nil)
|
||||
|
||||
// old pod should never be changed
|
||||
if !reflect.DeepEqual(oldPod, oldPodInfo.pod()) {
|
||||
t.Errorf("old pod changed: %v", diff.ObjectReflectDiff(oldPod, oldPodInfo.pod()))
|
||||
}
|
||||
|
||||
switch {
|
||||
case enabled || oldPodHasPodPriority:
|
||||
// new pod should not be changed if the feature is enabled, or if the old pod had PodPriority
|
||||
if !reflect.DeepEqual(newPod, newPodInfo.pod()) {
|
||||
t.Errorf("new pod changed: %v", diff.ObjectReflectDiff(newPod, newPodInfo.pod()))
|
||||
}
|
||||
case newPodHasPodPriority:
|
||||
// new pod should be changed
|
||||
if reflect.DeepEqual(newPod, newPodInfo.pod()) {
|
||||
t.Errorf("new pod was not changed")
|
||||
}
|
||||
// new pod should not have PodPriority
|
||||
if !reflect.DeepEqual(newPod, podWithoutPriority()) {
|
||||
t.Errorf("new pod had PodPriority: %v", diff.ObjectReflectDiff(newPod, podWithoutPriority()))
|
||||
}
|
||||
default:
|
||||
// new pod should not need to be changed
|
||||
if !reflect.DeepEqual(newPod, newPodInfo.pod()) {
|
||||
t.Errorf("new pod changed: %v", diff.ObjectReflectDiff(newPod, newPodInfo.pod()))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDropEmptyDirSizeLimit(t *testing.T) {
|
||||
sizeLimit := resource.MustParse("1Gi")
|
||||
podWithEmptyDirSizeLimit := func() *api.Pod {
|
||||
|
||||
Reference in New Issue
Block a user