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

Cleanup default Functions & Tasks while uninstall+ refactor installer script #4

Merged
merged 9 commits into from
Jul 4, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 16 additions & 0 deletions chart/stash/templates/update-status-function.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: stash.appscode.com/v1beta1
kind: Function
metadata:
name: update-status
labels:
{{- include "stash.labels" . | nindent 4 }}
spec:
image: {{ .Values.operator.registry }}/{{ .Values.operator.repository }}:{{ .Values.operator.tag }}
args:
- update-status
- --namespace=${NAMESPACE:=default}
- --repository=${REPOSITORY_NAME:=}
- --backup-session=${BACKUP_SESSION:=}
- --restore-session=${RESTORE_SESSION:=}
- --output-dir=${outputDir:=}
- --enable-status-subresource=${ENABLE_STATUS_SUBRESOURCE:=false}
hossainemruz marked this conversation as resolved.
Show resolved Hide resolved
142 changes: 112 additions & 30 deletions deploy/stash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,61 @@ kubectl config current-context || {
}
echo ""

OS=""
ARCH=""
DOWNLOAD_URL=""
DOWNLOAD_DIR=""
TEMP_DIRS=()
ONESSL=""
HELM=""

# http://redsymbol.net/articles/bash-exit-traps/
function cleanup() {
hossainemruz marked this conversation as resolved.
Show resolved Hide resolved
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
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
armv5*) ARCH="armv5";;
armv6*) ARCH="armv6";;
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 All @@ -35,37 +87,26 @@ onessl_found() {
return 1
}

# download onessl if it does not exist
onessl_found || {
echo "Downloading onessl ..."
if [[ "$(uname -m)" == "aarch64" ]]; then
curl -fsSL -o onessl https://github.com/kubepack/onessl/releases/download/0.10.0/onessl-linux-arm64
chmod +x onessl
export ONESSL=./onessl
else
# 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'
;;
esac
fi

ARTIFACT="https://github.com/kubepack/onessl/releases/download/0.10.0"
Copy link
Member

Choose a reason for hiding this comment

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

Why are we changing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. If we need to change URL we won't need to change for every OS.
  2. Make os detection/download part reusable. If we need to download another binary in future, we would be able to reuse .
  3. Support more architecture. In future, we may need to support ARM.

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 Expand Up @@ -472,6 +513,47 @@ for crd in "${non_namespaced_crds[@]}"; do
}
done

# Install "update-status" Function.
# we only need to resolve the variables of 'spec.image' part and keep others.
# we can't use onessl to resolve the variables as it will try to resolve all the variables.
# we will use helm to generate yaml from template then apply it.
if [ -x "$(command -v helm)" ]; then
export HELM=helm
else
echo "Helm is not installed!. Downloading Helm."
ARTIFACT="https://get.helm.sh"
HELM_VERSION="v2.14.1"
HELM_BIN=helm
HELM_DIST=${HELM_BIN}-${HELM_VERSION}-${OS}-${ARCH}.tar.gz

case "$OS" in
cygwin* | mingw* | msys*)
HELM_BIN=${HELM_BIN}.exe
;;
esac

DOWNLOAD_URL=${ARTIFACT}/${HELM_DIST}
DOWNLOAD_DIR="$(mktemp -dt helm-XXXXXX)"
TEMP_DIRS+=($DOWNLOAD_DIR)

downloadFile $HELM_DIST

tar xf ${DOWNLOAD_DIR}/${HELM_DIST} -C ${DOWNLOAD_DIR}
export HELM=${DOWNLOAD_DIR}/${OS}-${ARCH}/${HELM_BIN}
chmod +x $HELM
fi

export STASH_CHART=$SCRIPT_LOCATION

if [[ "$SCRIPT_LOCATION" == "cat " ]]; then
export STASH_CHART="chart/stash"
fi

$HELM template ${STASH_CHART} -x templates/update-status-function.yaml \
--set operator.registry=${STASH_DOCKER_REGISTRY} \
--set operator.tag=${STASH_IMAGE_TAG} \
| kubectl apply -f -

if [ "$STASH_ENABLE_VALIDATING_WEBHOOK" = true ]; then
echo "checking whether admission webhook(s) are activated or not"
active=$($ONESSL wait-until-has annotation \
Expand Down