Skip to content

Commit 73d3fab

Browse files
authored
[e2e] test softtainter (#495)
* [BUG] fix softtainter cleanup When running in the cleanup mode, LowNodeUtilizationArgs can be completely missing from the Descheduler policy. Let's ignore it to try completing the softtaints cleanup. Signed-off-by: Simone Tiraboschi <[email protected]> * [BUG] make softtainter VAP stricter on taint effect Signed-off-by: Simone Tiraboschi <[email protected]> * Refactor test/e2e/operator_test.go Refactor test/e2e/operator_test.go to make adding more tests in the future. easier. Signed-off-by: Simone Tiraboschi <[email protected]> * [e2e] test softtainter deployment Cover also softtainter depployment and its cleanup in e2e tests. Signed-off-by: Simone Tiraboschi <[email protected]> * [e2e] test softtainter VAP Cover also softtainter ValidatingAdmissionPolicy trying to adde and remove allowed and not allowed taints impersonating softtainer SA. Signed-off-by: Simone Tiraboschi <[email protected]> * Address review comments Signed-off-by: Simone Tiraboschi <[email protected]> --------- Signed-off-by: Simone Tiraboschi <[email protected]>
1 parent 9e2f80d commit 73d3fab

File tree

5 files changed

+608
-98
lines changed

5 files changed

+608
-98
lines changed

bindata/assets/kube-descheduler/softtaintervalidatingadmissionpolicy.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,18 @@ spec:
2020
variables:
2121
- name: "deschedulerTaintPrefix"
2222
expression: "'descheduler.openshift.io'"
23+
- name: "deschedulerTaintEffect"
24+
expression: "'PreferNoSchedule'"
2325
- name: "oldNonDeschedulerTaints"
24-
expression: "has(oldObject.spec.taints) ? oldObject.spec.taints.filter(t, !t.key.contains(variables.deschedulerTaintPrefix)) : []"
26+
expression: "has(oldObject.spec.taints) ? oldObject.spec.taints.filter(t, !t.key.contains(variables.deschedulerTaintPrefix) || t.effect != variables.deschedulerTaintEffect) : []"
2527
- name: "oldTaints"
2628
expression: "has(oldObject.spec.taints) ? oldObject.spec.taints : []"
2729
- name: "newNonDeschedulerTaints"
28-
expression: "has(object.spec.taints) ? object.spec.taints.filter(t, !t.key.contains(variables.deschedulerTaintPrefix)) : []"
30+
expression: "has(object.spec.taints) ? object.spec.taints.filter(t, !t.key.contains(variables.deschedulerTaintPrefix) || t.effect != variables.deschedulerTaintEffect) : []"
2931
- name: "newTaints"
3032
expression: "has(object.spec.taints) ? object.spec.taints : []"
3133
- name: "newDeschedulerTaints"
32-
expression: "has(object.spec.taints) ? object.spec.taints.filter(t, t.key.contains(variables.deschedulerTaintPrefix)) : []"
34+
expression: "has(object.spec.taints) ? object.spec.taints.filter(t, t.key.contains(variables.deschedulerTaintPrefix) && t.effect == variables.deschedulerTaintEffect) : []"
3335
validations:
3436
- expression: |
3537
oldObject.metadata.filter(k, k != "resourceVersion" && k != "generation" && k != "managedFields").all(k, k in object.metadata) &&

pkg/softtainter/softtainter.go

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ type softTainterArgs struct {
5050
useDeviationThresholds bool
5151
thresholds api.ResourceThresholds
5252
targetThresholds api.ResourceThresholds
53-
applySoftTaints bool
5453
mode desv1.Mode
5554
}
5655

@@ -108,6 +107,39 @@ func (st *softTainter) Reconcile(ctx context.Context, request reconcile.Request)
108107
}
109108
st.resyncPeriod = time.Duration(*des.Spec.DeschedulingIntervalSeconds) * time.Second
110109

110+
nodeSelector := labels.Everything()
111+
if policy.NodeSelector != nil {
112+
sel, err := labels.Parse(*policy.NodeSelector)
113+
if err != nil {
114+
return reconcile.Result{}, err
115+
}
116+
nodeSelector = sel
117+
}
118+
119+
nl := corev1.NodeList{}
120+
err = st.client.List(ctx, &nl, &client.ListOptions{LabelSelector: nodeSelector})
121+
if err != nil {
122+
return reconcile.Result{}, err
123+
}
124+
nodeList := make([]*corev1.Node, len(nl.Items))
125+
for i, node := range nl.Items {
126+
nodeList[i] = &node
127+
}
128+
129+
enableSoftTainter := false
130+
if des.Spec.ProfileCustomizations != nil && des.Spec.ProfileCustomizations.DevEnableSoftTainter {
131+
enableSoftTainter = true
132+
}
133+
134+
if !enableSoftTainter {
135+
logger.Info("SoftTainter is disabled, cleaning up eventual leftover taints")
136+
err = st.cleanAllSoftTaints(ctx, nodeList)
137+
if err != nil {
138+
return reconcile.Result{}, err
139+
}
140+
return reconcile.Result{RequeueAfter: st.resyncPeriod}, nil
141+
}
142+
111143
var lnargs *nodeutilization.LowNodeUtilizationArgs
112144

113145
for _, p := range policy.Profiles {
@@ -124,17 +156,10 @@ func (st *softTainter) Reconcile(ctx context.Context, request reconcile.Request)
124156
logger.Error(err, "reconciliation failed")
125157
return reconcile.Result{}, err
126158
}
127-
128-
enableSoftTainter := false
129-
if des.Spec.ProfileCustomizations != nil && des.Spec.ProfileCustomizations.DevEnableSoftTainter {
130-
enableSoftTainter = true
131-
}
132-
133159
st.args = &softTainterArgs{
134160
useDeviationThresholds: lnargs.UseDeviationThresholds,
135161
thresholds: lnargs.Thresholds,
136162
targetThresholds: lnargs.TargetThresholds,
137-
applySoftTaints: enableSoftTainter,
138163
mode: des.Spec.Mode,
139164
}
140165

@@ -172,37 +197,10 @@ func (st *softTainter) Reconcile(ctx context.Context, request reconcile.Request)
172197

173198
st.resourceNames = getResourceNames(st.args.thresholds)
174199

175-
nodeSelector := labels.Everything()
176-
if policy.NodeSelector != nil {
177-
sel, err := labels.Parse(*policy.NodeSelector)
178-
if err != nil {
179-
return reconcile.Result{}, err
180-
}
181-
nodeSelector = sel
182-
}
183-
184-
nl := corev1.NodeList{}
185-
err = st.client.List(ctx, &nl, &client.ListOptions{LabelSelector: nodeSelector})
200+
err = st.syncSoftTaints(ctx, nodeList)
186201
if err != nil {
187202
return reconcile.Result{}, err
188203
}
189-
nodeList := make([]*corev1.Node, len(nl.Items))
190-
for i, node := range nl.Items {
191-
nodeList[i] = &node
192-
}
193-
194-
if st.args.applySoftTaints {
195-
err = st.syncSoftTaints(ctx, nodeList)
196-
if err != nil {
197-
return reconcile.Result{}, err
198-
}
199-
} else {
200-
logger.Info("SoftTainter is disabled, cleaning up eventual leftover taints")
201-
err = st.cleanAllSoftTaints(ctx, nodeList)
202-
if err != nil {
203-
return reconcile.Result{}, err
204-
}
205-
}
206204
return reconcile.Result{RequeueAfter: st.resyncPeriod}, nil
207205
}
208206

test/e2e/bindata/assets/00_kube-descheduler-operator-crd.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ spec:
117117
- Low
118118
- Medium
119119
- High
120+
- AsymmetricLow
121+
- AsymmetricMedium
122+
- AsymmetricHigh
120123
- ""
121124
type: string
122125
devEnableEvictionsInBackground:
@@ -125,6 +128,12 @@ spec:
125128
The EvictionsInBackground alpha feature is a subject to change.
126129
Currently provided as an experimental feature.
127130
type: boolean
131+
devEnableSoftTainter:
132+
description: |-
133+
DevEnableSoftTainter enables SoftTainter alpha feature.
134+
The EnableSoftTainter alpha feature is a subject to change.
135+
Currently provided as an experimental feature.
136+
type: boolean
128137
devHighNodeUtilizationThresholds:
129138
description: |-
130139
devHighNodeUtilizationThresholds enumerates thresholds for node utilization levels.
@@ -137,7 +146,7 @@ spec:
137146
- ""
138147
type: string
139148
devLowNodeUtilizationThresholds:
140-
description: LowNodeUtilizationThresholds enumerates predefined
149+
description: DevLowNodeUtilizationThresholds enumerates predefined
141150
experimental thresholds
142151
enum:
143152
- Low
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: operator.openshift.io/v1
2+
kind: KubeDescheduler
3+
metadata:
4+
name: cluster
5+
namespace: openshift-kube-descheduler-operator
6+
spec:
7+
managementState: Managed
8+
deschedulingIntervalSeconds: 30
9+
mode: "Automatic"
10+
profiles:
11+
- DevKubeVirtRelieveAndMigrate
12+
profileCustomizations:
13+
podLifetime: 10s
14+
devEnableSoftTainter: true
15+
namespaces:
16+
included:
17+
- e2e-testdescheduling

0 commit comments

Comments
 (0)