Skip to content

Commit 9bbdd82

Browse files
committed
LowNodeUtilization: fall back to the list of protected namespaces as excluded when a list of included namespace is specified
LowNodeUtilization does not support namespace inclusion. Thus, the list of excluded namespace needs to fall back to the list of protected namespace instead of not setting ommiting the namespace inclusion.
1 parent 78b78b9 commit 9bbdd82

File tree

4 files changed

+101
-6
lines changed

4 files changed

+101
-6
lines changed

pkg/operator/target_config_reconciler.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ func softTopologyAndDuplicatesProfile(profileCustomizations *deschedulerv1.Profi
558558
return profile, err
559559
}
560560

561-
func lifecycleAndUtilizationProfile(profileCustomizations *deschedulerv1.ProfileCustomizations, includedNamespaces, excludedNamespaces []string, ignorePVCPods, evictLocalStoragePods bool) (*v1alpha2.DeschedulerProfile, error) {
561+
func lifecycleAndUtilizationProfile(profileCustomizations *deschedulerv1.ProfileCustomizations, includedNamespaces, excludedNamespaces, protectedNamespaces []string, ignorePVCPods, evictLocalStoragePods bool) (*v1alpha2.DeschedulerProfile, error) {
562562
profile := &v1alpha2.DeschedulerProfile{
563563
Name: string(deschedulerv1.LifecycleAndUtilization),
564564
PluginConfigs: []v1alpha2.PluginConfig{
@@ -630,7 +630,12 @@ func lifecycleAndUtilizationProfile(profileCustomizations *deschedulerv1.Profile
630630
}
631631
if len(includedNamespaces) > 0 {
632632
// log a warning if user tries to enable ns inclusion with a profile that activates LowNodeUtilization
633-
klog.Warning("LowNodeUtilization is enabled, however it does not support namespace inclusion. Namespace inclusion will only be considered by other strategies (like RemovePodsHavingTooManyRestarts and PodLifeTime)")
633+
klog.Warning("LowNodeUtilization is enabled, however it does not support namespace inclusion. Namespace inclusion will only be considered by other strategies (like RemovePodsHavingTooManyRestarts and PodLifeTime). Falling back to a list of excluded protected namespaces.")
634+
if len(excludedNamespaces) == 0 {
635+
profile.PluginConfigs[2].Args.Object.(*nodeutilization.LowNodeUtilizationArgs).EvictableNamespaces = &deschedulerapi.Namespaces{
636+
Exclude: protectedNamespaces,
637+
}
638+
}
634639
}
635640
if len(excludedNamespaces) > 0 {
636641
profile.PluginConfigs[2].Args.Object.(*nodeutilization.LowNodeUtilizationArgs).EvictableNamespaces = &deschedulerapi.Namespaces{
@@ -703,8 +708,8 @@ func lifecycleAndUtilizationProfile(profileCustomizations *deschedulerv1.Profile
703708
return profile, nil
704709
}
705710

706-
func longLifecycleProfile(profileCustomizations *deschedulerv1.ProfileCustomizations, includedNamespaces, excludedNamespaces []string, ignorePVCPods, evictLocalStoragePods bool) (*v1alpha2.DeschedulerProfile, error) {
707-
profile, err := lifecycleAndUtilizationProfile(profileCustomizations, includedNamespaces, excludedNamespaces, ignorePVCPods, evictLocalStoragePods)
711+
func longLifecycleProfile(profileCustomizations *deschedulerv1.ProfileCustomizations, includedNamespaces, excludedNamespaces, protectedNamespaces []string, ignorePVCPods, evictLocalStoragePods bool) (*v1alpha2.DeschedulerProfile, error) {
712+
profile, err := lifecycleAndUtilizationProfile(profileCustomizations, includedNamespaces, excludedNamespaces, protectedNamespaces, ignorePVCPods, evictLocalStoragePods)
708713
if err != nil {
709714
return profile, err
710715
}
@@ -907,11 +912,11 @@ func (c *TargetConfigReconciler) manageConfigMap(descheduler *deschedulerv1.Kube
907912
case deschedulerv1.SoftTopologyAndDuplicates:
908913
profile, err = softTopologyAndDuplicatesProfile(descheduler.Spec.ProfileCustomizations, includedNamespaces, excludedNamespaces, ignorePVCPods, evictLocalStoragePods)
909914
case deschedulerv1.LifecycleAndUtilization:
910-
profile, err = lifecycleAndUtilizationProfile(descheduler.Spec.ProfileCustomizations, includedNamespaces, excludedNamespaces, ignorePVCPods, evictLocalStoragePods)
915+
profile, err = lifecycleAndUtilizationProfile(descheduler.Spec.ProfileCustomizations, includedNamespaces, excludedNamespaces, c.protectedNamespaces, ignorePVCPods, evictLocalStoragePods)
911916
case deschedulerv1.EvictPodsWithLocalStorage, deschedulerv1.EvictPodsWithPVC:
912917
continue
913918
case deschedulerv1.DevPreviewLongLifecycle, deschedulerv1.LongLifecycle:
914-
profile, err = longLifecycleProfile(descheduler.Spec.ProfileCustomizations, includedNamespaces, excludedNamespaces, ignorePVCPods, evictLocalStoragePods)
919+
profile, err = longLifecycleProfile(descheduler.Spec.ProfileCustomizations, includedNamespaces, excludedNamespaces, c.protectedNamespaces, ignorePVCPods, evictLocalStoragePods)
915920
case deschedulerv1.CompactAndScale:
916921
profile, err = compactAndScaleProfile(descheduler.Spec.ProfileCustomizations, includedNamespaces, excludedNamespaces, ignorePVCPods, evictLocalStoragePods)
917922
default:

pkg/operator/target_config_reconciler_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,24 @@ func TestManageConfigMap(t *testing.T) {
127127
},
128128
err: fmt.Errorf("It is invalid to set both .spec.profileCustomizations.thresholdPriority and .spec.profileCustomizations.ThresholdPriorityClassName fields"),
129129
},
130+
{
131+
name: "LowNodeUtilizationIncludedNamespace",
132+
descheduler: &deschedulerv1.KubeDescheduler{
133+
Spec: deschedulerv1.KubeDeschedulerSpec{
134+
Profiles: []deschedulerv1.DeschedulerProfile{"LifecycleAndUtilization"},
135+
ProfileCustomizations: &deschedulerv1.ProfileCustomizations{
136+
DevLowNodeUtilizationThresholds: &deschedulerv1.LowThreshold,
137+
Namespaces: deschedulerv1.Namespaces{
138+
Included: []string{"includedNamespace"},
139+
},
140+
},
141+
},
142+
},
143+
want: &corev1.ConfigMap{
144+
TypeMeta: metav1.TypeMeta{APIVersion: "v1", Kind: "ConfigMap"},
145+
Data: map[string]string{"policy.yaml": string(bindata.MustAsset("assets/lowNodeUtilizationIncludedNamespace.yaml"))},
146+
},
147+
},
130148
{
131149
name: "LowNodeUtilizationLow",
132150
descheduler: &deschedulerv1.KubeDescheduler{

pkg/operator/testdata/assets/longLifecycleWithNamespaces.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ profiles:
1212
podRestartThreshold: 100
1313
name: RemovePodsHavingTooManyRestarts
1414
- args:
15+
evictableNamespaces:
16+
exclude:
17+
- kube-system
18+
- hypershift
19+
- openshift
20+
- openshift-kube-scheduler
1521
metricsUtilization:
1622
prometheus: {}
1723
targetThresholds:
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
apiVersion: descheduler/v1alpha2
2+
kind: DeschedulerPolicy
3+
metricsCollector: {}
4+
profiles:
5+
- name: LifecycleAndUtilization
6+
pluginConfig:
7+
- args:
8+
maxPodLifeTimeSeconds: 86400
9+
namespaces:
10+
include:
11+
- includedNamespace
12+
name: PodLifeTime
13+
- args:
14+
includingInitContainers: true
15+
namespaces:
16+
include:
17+
- includedNamespace
18+
podRestartThreshold: 100
19+
name: RemovePodsHavingTooManyRestarts
20+
- args:
21+
evictableNamespaces:
22+
exclude:
23+
- kube-system
24+
- hypershift
25+
- openshift
26+
- openshift-kube-scheduler
27+
metricsUtilization:
28+
prometheus: {}
29+
targetThresholds:
30+
cpu: 30
31+
memory: 30
32+
pods: 30
33+
thresholds:
34+
cpu: 10
35+
memory: 10
36+
pods: 10
37+
name: LowNodeUtilization
38+
- args:
39+
ignorePvcPods: true
40+
name: DefaultEvictor
41+
plugins:
42+
balance:
43+
disabled: null
44+
enabled:
45+
- LowNodeUtilization
46+
deschedule:
47+
disabled: null
48+
enabled:
49+
- PodLifeTime
50+
- RemovePodsHavingTooManyRestarts
51+
filter:
52+
disabled: null
53+
enabled:
54+
- DefaultEvictor
55+
preevictionfilter:
56+
disabled: null
57+
enabled: null
58+
presort:
59+
disabled: null
60+
enabled: null
61+
sort:
62+
disabled: null
63+
enabled: null
64+
prometheus:
65+
authToken:
66+
secretReference: {}

0 commit comments

Comments
 (0)