Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set context before calculating default namespace #110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
25 changes: 22 additions & 3 deletions kubetail
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,31 @@ fi

readonly PROGNAME=$(basename $0)

get_context() {
if [ "$#" -ne 0 ]; then
while [ "$#" -gt 0 ]
do
case "$1" in
-t|--context)
context="$2"
;;
esac
shift
done
fi
}

calculate_default_namespace() {
local config_namespace=$(${KUBECTL_BIN} config view --minify --output 'jsonpath={..namespace}')
local config_namespace=$(${KUBECTL_BIN} config view ${context:+--context=${context}} --minify --output 'jsonpath={..namespace}')
echo "${KUBETAIL_NAMESPACE:-${config_namespace:-default}}"
}

default_previous="${KUBETAIL_PREVIOUS:-false}"
default_since="${KUBETAIL_SINCE:-10s}"

# Set $context before default namespace as the latter can be specified under specific context in .kube/config
get_context "$@"

default_namespace=$(calculate_default_namespace)
default_follow="${KUBETAIL_FOLLOW:-true}"
default_line_buffered="${KUBETAIL_LINE_BUFFERED:-}"
Expand Down Expand Up @@ -79,8 +97,8 @@ where:
--tail Lines of recent log file to display. Defaults to ${default_tail}, showing all log lines.
-v, --version Prints the kubetail version
-r, --cluster The name of the kubeconfig cluster to use.
-i, --show-color-index Show the color index before the pod name prefix that is shown before each log line.
Normally only the pod name is added as a prefix before each line, for example \"[app-5b7ff6cbcd-bjv8n]\",
-i, --show-color-index Show the color index before the pod name prefix that is shown before each log line.
Normally only the pod name is added as a prefix before each line, for example \"[app-5b7ff6cbcd-bjv8n]\",
but if \"show-color-index\" is true then color index is added as well: \"[1:app-5b7ff6cbcd-bjv8n]\".
This is useful if you have color blindness or if you want to know which colors to exclude (see \"--skip-colors\").
Defaults to ${default_show_color_index}.
Expand Down Expand Up @@ -212,6 +230,7 @@ else
exit 1
fi


# Join function that supports a multi-character separator (copied from http://stackoverflow.com/a/23673883/398441)
function join() {
# $1 is return variable name
Expand Down