David Bainbridge | f81cd64 | 2019-11-20 00:14:47 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Copyright 2019 Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | DEVICE_ID=$1 |
| 17 | |
| 18 | BEST_DATE= |
| 19 | BEST_DEPLOY= |
| 20 | for DEPLOY in $(kubectl -n voltha get deploy -o 'jsonpath={.items[*].metadata.name}'); do |
| 21 | if [[ "$DEPLOY" =~ voltha-rw-core-.* ]]; then |
| 22 | FOUND=$(kubectl -n voltha logs "deploy/$DEPLOY" 2>/dev/null | grep "$DEVICE_ID" | grep -i ownedbyme | tail -1) |
Joey Armstrong | 83874cc | 2022-11-26 09:40:08 -0500 | [diff] [blame] | 23 | if [ -n "$FOUND" ]; then |
David Bainbridge | f81cd64 | 2019-11-20 00:14:47 +0000 | [diff] [blame] | 24 | OWNED=$(echo "$FOUND" | grep '"owned":true') |
Joey Armstrong | 83874cc | 2022-11-26 09:40:08 -0500 | [diff] [blame] | 25 | if [ -n "$OWNED" ]; then |
David Bainbridge | f81cd64 | 2019-11-20 00:14:47 +0000 | [diff] [blame] | 26 | CUR_DATE=$(echo "$OWNED" | jq -r .ts) |
| 27 | CUR_DEPLOY=$DEPLOY |
| 28 | if [ -z "$BEST_DEPLOY" ]; then |
| 29 | BEST_DATE=$CUR_DATE |
| 30 | BEST_DEPLOY=$CUR_DEPLOY |
| 31 | elif [[ "$CUR_DATE" > "$BEST_DATE" ]]; then |
| 32 | BEST_DATE=$CUR_DATE |
| 33 | BEST_DEPLOY=$CUR_DEPLOY |
| 34 | fi |
| 35 | fi |
| 36 | fi |
| 37 | fi |
| 38 | done |
| 39 | if [ -z "$BEST_DEPLOY" ]; then |
| 40 | exit 1 |
| 41 | fi |
| 42 | echo "$BEST_DEPLOY" |