blob: 55b7a6fe8528d87e556347acc67f2972d5c26b79 [file] [log] [blame]
David Bainbridgef81cd642019-11-20 00:14:47 +00001#!/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
16DEVICE_ID=$1
17
18BEST_DATE=
19BEST_DEPLOY=
20for 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 Armstrong83874cc2022-11-26 09:40:08 -050023 if [ -n "$FOUND" ]; then
David Bainbridgef81cd642019-11-20 00:14:47 +000024 OWNED=$(echo "$FOUND" | grep '"owned":true')
Joey Armstrong83874cc2022-11-26 09:40:08 -050025 if [ -n "$OWNED" ]; then
David Bainbridgef81cd642019-11-20 00:14:47 +000026 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
38done
39if [ -z "$BEST_DEPLOY" ]; then
40 exit 1
41fi
42echo "$BEST_DEPLOY"