Skip to content

Commit

Permalink
Do not assume that kubectl is installed on the system
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Pearson committed Nov 21, 2019
1 parent dcf7bc8 commit 0fc3c27
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions k
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,21 @@ if [ ! -z "$KUBECONFIG" ]; then
TARGET_VERSION=$(cat "$VERSION_CACHE_FILE" 2> /dev/null)
fi

# Ensure we have at least 1 kubectl version
KNOWN_VERSION="v1.16.3"
KNOWN_TARGET=$KX_PATH/kubectl-$KNOWN_VERSION
if [ ! -f "$KNOWN_TARGET" ]; then
curl -L -o $KNOWN_TARGET "https://storage.googleapis.com/kubernetes-release/release/$KNOWN_VERSION/bin/$OS/amd64/kubectl"
chmod +x $KNOWN_TARGET
fi

# Get the server version from the server if not cached
if [ -z "$TARGET_VERSION" ]; then
TARGET_VERSION=$(kubectl version -o json | jq -r '.serverVersion.gitVersion')
TARGET_VERSION=$($KNOWN_TARGET version -o json | jq -r '.serverVersion.gitVersion')
if [ -z "$TARGET_VERSION" ] || [ "$TARGET_VERSION" == "null" ]; then
echo "Unable to get version information from cluster"
exit 1
fi
if [ $(echo $TARGET_VERSION | egrep "alpha|beta|rc") ]; then
TARGET_VERSION=$(echo $TARGET_VERSION | cut -d'.' -f1-4)
else
Expand All @@ -44,9 +56,7 @@ fi
TARGET=$KX_PATH/kubectl-$TARGET_VERSION

if [ ! -f $TARGET ]; then
cd "$KX_PATH"
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$TARGET_VERSION/bin/$OS/amd64/kubectl"
mv $KX_PATH/kubectl $TARGET
curl -L -o $TARGET "https://storage.googleapis.com/kubernetes-release/release/$TARGET_VERSION/bin/$OS/amd64/kubectl"
chmod +x $TARGET
fi

Expand Down

0 comments on commit 0fc3c27

Please sign in to comment.