mirror of
https://github.com/kubernetes-sigs/descheduler.git
synced 2026-01-26 05:14:13 +01:00
refactor(defaultevictor_test): move newProtectedStorageClassesConfig to package level
Move the newProtectedStorageClassesConfig helper function from local scope to package level so it can be reused by both TestDefaultEvictorFilter and Test_protectedPVCStorageClasses, eliminating code duplication.
This commit is contained in:
@@ -68,6 +68,18 @@ func buildTestPod(name string, nodeName string, apply func(*v1.Pod)) *v1.Pod {
|
|||||||
return test.BuildTestPod(name, 400, 0, nodeName, apply)
|
return test.BuildTestPod(name, 400, 0, nodeName, apply)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newProtectedStorageClassesConfig(storageClassNames ...string) *PodProtectionsConfig {
|
||||||
|
protectedClasses := make([]ProtectedStorageClass, len(storageClassNames))
|
||||||
|
for i, name := range storageClassNames {
|
||||||
|
protectedClasses[i] = ProtectedStorageClass{Name: name}
|
||||||
|
}
|
||||||
|
return &PodProtectionsConfig{
|
||||||
|
PodsWithPVC: &PodsWithPVCConfig{
|
||||||
|
ProtectedStorageClasses: protectedClasses,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestDefaultEvictorPreEvictionFilter(t *testing.T) {
|
func TestDefaultEvictorPreEvictionFilter(t *testing.T) {
|
||||||
n1 := buildTestNode("node1", nil)
|
n1 := buildTestNode("node1", nil)
|
||||||
|
|
||||||
@@ -790,15 +802,7 @@ func TestDefaultEvictorFilter(t *testing.T) {
|
|||||||
},
|
},
|
||||||
podProtections: PodProtections{
|
podProtections: PodProtections{
|
||||||
ExtraEnabled: []PodProtection{PodsWithPVC},
|
ExtraEnabled: []PodProtection{PodsWithPVC},
|
||||||
Config: &PodProtectionsConfig{
|
Config: newProtectedStorageClassesConfig("standard"),
|
||||||
PodsWithPVC: &PodsWithPVCConfig{
|
|
||||||
ProtectedStorageClasses: []ProtectedStorageClass{
|
|
||||||
{
|
|
||||||
Name: "standard",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
pvcs: []*v1.PersistentVolumeClaim{
|
pvcs: []*v1.PersistentVolumeClaim{
|
||||||
test.BuildTestPVC("foo", "standard"),
|
test.BuildTestPVC("foo", "standard"),
|
||||||
@@ -815,15 +819,7 @@ func TestDefaultEvictorFilter(t *testing.T) {
|
|||||||
},
|
},
|
||||||
podProtections: PodProtections{
|
podProtections: PodProtections{
|
||||||
ExtraEnabled: []PodProtection{PodsWithPVC},
|
ExtraEnabled: []PodProtection{PodsWithPVC},
|
||||||
Config: &PodProtectionsConfig{
|
Config: newProtectedStorageClassesConfig("protected"),
|
||||||
PodsWithPVC: &PodsWithPVCConfig{
|
|
||||||
ProtectedStorageClasses: []ProtectedStorageClass{
|
|
||||||
{
|
|
||||||
Name: "protected",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
pvcs: []*v1.PersistentVolumeClaim{
|
pvcs: []*v1.PersistentVolumeClaim{
|
||||||
test.BuildTestPVC("foo", "unprotected"),
|
test.BuildTestPVC("foo", "unprotected"),
|
||||||
@@ -840,15 +836,7 @@ func TestDefaultEvictorFilter(t *testing.T) {
|
|||||||
},
|
},
|
||||||
podProtections: PodProtections{
|
podProtections: PodProtections{
|
||||||
ExtraEnabled: []PodProtection{PodsWithPVC},
|
ExtraEnabled: []PodProtection{PodsWithPVC},
|
||||||
Config: &PodProtectionsConfig{
|
Config: newProtectedStorageClassesConfig("protected"),
|
||||||
PodsWithPVC: &PodsWithPVCConfig{
|
|
||||||
ProtectedStorageClasses: []ProtectedStorageClass{
|
|
||||||
{
|
|
||||||
Name: "protected",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
pvcs: []*v1.PersistentVolumeClaim{},
|
pvcs: []*v1.PersistentVolumeClaim{},
|
||||||
result: false,
|
result: false,
|
||||||
@@ -878,15 +866,7 @@ func TestDefaultEvictorFilter(t *testing.T) {
|
|||||||
},
|
},
|
||||||
podProtections: PodProtections{
|
podProtections: PodProtections{
|
||||||
ExtraEnabled: []PodProtection{PodsWithPVC},
|
ExtraEnabled: []PodProtection{PodsWithPVC},
|
||||||
Config: &PodProtectionsConfig{
|
Config: newProtectedStorageClassesConfig("protected"),
|
||||||
PodsWithPVC: &PodsWithPVCConfig{
|
|
||||||
ProtectedStorageClasses: []ProtectedStorageClass{
|
|
||||||
{
|
|
||||||
Name: "protected",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
pvcs: []*v1.PersistentVolumeClaim{
|
pvcs: []*v1.PersistentVolumeClaim{
|
||||||
test.BuildTestPVC("protected", "protected"),
|
test.BuildTestPVC("protected", "protected"),
|
||||||
@@ -1161,14 +1141,7 @@ func Test_protectedPVCStorageClasses(t *testing.T) {
|
|||||||
name: "storage classes specified",
|
name: "storage classes specified",
|
||||||
args: &DefaultEvictorArgs{
|
args: &DefaultEvictorArgs{
|
||||||
PodProtections: PodProtections{
|
PodProtections: PodProtections{
|
||||||
Config: &PodProtectionsConfig{
|
Config: newProtectedStorageClassesConfig("sc1", "sc2"),
|
||||||
PodsWithPVC: &PodsWithPVCConfig{
|
|
||||||
ProtectedStorageClasses: []ProtectedStorageClass{
|
|
||||||
{Name: "sc1"},
|
|
||||||
{Name: "sc2"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: []ProtectedStorageClass{
|
expected: []ProtectedStorageClass{
|
||||||
|
|||||||
Reference in New Issue
Block a user