Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions find-pod-and
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@ fi
if [ "$namespace" == "-A" ]; then
podlist=$(kubectl get pod -A -o wide)
# & search by both name + namespace
results=$(echo "$podlist" | tr -s ' ' | awk '{print $1" "$2}' | grep $search)
results=$(echo "$podlist" | tr -s ' ' | awk '{print $1" "$2}' | grep "$search")
else
podlist=$(kubectl get pod -n $namespace -o wide)
# and search by name only
results=$(echo "$podlist" | tr -s ' ' | awk '{print $1}' | grep $search)
results=$(echo "$podlist" | tr -s ' ' | awk '{print $1}' | grep "$search")
fi
if [ "$search" != "-" ]; then
results=$(echo "$results" | grep $search)
results=$(echo "$results" | grep "$search")
fi

# get containers running inside each pod
Expand All @@ -154,9 +154,9 @@ while read pod; do
podns=$namespace
podname=$(echo $pod | awk '{print $1}')
fi
if [ ! -z $podname ]; then
if [ ! -z "$podname" ]; then
# check if pod has containers (should)
containers=$(kubectl get pods $podname -n $podns -o jsonpath='{.spec.containers[*].name}')
containers=$(kubectl get pods "$podname" -n "$podns" -o jsonpath='{.spec.containers[*].name}')
#containers="nginx varnish" # test mutliple container output
if [ "$?" != "0" ]; then
# in the event of an error, just show the pod info, pod level commands should still work
Expand All @@ -173,7 +173,7 @@ while read pod; do
fi
done <<< "$results"

if [ $(echo "$results" | xargs | wc -l) == 0 ]; then
if [ "$(echo "$results" | xargs | wc -l)" == 0 ]; then
echo "None found"
exit 0
else
Expand All @@ -189,13 +189,13 @@ if [ -z "$selected" ]; then
exit 0
fi
entry=$(echo "$container_list" | grep "^$selected")
if [ $(echo "$entry" | xargs | wc -l) == 0 ]; then
if [ "$(echo "$entry" | xargs | wc -l)" == 0 ]; then
errMsg "invalid selection"
exit 1
fi
ns=$(echo $entry | awk '{print $2}')
pod=$(echo $entry | awk '{print $3}')
container=$(echo $entry | awk '{print $4}')
ns=$(echo "$entry" | awk '{print $2}')
pod=$(echo "$entry" | awk '{print $3}')
container=$(echo "$entry" | awk '{print $4}')

# and run the selected command on it...
echo
Expand Down
35 changes: 23 additions & 12 deletions launch-dashboard
Original file line number Diff line number Diff line change
Expand Up @@ -148,21 +148,32 @@ if (( $(kubectl get replicaset -n $DASHBAORD_NAMESPACE | grep $DASHBOARD_DEPLOYM
fi

# start the kubectl proxy if not already running & open the browser
if [ "$(ps aux | grep -w '[k]ubectl proxy' | wc -l)" -eq "0" ]; then

echo "Starting kubectl proxy"
# put the process in the background and get the pid
kubectl proxy &
BG_PID=$!
sleep 1 # allow a beat for the proxy to init
openBrowser
echo "kubectl proxy is running (CTRL+C to exit)"
wait
PROXY_LOCK_FILE="/tmp/kubectl-proxy.lock"

# Check if proxy is already running
if [ "$(ps aux | grep -w '[k]ubectl proxy' | wc -l)" -eq "0" ]; then
# Use file lock to prevent race condition
if (set -C; : > "$PROXY_LOCK_FILE") 2>/dev/null; then
# We got the lock, start the proxy
echo "Starting kubectl proxy"
kubectl proxy &
BG_PID=$!
sleep 2 # allow more time for the proxy to init
openBrowser
echo "kubectl proxy is running (CTRL+C to exit)"
rm -f "$PROXY_LOCK_FILE" # Release lock
wait
else
# Another instance is starting the proxy, wait and then open browser
echo "Another instance is starting kubectl proxy, waiting..."
while [ -f "$PROXY_LOCK_FILE" ]; do
sleep 1
done
sleep 1 # Additional wait to ensure proxy is ready
openBrowser
fi
else

openBrowser

fi

exit 0