Skip to content

Instantly share code, notes, and snippets.

@matheusneder
Last active March 25, 2020 15:24
Show Gist options
  • Save matheusneder/2ee7fcf81ee4a94b20b46823f46427e8 to your computer and use it in GitHub Desktop.
Save matheusneder/2ee7fcf81ee4a94b20b46823f46427e8 to your computer and use it in GitHub Desktop.
#!/bin/bash
NS=$1;
if [ -z "$NS" ]
then
echo "Usage: $0 namespace" >&2
exit 1;
fi
for APP in $(kubectl -n $NS get deployment \
-o jsonpath="{range .items[*]}{.metadata.labels.app}{'\n'}{end}" | grep -v 'eph-pr')
do
POD=$(kubectl -n $NS get pod -l app=$APP \
-o jsonpath="{range .items[*]}{.metadata.name} {.status.containerStatuses[0].ready}{'\n'}{end}" \
| egrep ' true$' | sed 's/ true$//' | head -1)
VERSION='deployment has no ready pods'
[ -z "$POD" ] || VERSION=$(kubectl -n $NS exec $POD -- sh -c '
dotnet --info 2> /dev/null || dotnet 2> /dev/null
if [ "$?" -eq 127 ] # command not found
then
echo "Version: -1" # dotnet command not found (not a dotnet container)
fi
exit 0
' 2> /dev/null | grep -oP "^\s*Version\s*:\s*\K[0-9.-]+" )
[ -z "$POD" ] && POD="n/a"
[ -z "$VERSION" ] && VERSION="container error (POD: $POD)"
if [ "$VERSION" != "-1" ] # print only dotnet containers
then
printf "%-40s %s\n" "$APP" "$VERSION"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment