Skip to content
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: 13 additions & 12 deletions kubectl
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ if [ ! -f "$DEFAULT_CLIENT" ]; then
downloadClient "$DEFAULT_VERSION"
fi

if [ "$1" == "config" ]; then
$DEFAULT_CLIENT "$@"
exit $?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep config with default client to make sure we can always configure our kubectl and dont have to wait 30 seconds for an i/o timeout if cluster not reachable for example.

VERSION_OUTPUT=$($DEFAULT_CLIENT version -o json 2>&1)
if grep -q "Unable to connect to the server" <<<"$VERSION_OUTPUT"; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on error message strings is fragile. Better to check the exit code != 0

# Echo as comment to make sure "kubectl completion" etc works in profile
echo -e "#WARNING: Wrapper unable to verify server version, using default version $DEFAULT_VERSION.\n"
$DEFAULT_CLIENT "$@"
else
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary else statement. use exit $?

SERVER_VERSION=$(echo $VERSION_OUTPUT | jq ".serverVersion.gitVersion" -r | grep -Po "v\d+.\d+.\d+")
CLIENT="$CLIENTS_PATH/$SERVER_VERSION"
#Download client if we dont have it
if [ ! -f "$CLIENT" ]; then
downloadClient "$SERVER_VERSION"
fi
$CLIENT "$@"
fi

SERVER_VERSION=$($DEFAULT_CLIENT version -o json | jq ".serverVersion.gitVersion" -r | grep -Po "v\d+.\d+.\d+")
CLIENT="$CLIENTS_PATH/$SERVER_VERSION"

#Download client if we dont have it
if [ ! -f "$CLIENT" ]; then
downloadClient "$SERVER_VERSION"
fi

$CLIENT "$@"
exit $?