Skip to content
This repository was archived by the owner on Jan 29, 2025. It is now read-only.

Commit 1e4739e

Browse files
madalazaruniemimu
authored andcommitted
Update TAS configuration script to handle K8s Scheduler v19 to v25
This commit will: - use control-plane as labels for TAS POD tolerations and NodeAffinity rules - update TAS deployment nodeAffinity& tolerations rules via the configuration-scheduler.sh - document changes to tolerations and nodeAffinity rules for TAS pods Signed-off-by: Madalina Lazar <[email protected]>
1 parent 865edf6 commit 1e4739e

File tree

3 files changed

+99
-95
lines changed

3 files changed

+99
-95
lines changed

telemetry-aware-scheduling/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ kubectl create secret tls extender-secret --cert /etc/kubernetes/<PATH_TO_CERT>
107107
must match the scheduler configuration, so use those files. If you instead want to use your own cert, you need to configure the scheduler to match.
108108
</details>&nbsp;
109109

110+
Note: From K8s v24+ the control-plane node labels have changed, from `node-role.kubernetes.io/master` to `node-role.kubernetes.io/control-plane`.
111+
This change affects how TAS gets deployed as the toleration and nodeAffinity rules have to be changed accordingly.
112+
In order to provide support for future versions of K8s, both of these rules have been changed to make use of the `node-role.kubernetes.io/control-plane`
113+
label [file](https://github.com/intel/platform-aware-scheduling/blob/master/telemetry-aware-scheduling/deploy/tas-deployment.yaml#L51-L62).
114+
If you are running a version of Kubernetes **older that v1.24**, you will need to change both rules in the file above to use
115+
`node-role.kubernetes.io/master`. To see how this can be done automatically please see [this shell script](deploy/extender-configuration/configure-scheduler.sh)
116+
110117
In order to deploy run:
111118

112119
``kubectl apply -f deploy/``

telemetry-aware-scheduling/deploy/extender-configuration/configure-scheduler.sh

Lines changed: 92 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ is_test=false
99
MANIFEST_FILE=/etc/kubernetes/manifests/kube-scheduler.yaml
1010
scheduler_config_file_path=deploy/extender-configuration/scheduler-config.yaml
1111
scheduler_config_destination=/etc/kubernetes
12+
TAS_DEPLOYMENT_FILE=deploy/tas-deployment.yaml
13+
SCHEDULER_VERSION=""
14+
KUBE_SCHEDULER_API_VERSION=""
15+
CONTROL_PLANE_NODE_AFINITY_LABEL="control-plane"
16+
NODE_AFFINITY_LABEL_KEY=$CONTROL_PLANE_NODE_AFINITY_LABEL
1217

1318
help() {
1419
echo "Usage: $(basename "$0") [-m PATH_TO_MANIFEST_FILE] [-f PATH_TO_CONFIGURATION_FILE] [-d CONFIGURATION_DESTINATION_FOLDER] [-th]" 2>&1
@@ -90,18 +95,58 @@ echo "Scheduler config file is located at: $scheduler_config_file_path"
9095
echo "Scheduler config destination will be: $scheduler_config_destination"
9196

9297
####### DETERMINE THE VERSION OF SCHEDULER USED IN THE K8S CLUSTER
93-
scheduler_image_version_22=22
94-
# The scheduling configuration API is currently (K8s v22) in the v1beta2 version. From K8s v23 onwards the api
95-
# will have version v1.
96-
scheduler_config_api_versions_v1beta2="v1beta2"
97-
scheduler_image=$( grep "image:" "$MANIFEST_FILE" | cut -d '.' -f 4 )
98-
99-
if [ -z "$scheduler_image" ]; then
100-
echo "Unable to retrieve the scheduler image value from manifest file. We got: $scheduler_image. Exiting..."
101-
exit 1
102-
fi
98+
get_scheduler_version() {
99+
scheduler_image=$( grep "image:" "$MANIFEST_FILE" | cut -d '.' -f 4 )
100+
101+
if [ -z "$scheduler_image" ]; then
102+
echo "Unable to retrieve the scheduler image value from manifest file. We got: $scheduler_image. Exiting..."
103+
exit 1
104+
fi
105+
106+
SCHEDULER_VERSION=$scheduler_image
107+
}
108+
109+
get_kube_scheduler_api_version() {
110+
[ -z "${SCHEDULER_VERSION}" ] && echo "### Empty value for K8s scheduler value: $SCHEDULER_VERSION. Exit..." && exit 1
111+
112+
scheduler_image_version_19=19
113+
scheduler_image_version_22=22
114+
scheduler_image_version_25=25
115+
scheduler_config_api_versions_v1beta1="v1beta1"
116+
scheduler_config_api_versions_v1beta2="v1beta2"
117+
scheduler_config_api_versions_v1="v1"
118+
119+
currentKubeSchedulerApiVersion=""
120+
if [ "$SCHEDULER_VERSION" -lt $scheduler_image_version_19 ]; then
121+
echo "E2E tests will not execute for K8s version older than $scheduler_image_version_19. Exit..."
122+
exit 1
123+
elif [ "$SCHEDULER_VERSION" -ge $scheduler_image_version_19 ] && [ "$SCHEDULER_VERSION" -lt $scheduler_image_version_22 ]; then
124+
currentKubeSchedulerApiVersion=$scheduler_config_api_versions_v1beta1
125+
elif [ "$SCHEDULER_VERSION" -ge $scheduler_image_version_22 ] && [ "$SCHEDULER_VERSION" -lt $scheduler_image_version_25 ]; then
126+
currentKubeSchedulerApiVersion=$scheduler_config_api_versions_v1beta2
127+
else
128+
currentKubeSchedulerApiVersion=$scheduler_config_api_versions_v1
129+
fi
103130

104-
echo "Version of the image used in the kube scheduler is: $scheduler_image"
131+
[ -z "${currentKubeSchedulerApiVersion}" ] && echo "Invalid API version for Kube Scheduler Configuration, got: $currentKubeSchedulerApiVersion. Exit..." && exit 1
132+
133+
KUBE_SCHEDULER_API_VERSION=$currentKubeSchedulerApiVersion
134+
}
135+
136+
set_node_affinity_expression_label_key() {
137+
scheduler_image_version_24=24
138+
[ -z "${SCHEDULER_VERSION}" ] && echo "### Unable to get K8s scheduler value, got $SCHEDULER_VERSION. Exit..." && exit 1
139+
if [ "$SCHEDULER_VERSION" -lt $scheduler_image_version_24 ]; then
140+
NODE_AFFINITY_LABEL_KEY="master"
141+
fi
142+
143+
[ -z "${NODE_AFFINITY_LABEL_KEY}" ] && echo "### Node affinity label key is empty: $NODE_AFFINITY_LABEL_KEY. Exit..." && exit 1
144+
}
145+
146+
get_scheduler_version
147+
echo "Version of the image used in the kube scheduler is: $SCHEDULER_VERSION"
148+
get_kube_scheduler_api_version
149+
echo "Version of the KubeScheduler API: $KUBE_SCHEDULER_API_VERSION"
105150

106151
####### CLEAN_UP MANIFEST FILE
107152
# In case the previous run of this script was partially successful or unsuccessful, we'd like to start from a clean
@@ -153,96 +198,50 @@ sed -e "/ volumes:/a\\
153198

154199
####### VERSION SPECIFIC MANIFEST_FILE CHANGES. These are necessary, but change according to the version of Kubernetes
155200

156-
## Before K8s v22 we will use the Policy API instead of the Scheduler Config API in order to setup the scheduler
157-
if [ "$scheduler_image" -lt $scheduler_image_version_22 ]; then
158-
echo "[IMPORTANT] Will proceed by using the Policy API to configure the scheduler extender. This API will be **DEPRECATED** from $scheduler_image_version_22 onwards"
159-
# Create the config map and the cluster role for the scheduler configuration.
160-
#The cluster role is needed in Kubeadm to ensure the scheduler can access configmaps.
161-
config_map=deploy/extender-configuration/scheduler-extender-configmap.yaml
162-
cluster_role=deploy/extender-configuration/configmap-getter.yaml
163-
164-
if ! $is_test ; then
165-
echo "Will proceed to generate the required K8s resources..."
166-
# check if the necessary files exist. If they don't the commands below will fail anyway
167-
if [ ! -f "$config_map" ]; then
168-
echo "Critical error: $config_map doesn't exist. Can't configure the scheduler for version $scheduler_image. Exiting..."
169-
exit 1
170-
fi
171-
if [ ! -f "$cluster_role" ]; then
172-
echo "Critical error: $cluster_role doesn't exist. Can't configure the scheduler for version $scheduler_image. Exiting..."
173-
exit 1
174-
fi
175-
176-
if ! kubectl apply -f $config_map; then
177-
echo "Unable to successfully apply $config_map. Will revert the change and exit."
178-
kubectl delete -f $config_map
179-
exit 1
180-
fi
181-
182-
if ! kubectl apply -f $cluster_role; then
183-
echo "Unable to successfully apply $cluster_role. Reverting the change... "
184-
kubectl delete -f $cluster_role
185-
echo " Reverting changes from $config_map as the resources from $cluster_role and $config_map are related."
186-
kubectl delete -f $config_map
187-
echo "Exit..."
188-
exit 1
189-
fi
190-
191-
# we aim to create this resource only once, as with the use of create the kubectl command below
192-
# will return an error if the resource in question already exists
193-
cluster_role_binding_result=$(kubectl get clusterrolebinding -A | grep scheduler-config-map)
194-
if [ -z "$cluster_role_binding_result" ]; then
195-
echo "Cluster role binding scheduler-config-map doesn't exist. Will proceed to create it..."
196-
#Add clusterrole binding - default binding edit - to give kube-scheduler access to configmaps in kube-system.
197-
kubectl create clusterrolebinding scheduler-config-map --clusterrole=configmapgetter --user=system:kube-scheduler
198-
fi
199-
fi
200-
## Add arguments to our kube-scheduler manifest. The arguments are:
201-
## 1) Policy configmap extender as arg to binary.
202-
## 2) Policy configmap namespace as arg to binary.
203-
sed -e "/ - kube-scheduler/a\\
204-
- --policy-configmap=scheduler-extender-policy\n - --policy-configmap-namespace=kube-system" "$MANIFEST_FILE" -i
205-
else
206-
echo "[IMPORTANT]Will proceed by using the kube-scheduler Configuration API instead for the scheduler extender. This API will be **USED** from $scheduler_image_version_22 onwards."
207-
currentKubeSchedulerApiVersion=$scheduler_config_api_versions_v1beta2
208-
echo "Kube Scheduler Configuration api version: $currentKubeSchedulerApiVersion"
209-
210-
if [ -z "$currentKubeSchedulerApiVersion" ]; then
211-
echo "Unable to determine the correct API version for Kube Scheduler Configuration. We got: $currentKubeSchedulerApiVersion. Exiting..."
212-
exit 1
213-
fi
201+
if [ -z "$KUBE_SCHEDULER_API_VERSION" ]; then
202+
echo "Invalid KubeSchedulerConfiguration API version: $KUBE_SCHEDULER_API_VERSION. Exiting..."
203+
exit 1
204+
fi
214205

215-
if [ ! -f "$scheduler_config_file_path" ]; then
216-
echo "Critical error: $scheduler_config_file_path doesn't exist. Can't configure the scheduler for version $scheduler_image. Exiting..."
217-
exit 1
218-
fi
219-
# update the scheduler's version
220-
sed -i "s/XVERSIONX/$currentKubeSchedulerApiVersion/g" "$scheduler_config_file_path"
206+
if [ ! -f "$scheduler_config_file_path" ]; then
207+
echo "Critical error: $scheduler_config_file_path doesn't exist. Can't configure the scheduler for version $scheduler_image. Exiting..."
208+
exit 1
209+
fi
210+
# update the scheduler's version
211+
sed -i "s/XVERSIONX/$KUBE_SCHEDULER_API_VERSION/g" "$scheduler_config_file_path"
221212

222-
if [ ! -d "$scheduler_config_destination" ]; then
223-
echo "Critical error. $scheduler_config_destination doesn't exist. Please check the cluster configuration. Exiting..."
224-
exit 1
225-
fi
213+
if [ ! -d "$scheduler_config_destination" ]; then
214+
echo "Critical error. $scheduler_config_destination doesn't exist. Please check the cluster configuration. Exiting..."
215+
exit 1
216+
fi
226217

227-
if ! $is_test ; then
228-
# copy the scheduler-config file to the expected folder
229-
echo "Will proceed to copy the scheduler configuration to its destination path: $scheduler_config_destination."
230-
cp "$scheduler_config_file_path" "$scheduler_config_destination"
231-
fi
218+
if ! $is_test ; then
219+
# copy the scheduler-config file to the expected folder
220+
echo "Will proceed to copy the scheduler configuration to its destination path: $scheduler_config_destination."
221+
cp "$scheduler_config_file_path" "$scheduler_config_destination"
222+
fi
232223

233-
# generate the new path of the config file
234-
scheduler_config_destination_path="$scheduler_config_destination/$scheduler_config_file"
224+
# generate the new path of the config file
225+
scheduler_config_destination_path="$scheduler_config_destination/$scheduler_config_file"
235226

236-
## Add arguments to our kube-scheduler manifest. The arguments are:
237-
## 1) Config file with the extender policy and other configuration
238-
## 2) Mount the configuration file to make sure it's accessible by K8s
239-
sed -e "/ - kube-scheduler/a\\
227+
## Add arguments to our kube-scheduler manifest. The arguments are:
228+
## 1) Config file with the extender policy and other configuration
229+
## 2) Mount the configuration file to make sure it's accessible by K8s
230+
sed -e "/ - kube-scheduler/a\\
240231
- --config=$scheduler_config_destination_path" "$MANIFEST_FILE" -i
241-
sed -e "/ volumeMounts:/a\\
232+
sed -e "/ volumeMounts:/a\\
242233
- mountPath: $scheduler_config_destination_path\n name: schedulerconfig\n readOnly: true" "$MANIFEST_FILE" -i
243-
sed -e "/ volumes:/a\\
234+
sed -e "/ volumes:/a\\
244235
- hostPath:\n path: $scheduler_config_destination_path\n name: schedulerconfig" "$MANIFEST_FILE" -i
245-
fi
246236

237+
### From v24 onwards the Kubernetes control plane labels have changes, node-role.kubernetes.io/master
238+
### has been replaced with node-role.kubernetes.io/control-plane. This means that the nodeAffinity nodeSelector
239+
### keys will be affected. The labels do not work together, so depending on the version of K8s used
240+
### we need to use one or the other
247241

242+
set_node_affinity_expression_label_key
243+
echo "Determined that the appropriate nodeSelector key would be: $NODE_AFFINITY_LABEL_KEY"
244+
if [ "$CONTROL_PLANE_NODE_AFINITY_LABEL" != "$NODE_AFFINITY_LABEL_KEY" ]; then
245+
sed "s/control-plane/$NODE_AFFINITY_LABEL_KEY/g" "$TAS_DEPLOYMENT_FILE" -i
246+
fi
248247

telemetry-aware-scheduling/deploy/tas-deployment.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ spec:
4949
secret:
5050
secretName: extender-secret
5151
tolerations:
52-
- key: node-role.kubernetes.io/master
53-
operator: Exists
5452
- key: node-role.kubernetes.io/control-plane
5553
operator: Exists
5654
affinity:

0 commit comments

Comments
 (0)