David Bainbridge | 51cd12b | 2019-11-13 19:55:14 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | DEVICE_ID=$1 |
| 3 | |
| 4 | BEST_DATE= |
| 5 | BEST_POD= |
| 6 | for POD in $(kubectl -n voltha get pods -l app=rw-core -o 'jsonpath={.items[*].metadata.name}'); do |
| 7 | FOUND=$(kubectl -n voltha logs $POD | grep $DEVICE_ID | grep -i ownedbyme | tail -1) |
| 8 | if [ ! -z "$FOUND" ]; then |
| 9 | OWNED=$(echo $FOUND | grep '"owned":true') |
| 10 | if [ ! -z "$OWNED" ]; then |
| 11 | CUR_DATE=$(echo $OWNED | jq -r .ts) |
| 12 | CUR_POD=$(echo $OWNED | jq -r .instanceId) |
| 13 | if [ -z "$BEST_POD" ]; then |
| 14 | BEST_DATE=$CUR_DATE |
| 15 | BEST_POD=$CUR_POD |
| 16 | elif [ $CUR_DATE > $BEST_DATE ]; then |
| 17 | BEST_DATE=$CUR_DATE |
| 18 | BEST_POD=$CUR_POD |
| 19 | fi |
| 20 | fi |
| 21 | fi |
| 22 | done |
| 23 | echo $BEST_POD |