Skip to content

Commit dc4cef9

Browse files
Kubevirt: Run Descheduler on node boot to rebalance cluster apps
Update_RunDeschedulerOnBoot will run the descheduler to evict pods from the edge node on boot. This is to allow rebalancing apps via re-scheduling them with an aim to meet affinity as specified in the pod config. This path includes a series of gates to ensure the destination node is available as a scheduling destination. - Wait for the kubernetes api to be available. - Wait until node is online and uncordoned. Signed-off-by: Andrew Durbin <[email protected]>
1 parent 0769a20 commit dc4cef9

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

pkg/kube/cluster-init.sh

+1
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,7 @@ fi
862862
check_kubeconfig_yaml_files
863863
check_and_remove_excessive_k3s_logs
864864
check_and_run_vnc
865+
Update_RunDeschedulerOnBoot
865866
wait_for_item "wait"
866867
sleep 15
867868
done

pkg/kube/cluster-update.sh

+55
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,61 @@
33
# Copyright (c) 2024 Zededa, Inc.
44
# SPDX-License-Identifier: Apache-2.0
55

6+
EdgeNodeInfoPath="/persist/status/zedagent/EdgeNodeInfo/global.json"
7+
COMP_UPDATE_PATH="/usr/bin/update-component"
8+
69
link_multus_into_k3s() {
710
ln -s /var/lib/cni/bin/multus /var/lib/rancher/k3s/data/current/bin/multus
811
}
12+
13+
# Update_RunDeschedulerOnBoot will run the descheduler to evict pods from the edge node
14+
# on boot. This is to allow rebalancing apps via re-scheduling them to requested node
15+
# affinity as specified in the pod config.
16+
Update_RunDeschedulerOnBoot() {
17+
# Currently only run once per boot
18+
if [ -f /tmp/descheduler-ran-onboot ]; then
19+
return
20+
fi
21+
22+
if [ ! -f $EdgeNodeInfoPath ]; then
23+
return
24+
fi
25+
# is api ready
26+
if ! update_isClusterReady; then
27+
return
28+
fi
29+
# Don't run unless it has been installed
30+
if [ ! descheduler_install ]; then
31+
return
32+
fi
33+
# node ready and allowing scheduling
34+
node=$(jq -r '.DeviceName' < $EdgeNodeInfoPath | tr -d '\n' | tr '[:upper:]' '[:lower:]')
35+
node_count_ready=$(kubectl get "node/${node}" | grep -v SchedulingDisabled | grep -cw Ready )
36+
if [ "$node_count_ready" -ne 1 ]; then
37+
return
38+
fi
39+
# Job lives persistently in cluster, cleanup after old runs
40+
if kubectl -n kube-system get job/descheduler-job; then
41+
kubectl -n kube-system delete job/descheduler-job
42+
fi
43+
kubectl apply -f /etc/descheduler-job.yaml
44+
touch /tmp/descheduler-ran-onboot
45+
}
46+
47+
update_isClusterReady() {
48+
if ! kubectl cluster-info; then
49+
return 1
50+
fi
51+
52+
if ! update_Helper_APIResponding; then
53+
return 1
54+
fi
55+
return 0
56+
}
57+
58+
update_Helper_APIResponding() {
59+
if $COMP_UPDATE_PATH --check-api-ready; then
60+
return 0
61+
fi
62+
return 1
63+
}

0 commit comments

Comments
 (0)