forked from konflux-ci/release-service-catalog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtkn_check_compute_resources.sh
More file actions
executable file
·72 lines (59 loc) · 2.73 KB
/
Copy pathtkn_check_compute_resources.sh
File metadata and controls
executable file
·72 lines (59 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env bash
# This file was created with assistance from the AI tool Cursor
set -euo pipefail
fail=0
echo Checking that computeResources are properly set for all steps in each modified managed or internal task
for file in ${CHANGED_FILES}; do
# Only process non test files in tasks/managed and tasks/internal
if [[ "$file" == */tests/* ]] || [[ ! "$file" =~ ^tasks/(managed|internal)/ ]]; then
continue
fi
step_count=$(yq '.spec.steps | length' "$file")
for ((i=0; i<step_count; i++)); do
compute_resources=$(yq ".spec.steps[$i].computeResources" "$file")
step_name=$(yq ".spec.steps[$i].name" "$file")
if [[ "$compute_resources" == "null" ]]; then
echo "ERROR: $file step $step_name (index $i) does not have computeResources defined"
fail=1
continue
fi
# Extract limits and requests for this step
limits=$(yq '.limits' <<< "$compute_resources")
requests=$(yq '.requests' <<< "$compute_resources")
# Ensure requests.cpu is defined
if ! yq -e 'has("cpu")' <<< "$requests" > /dev/null 2>&1; then
echo "ERROR: $file step $step_name (index $i) does not have requests.cpu defined"
fail=1
fi
# Ensure limits.memory equals requests.memory
limits_mem=$(yq '.memory' <<< "$limits")
requests_mem=$(yq '.memory' <<< "$requests")
if [[ "$limits_mem" == "null" || "$requests_mem" == "null" || "$limits_mem" != "$requests_mem" ]]; then
echo "ERROR: $file step $step_name (index $i) limits.memory and requests.memory must be defined and equal"
fail=1
fi
# Check no other keys exist in computeResources (order-agnostic)
if ! yq -e 'keys | contains(["limits","requests"]) and length == 2' <<< "$compute_resources" > /dev/null 2>&1; then
echo "ERROR: $file step $step_name (index $i) computeResources has extra or missing keys"
fail=1
else
# Check that limits has memory (and optionally cpu), requests has cpu and memory (order-agnostic)
if ! yq -e 'has("memory")' <<< "$limits" > /dev/null 2>&1; then
echo "ERROR: $file step $step_name (index $i) computeResources.limits must have memory defined"
fail=1
fi
limits_keys_ok=$(yq -e 'keys | all_c(. == "memory" or . == "cpu")' <<< "$limits" 2>/dev/null)
if [[ "$limits_keys_ok" != "true" ]]; then
echo "ERROR: $file step $step_name (index $i) computeResources.limits has unexpected keys (only memory and cpu allowed)"
fail=1
fi
if ! yq -e 'keys | contains(["cpu","memory"]) and length == 2' <<< "$requests" > /dev/null 2>&1; then
echo "ERROR: $file step $step_name (index $i) computeResources.requests has keys other than cpu and memory"
fail=1
fi
fi
done
done
if [[ $fail -ne 0 ]]; then
exit 1
fi