[GitHub Actions] Improve scaling runners
This commit is contained in:
10
.github/actions/scale-runners-up/action.yml
vendored
10
.github/actions/scale-runners-up/action.yml
vendored
@@ -80,7 +80,15 @@ runs:
|
||||
VERBOSE: ${{ inputs.verbose && '--verbose' || '' }}
|
||||
run: |
|
||||
echo "::notice ::Scaling stream-apps-gh-runners to ${{ inputs.max_parallel }} pods"
|
||||
./scripts/scale-cluster-pods.sh stream-apps-gh-runners ${{ inputs.max_parallel }} --add 1
|
||||
source ./scripts/kubeconfig-runners.sh
|
||||
IDLE=$(./scripts/count-runners-idle.sh runners-stream-ci)
|
||||
if ((IDLE < ${{ inputs.max_parallel }})); then
|
||||
REQUEST=$((${{ inputs.max_parallel }} - IDLE))
|
||||
echo "::info Requesting $REQUEST runners with $IDLE idle"
|
||||
./scripts/scale-cluster-pods.sh stream-apps-gh-runners $REQUEST --add 1
|
||||
else
|
||||
echo "::info Sufficient runners idle:$IDLE"
|
||||
fi
|
||||
- name: 'Check: Wait for cluster nodes: stream-apps-gh-runners'
|
||||
shell: bash
|
||||
env:
|
||||
|
||||
@@ -15,5 +15,10 @@ echo ""
|
||||
echo "Runners:"
|
||||
RUNNER_DEPLOYMENTS=$(echo "$DEPLOYMENTS" | grep -F "runner" | awk '{print $1}')
|
||||
for deployment in $RUNNER_DEPLOYMENTS; do
|
||||
kubectl get runners -l runner-deployment-name=$deployment --output=json | jq --arg deployment $deployment '.items | map(.status) | group_by(.phase,.ready) | map({ "deployment": $deployment, "count": length, "phase": .[0].phase})'
|
||||
RUNNERS=$(kubectl get runners -l runner-deployment-name=$deployment --output=json | jq -c '.')
|
||||
PHASES=$(echo "$RUNNERS" | jq '.items | map(.status.phase) | unique | .[]' | sed 's/\"//g')
|
||||
for phase in $PHASES; do
|
||||
# kubectl get runners -l runner-deployment-name=$deployment --output=json | jq --arg deployment $deployment '.items | map(.status) | group_by(.phase,.ready) | map({ "deployment": $deployment, "count": length, "phase": .[0].phase})'
|
||||
echo "$RUNNERS"| jq --arg phase $phase --arg deployment $deployment '.items | map(.status) | .[] | select(.phase == $phase)' | jq --slurp --arg phase $phase --arg deployment $deployment 'group_by(.phase) | map({ "deployment": $deployment, "count": length, "phase": $phase})'
|
||||
done
|
||||
done
|
||||
|
||||
@@ -15,6 +15,9 @@ function count_runners() {
|
||||
function count_running() {
|
||||
kubectl get rdeploy | grep -F "runners-stream-ci" | awk '{print $4}'
|
||||
}
|
||||
function count_idle() {
|
||||
kubectl get runners -l runner-deployment-name="runners-stream-ci" --output=json | jq -c '.items | map(.status) | .[] | .phase' | grep -c -F "Idle"
|
||||
}
|
||||
|
||||
if [ "$1" = "" ]; then
|
||||
echo "Expected number to increase"
|
||||
@@ -43,19 +46,27 @@ if [ "$SCALING" == "auto" ]; then
|
||||
MIN_RUNNERS=$MAX_RUNNERS
|
||||
fi
|
||||
else
|
||||
CURRENT=$(count_runners)
|
||||
echo "There are now $CURRENT runners"
|
||||
TARGET=$((CURRENT + INC))
|
||||
if [ "$MAX_RUNNERS" != "" ]; then
|
||||
MAX=$MAX_RUNNERS
|
||||
if ((TARGET > MAX)); then
|
||||
if ((CURRENT > MAX)); then
|
||||
echo "There are $CURRENT which is more than $MAX"
|
||||
exit 0
|
||||
RUNNING=$(count_runners)
|
||||
IDLE=$(count_idle)
|
||||
CURRENT=$((RUNNING - IDLE))
|
||||
echo "There are now $RUNNING runners and $IDLE idle"
|
||||
if ((INC > IDLE)); then
|
||||
TARGET=$((CURRENT+INC-IDLE))
|
||||
if [ "$MAX_RUNNERS" != "" ]; then
|
||||
MAX=$MAX_RUNNERS
|
||||
if ((TARGET > MAX)); then
|
||||
if ((CURRENT > MAX)); then
|
||||
echo "There are $CURRENT which is more than $MAX"
|
||||
exit 0
|
||||
fi
|
||||
echo "There cannot be more than $MAX runners"
|
||||
TARGET=$MAX
|
||||
fi
|
||||
echo "There cannot be more than $MAX runners"
|
||||
TARGET=$MAX
|
||||
fi
|
||||
else
|
||||
echo "Sufficient idle"
|
||||
$SCDIR/check-runners.sh
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
OS=$(uname)
|
||||
|
||||
Reference in New Issue
Block a user