forked from RobertKrawitz/OpenShift4-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-nodes
executable file
·40 lines (36 loc) · 1.33 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
#!/bin/sh
# 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))[]'
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 ]] && {
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