Skip to content

Commit c76613c

Browse files
Merge pull request #70 from npinaeva/update-ovn-get-mg
OCPBUGS-1831: Improve error propagation
2 parents b5a46f0 + a9c7fb1 commit c76613c

4 files changed

Lines changed: 29 additions & 11 deletions

File tree

debug-scripts/scripts/ovn-db-run-command

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ main() {
5555
final_command="oc exec -tic ovnkube-master -n $OVN_NAMESPACE $pod -- /bin/bash"
5656
else
5757
command="bash -c \"${*:1}\""
58-
if [ ! -z "${POD_NAME:-}" ]; then
58+
if [ -n "${POD_NAME:-}" ]; then
5959
# save output when run with must-gather
6060
command+="|& tee /must-gather/output"
6161
fi

debug-scripts/scripts/ovn-get

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,25 @@ Usage: $USAGE [object] [object options]
1313
1414
Supported object:
1515
leaders - prints ovnk master leader pod, nbdb and sbdb leader pods
16-
dbs [output directory] - downloads nbdb and sbdb for every master pod. [output directory] is optional
16+
dbs [output directory] - downloads nbdb and sbdb for every master pod. [output directory] is optional for local usage
17+
and should be omitted for must-gather
1718
1819
Examples:
1920
$USAGE leaders
2021
$USAGE dbs ./dbs
2122
2223
oc adm must-gather --image=$NETWORK_TOOLS_IMAGE -- $USAGE leaders
23-
oc adm must-gather --image=$NETWORK_TOOLS_IMAGE -- $USAGE dbs /must-gather
24+
oc adm must-gather --image=$NETWORK_TOOLS_IMAGE -- $USAGE dbs
2425
"
2526
}
2627

2728
copy_ovn_dbs() {
28-
dir=$(ensure_output_dir "${1:-}")
29+
if [ -n "${POD_NAME:-}" ]; then
30+
# script is run with must-gather
31+
dir="/must-gather"
32+
else
33+
dir=$(ensure_output_dir "${1:-}")
34+
fi
2935
echo "Output directory ${dir}"
3036
# next command will return an error, but this is expected, ignore error
3137
set +e

debug-scripts/utils

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ get_ovnk_leader_node () {
1313

1414
get_ovnk_leader_pod () {
1515
leader_host=$(get_ovnk_leader_node)
16-
master_leader_pod="$(oc get pods -n $OVN_NAMESPACE --field-selector spec.nodeName=${leader_host} -l app=ovnkube-master -o=jsonpath='{.items..metadata.name}')"
16+
[ -z "$leader_host" ] && { echo "not found"; exit 1; }
17+
master_leader_pod="$(oc get pods -n $OVN_NAMESPACE --field-selector spec.nodeName=${leader_host} -l app=ovnkube-master -o=jsonpath='{.items..metadata.name}' \
18+
|| { echo "Can't get master leader pod on the node ${leader_host}" 1>&2; echo "not found"; exit 1; })"
1719
echo "${master_leader_pod}"
1820
}
1921

@@ -28,7 +30,8 @@ get_ovndb_leader_pod () {
2830
s) DB="s"; DB_NAME="OVN_Southbound" ;;
2931
*) echo "Unrecognized ovn db type ${1}, choose one of n, s"; exit 1 ;;
3032
esac
31-
for MASTER_POD in $(oc -n ${OVN_NAMESPACE} get pods -l app=ovnkube-master -o=jsonpath='{.items[*].metadata.name}'); do
33+
MASTER_PODS=$(oc -n ${OVN_NAMESPACE} get pods -l app=ovnkube-master -o=jsonpath='{.items[*].metadata.name}' || { echo "Can't get ovnkube-master pods" 1>&2; exit 1; })
34+
for MASTER_POD in ${MASTER_PODS}; do
3235
RAFT_ROLE=$(oc exec -n ${OVN_NAMESPACE} "${MASTER_POD}" -c ${DB}bdb -- bash -c "ovn-appctl -t /var/run/ovn/ovn${DB}b_db.ctl cluster/status ${DB_NAME} 2>&1 | grep \"^Role\"")
3336
if echo "${RAFT_ROLE}" | grep -q -i leader; then
3437
LEADER=$MASTER_POD
@@ -49,19 +52,25 @@ ensure_output_dir () {
4952
get_pod_node() {
5053
local namespace="${1}"
5154
local name="${2}"
52-
oc get pod -n "$namespace" "$name" -o jsonpath={.spec.nodeName}
55+
oc get pod -n "$namespace" "$name" -o jsonpath={.spec.nodeName} || { echo "ERROR: Can't get pod node" 1>&2; exit 1; }
5356
}
5457

55-
get_ns_pid() {
58+
get_netns_pid() {
5659
local namespace="${1}"
5760
local pod="${2}"
5861

5962
node_name="$(get_pod_node "$namespace" "$pod")"
6063
ns_pid=$(oc debug node/"$node_name" -- chroot /host bash -c \
61-
"runc state \$(crictl ps --pod \$(crictl pods --namespace $namespace --name $pod -q) -q) | jq .pid" 2> /dev/null)
64+
"runc state \$(crictl ps --pod \$(crictl pods --namespace $namespace --name $pod -q) -q) | jq .pid" || \
65+
{ echo "ERROR: Can't get netns pid" 1>&2; exit 1; })
6266
echo "$ns_pid"
6367
}
6468

69+
ctrl_c () {
70+
echo "Ctrl+C was detected"
71+
exit 0
72+
}
73+
6574
run_command_inside_pod_network_namespace_with_network_tools() {
6675
SLEEP=""
6776
if [[ "$1" == "--preserve-pod" || "$1" == "-pp" ]]; then
@@ -89,10 +98,13 @@ run_command_inside_pod_network_namespace_with_network_tools() {
8998
local command="$left_braces${*:3}$right_braces"
9099

91100
node_name="$(get_pod_node "$namespace" "$pod")"
92-
ns_pid="$(get_ns_pid "$namespace" "$pod")"
101+
ns_pid="$(get_netns_pid "$namespace" "$pod")"
93102
if [ -z "$ns_pid" ]; then
103+
echo "ERROR: Failed to find netns pid"
94104
exit 1
95105
fi
106+
107+
trap ctrl_c SIGINT
96108
if [ -z "$command" ]; then
97109
echo "Running interactive shell for network-tools container.
98110
To run commands for pod netnamespace use

docs/generate-docs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ print_help() {
99
while IFS= read -r line
1010
do
1111
command=$(echo $line | cut -s -d ":" -f 1)
12-
if [ ! -z "$command" ]; then
12+
if [ -n "$command" ]; then
1313
echo "* \`network-tools $command\`"
1414
echo
1515
echo "\`\`\`"

0 commit comments

Comments
 (0)