Skip to content

Instantly share code, notes, and snippets.

@ianblenke
Created March 10, 2015 18:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ianblenke/36f1b82efd7eecef0732 to your computer and use it in GitHub Desktop.
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
#!/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