Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Commit

Permalink
move upgrade logic into shell script to improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jmlrt committed May 29, 2020
1 parent 9c616af commit 8a44590
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 7 deletions.
8 changes: 1 addition & 7 deletions elasticsearch/examples/upgrade/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@ default: test
include ../../../helpers/examples.mk

RELEASE := helm-es-upgrade
KUBE_MINOR_VERSION := $(shell kubectl version --client -o yaml | grep minor | sed 's/[^0-9]*//g')
VERSION := $(shell test $(KUBE_MINOR_VERSION) -lt 16 && echo 7.0.0-alpha1 || echo 7.4.0)

install:
helm repo add elastic https://helm.elastic.co && \
helm upgrade --wait --timeout=600 --install $(RELEASE) elastic/elasticsearch --version $(VERSION) --set clusterName=upgrade ; \
kubectl rollout status sts/upgrade-master --timeout=600s
helm upgrade --wait --timeout=600 --set terminationGracePeriod=121 --install $(RELEASE) ../../ --set clusterName=upgrade ; \
kubectl rollout status sts/upgrade-master --timeout=600s
./scripts/upgrade.sh --release $(RELEASE)

init:
helm init --client-only
Expand Down
67 changes: 67 additions & 0 deletions elasticsearch/examples/upgrade/scripts/upgrade.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env bash

set -eo pipefail

usage() {
cat <<-EOF
USAGE:
$0 [--release <release-name>] [--from <elasticsearch-version>] --to <elasticsearch-version>
$0 --help
OPTIONS:
--release <release-name>
Name of the Helm release to install
--from <elasticsearch-version>
Elasticsearch version to use for first install
EOF
exit 1
}

RELEASE="helm-es-upgrade"
FROM=""

while [[ $# -gt 0 ]]
do
key="$1"

case $key in
--help)
usage
;;
--release)
RELEASE="$2"
shift 2
;;
--from)
FROM="$2"
shift 2
;;
*)
log "Unrecognized argument: '$key'"
usage
;;
esac
done

# Elasticsearch chart < 7.4.0 are not compatible with K8S >= 1.16)
if [[ -z $FROM ]]
then
KUBE_MINOR_VERSION=$(kubectl version --client -o yaml | grep minor | sed 's/[^0-9]*//g')

if [ "$KUBE_MINOR_VERSION" -lt 16 ]
then
FROM="7.0.0-alpha1"
else
FROM="7.4.0"
fi
fi

helm repo add elastic https://helm.elastic.co

# Initial install
helm upgrade --wait --timeout=600 --install "$RELEASE" elastic/elasticsearch --version "$FROM" --set clusterName=upgrade -f ../docker-for-mac/values.yaml
kubectl rollout status sts/upgrade-master --timeout=600s

# Upgrade
helm upgrade --wait --timeout=600 --set terminationGracePeriod=121 --install "$RELEASE" ../../ --set clusterName=upgrade -f ../docker-for-mac/values.yaml
kubectl rollout status sts/upgrade-master --timeout=600s

0 comments on commit 8a44590

Please sign in to comment.