Created
March 10, 2015 18:56
-
-
Save ianblenke/36f1b82efd7eecef0732 to your computer and use it in GitHub Desktop.
Fix fleet's naive unit count based scheduling of deis application units by resubmitting fleet units with an X-Fleet Conflicts glob
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
tmpdir=/tmp/add-xfleet-conflicts | |
mkdir -p $tmpdir | |
fleetctl list-units -fields=unit -no-legend | grep -v -e '@\|deis' | cut -d. -f1-2 | sort | uniq | while read name ; do | |
max=$(fleetctl list-machines -no-legend | wc -l) | |
count=$(fleetctl list-units -fields=unit -no-legend | grep -e "^$name" | wc -l) | |
fleetctl list-units -fields=unit -no-legend | grep -e "^$name" | sort -n | while read service; do | |
tmpfile=$tmpdir/$service | |
fleetctl cat $service >| $tmpfile | |
if ! grep X-Fleet $tmpfile > /dev/null; then | |
ordinal=$(echo $service | sed -e 's/^.*\.\([0-9]\{1,2\}\).*$/\1/' ) | |
(( divisor=$ordinal / $max )) || true | |
(( remainder=$ordinal % $max )) || true | |
if [ $count -gt $max ]; then | |
conflicts="$divisor." | |
echo "Alias=$name.$divisor.$remainder" >> $tmpfile | |
echo "" >> $tmpfile | |
else | |
conflicts='' | |
fi | |
echo "[X-Fleet]" >> $tmpfile | |
echo "Conflicts=$name.$conflicts*" >> $tmpfile | |
fleetctl destroy $tmpfile | |
fleetctl start $tmpfile | |
fi | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment