-
Notifications
You must be signed in to change notification settings - Fork 24
/
get-nodes
executable file
·42 lines (38 loc) · 1.4 KB
/
get-nodes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
# cmd='
# [foreach .items[] as $item
# ([[],[]];0;
# if ($item.kind == "Node") then
# [([(foreach $item.status.addresses[] as $address
# ([[],[]];0;
# if $address.type == "ExternalIP" then $address.address else null end)),
# (foreach $item.status.addresses[] as $address
# ([[],[]];0;
# if $address.type == "InternalIP" then $address.address else null end))])] | flatten | map (select (. != null))[0]
# else null end)]|flatten | map(select (. != null))[]'
# shellcheck disable=SC2016
cmd='
[foreach .items[] as $item
([[],[]];0;
if ($item.kind == "Node") then
[([(foreach $item.status.addresses[] as $address
([[],[]];0;
if $address.type == "ExternalIP" then $address.address else null end))])] | flatten | map (select (. != null))[0]
else null end)]|flatten | map(select (. != null))[]'
out="$(oc get nodes -o json | jq -r "$cmd")"
[[ -z "$out" ]] && {
# shellcheck disable=SC2016
cmd='
[foreach .items[] as $item
([[],[]];0;
if ($item.kind == "Node") then
[([(foreach $item.status.addresses[] as $address
([[],[]];0;
if $address.type == "ExternalIP" then $address.address else null end)),
(foreach $item.status.addresses[] as $address
([[],[]];0;
if $address.type == "InternalIP" then $address.address else null end))])] | flatten | map (select (. != null))[0]
else null end)]|flatten | map(select (. != null))[]'
out="$(oc get nodes -o json | jq -r "$cmd")"
}
echo "$out"