Skip to content

Commit

Permalink
fix: handle empty subjects
Browse files Browse the repository at this point in the history
- if subject doesn't exist, print nice msg
- change to /bin/bash
- remove lib.sh
  • Loading branch information
keegoid-nr committed Feb 23, 2021
1 parent 0dd135c commit cd2bccb
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions cki.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/bash

{ # this ensures the entire script is downloaded #

Expand All @@ -17,8 +17,6 @@ SCRIPT_HEADER=(
"# -----------------------------------------------------"
)

# source lib.sh

# -------------------------- DECLARE COLOR VARIABLES

declare -r COLOR='\033[0'
Expand Down Expand Up @@ -355,6 +353,7 @@ cki_handle_error() {
cki_kubectl() {
local path="$1"
local ns="$2"
local subjects
shift 2
local commands=("$@")
local cnt=1
Expand All @@ -371,13 +370,23 @@ cki_kubectl() {

for res in "${commands[@]}"
do
lib_echo "$res" >>"$path" 2>&1
lib_echo "$res" &>>"$path"
if [ "$ns" == "foo" ]; then
kubectl $res >>"$path" 2>&1
kubectl $res &>>"$path"
elif [ "$ns" == "bar" ]; then
kubectl describe $(kubectl get $res -o name) >>"$path" 2>&1
subjects=$(kubectl get $res -o name)
if [ -z "$subjects" ]; then
echo "nothing found" &>>"$path"
else
kubectl describe $subjects &>>"$path"
fi
else
kubectl describe $(kubectl get $res -o name -n "$ns") -n "$ns" >>"$path" 2>&1
subjects=$(kubectl get $res -o name -n "$ns")
if [ -z "$subjects" ]; then
echo "nothing found" &>>"$path"
else
kubectl describe $subjects -n "$ns" &>>"$path"
fi
fi
lib_progress_bar $((alignedStep * cnt))
cnt=$(( cnt + 1 ))
Expand Down

0 comments on commit cd2bccb

Please sign in to comment.