-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathget-masters
executable file
·32 lines (29 loc) · 1.05 KB
/
get-masters
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
#!/bin/sh
cmd='
[foreach .items[] as $item
([[],[]];0;
if ($item.kind == "Node") then
(if ($item.metadata.labels|has("node-role.kubernetes.io/master")) 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)
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
(if ($item.metadata.labels|has("node-role.kubernetes.io/master")) 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)
else null end)]|flatten | map(select (. != null))[]'
out=$(oc get nodes -o json | jq -r "$cmd")
}
echo $out