Skip to content

Commit

Permalink
Download onessl version v0.13.1 for Kubernetes 1.16 fix
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <tamal@appscode.com>
  • Loading branch information
tamalsaha committed Sep 21, 2019
1 parent 494c34e commit 425e462
Showing 1 changed file with 69 additions and 23 deletions.
92 changes: 69 additions & 23 deletions hack/deploy/searchlight.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,60 @@ kubectl config current-context || {
}
echo ""

OS=""
ARCH=""
DOWNLOAD_URL=""
DOWNLOAD_DIR=""
TEMP_DIRS=()
ONESSL=""
ONESSL_VERSION=v0.13.1

# http://redsymbol.net/articles/bash-exit-traps/
function cleanup() {
rm -rf $ONESSL ca.crt ca.key server.crt server.key
rm -rf ca.crt ca.key server.crt server.key
# remove temporary directories
for dir in "${TEMP_DIRS[@]}"; do
rm -rf "${dir}"
done
}

# detect operating system
# ref: https://raw.githubusercontent.com/helm/helm/master/scripts/get
function detectOS() {
OS=$(echo `uname`|tr '[:upper:]' '[:lower:]')

case "$OS" in
# Minimalist GNU for Windows
cygwin* | mingw* | msys*) OS='windows';;
esac
}

# detect machine architecture
function detectArch() {
ARCH=$(uname -m)
case $ARCH in
armv7*) ARCH="arm";;
aarch64) ARCH="arm64";;
x86) ARCH="386";;
x86_64) ARCH="amd64";;
i686) ARCH="386";;
i386) ARCH="386";;
esac
}

detectOS
detectArch

# download file pointed by DOWNLOAD_URL variable
# store download file to the directory pointed by DOWNLOAD_DIR variable
# you have to sent the output file name as argument. i.e. downloadFile myfile.tar.gz
function downloadFile() {
if curl --output /dev/null --silent --head --fail "$DOWNLOAD_URL"; then
curl -fsSL ${DOWNLOAD_URL} -o $DOWNLOAD_DIR/$1
else
echo "File does not exist"
exit 1
fi
}

export APPSCODE_ENV=${APPSCODE_ENV:-prod}
Expand Down Expand Up @@ -64,7 +115,7 @@ detect_tag() {
onessl_found() {
# https://stackoverflow.com/a/677212/244009
if [ -x "$(command -v onessl)" ]; then
onessl wait-until-has -h >/dev/null 2>&1 || {
onessl version --check=">=${ONESSL_VERSION}" >/dev/null 2>&1 || {
# old version of onessl found
echo "Found outdated onessl"
return 1
Expand All @@ -75,31 +126,26 @@ onessl_found() {
return 1
}

# download onessl if it does not exist
onessl_found || {
echo "Downloading onessl ..."
# ref: https://stackoverflow.com/a/27776822/244009
case "$(uname -s)" in
Darwin)
curl -fsSL -o onessl https://github.com/kubepack/onessl/releases/download/0.10.0/onessl-darwin-amd64
chmod +x onessl
export ONESSL=./onessl
;;

Linux)
curl -fsSL -o onessl https://github.com/kubepack/onessl/releases/download/0.10.0/onessl-linux-amd64
chmod +x onessl
export ONESSL=./onessl
;;

CYGWIN* | MINGW* | MSYS*)
curl -fsSL -o onessl.exe https://github.com/kubepack/onessl/releases/download/0.10.0/onessl-windows-amd64.exe
chmod +x onessl.exe
export ONESSL=./onessl.exe
;;
*)
echo 'other OS'
;;
ARTIFACT="https://github.com/kubepack/onessl/releases/download/${ONESSL_VERSION}"
ONESSL_BIN=onessl-${OS}-${ARCH}
case "$OS" in
cygwin* | mingw* | msys*)
ONESSL_BIN=${ONESSL_BIN}.exe
;;
esac

DOWNLOAD_URL=${ARTIFACT}/${ONESSL_BIN}
DOWNLOAD_DIR="$(mktemp -dt onessl-XXXXXX)"
TEMP_DIRS+=($DOWNLOAD_DIR) # store DOWNLOAD_DIR to cleanup later

downloadFile $ONESSL_BIN # downloaded file name will be saved as the value of ONESSL_BIN variable

export ONESSL=${DOWNLOAD_DIR}/${ONESSL_BIN}
chmod +x $ONESSL
}

# ref: https://stackoverflow.com/a/7069755/244009
Expand Down

0 comments on commit 425e462

Please sign in to comment.