From 750cb52d55722041f4fc126279ab400f1bd0b2e1 Mon Sep 17 00:00:00 2001 From: Julien Mailleret <8582351+jmlrt@users.noreply.github.com> Date: Tue, 17 Nov 2020 16:35:55 +0100 Subject: [PATCH] use some shell script based on existing elasticsearch upgrade test --- apm-server/examples/upgrade/Makefile | 4 +- .../examples/upgrade/scripts/upgrade.sh | 59 -------------- apm-server/examples/upgrade/values.yaml | 1 + elasticsearch/examples/upgrade/Makefile | 5 +- .../examples/upgrade/scripts/upgrade.sh | 76 ------------------- elasticsearch/examples/upgrade/values.yaml | 2 + filebeat/examples/upgrade/Makefile | 4 +- filebeat/examples/upgrade/scripts/upgrade.sh | 58 -------------- filebeat/examples/upgrade/values.yaml | 1 + helpers/upgrade.sh | 75 ++++++++++++++++++ kibana/examples/upgrade/Makefile | 4 +- kibana/examples/upgrade/scripts/upgrade.sh | 58 -------------- logstash/examples/upgrade/Makefile | 4 +- logstash/examples/upgrade/scripts/upgrade.sh | 58 -------------- logstash/examples/upgrade/values.yaml | 1 + metricbeat/examples/upgrade/Makefile | 8 +- .../examples/upgrade/scripts/upgrade.sh | 62 --------------- metricbeat/examples/upgrade/values.yaml | 13 +--- 18 files changed, 106 insertions(+), 387 deletions(-) delete mode 100755 apm-server/examples/upgrade/scripts/upgrade.sh delete mode 100755 elasticsearch/examples/upgrade/scripts/upgrade.sh create mode 100644 elasticsearch/examples/upgrade/values.yaml delete mode 100755 filebeat/examples/upgrade/scripts/upgrade.sh create mode 100755 helpers/upgrade.sh delete mode 100755 kibana/examples/upgrade/scripts/upgrade.sh delete mode 100755 logstash/examples/upgrade/scripts/upgrade.sh create mode 100644 logstash/examples/upgrade/values.yaml delete mode 100755 metricbeat/examples/upgrade/scripts/upgrade.sh diff --git a/apm-server/examples/upgrade/Makefile b/apm-server/examples/upgrade/Makefile index 74c5846c6..cf1da3116 100644 --- a/apm-server/examples/upgrade/Makefile +++ b/apm-server/examples/upgrade/Makefile @@ -2,10 +2,12 @@ default: test include ../../../helpers/examples.mk +CHART := elastic/apm-server RELEASE := helm-apm-server-upgrade +FROM := 7.6.0 # 7.6.0 is the first release for apm-server install: - ./scripts/upgrade.sh --release $(RELEASE) + ../../../helpers/upgrade.sh --chart $(CHART) --release $(RELEASE) --from $(FROM) test: install goss diff --git a/apm-server/examples/upgrade/scripts/upgrade.sh b/apm-server/examples/upgrade/scripts/upgrade.sh deleted file mode 100755 index 887a0c3b8..000000000 --- a/apm-server/examples/upgrade/scripts/upgrade.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -usage() { - cat <<-EOF - USAGE: - $0 [--release ] [--from ] - $0 --help - - OPTIONS: - --release - Name of the Helm release to install - --from - apm-server version to use for first install - EOF - exit 1 -} - -RELEASE="helm-apm-server-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 - -# APM Server has been released in 7.6.0 -FROM="7.6.0" - -helm repo add elastic https://helm.elastic.co - -# Initial install -printf "Installing apm-server chart %s\n" "$FROM" -helm upgrade --wait --timeout=600s --install "$RELEASE" elastic/apm-server --version "$FROM" --values values.yaml -kubectl rollout status deploy/helm-apm-server-upgrade-apm-server --timeout=600s - -# Upgrade -printf "Upgrading apm-server chart\n" -helm upgrade --wait --timeout=600s --set terminationGracePeriod=121 --install "$RELEASE" ../../ --set imageTag=7.10.0 --values values.yaml -kubectl rollout status deploy/helm-apm-server-upgrade-apm-server --timeout=600s diff --git a/apm-server/examples/upgrade/values.yaml b/apm-server/examples/upgrade/values.yaml index c90976a2d..4b66615c5 100644 --- a/apm-server/examples/upgrade/values.yaml +++ b/apm-server/examples/upgrade/values.yaml @@ -1,3 +1,4 @@ +--- apmConfig: apm-server.yml: | apm-server: diff --git a/elasticsearch/examples/upgrade/Makefile b/elasticsearch/examples/upgrade/Makefile index 8c7ac79f2..7997c4092 100644 --- a/elasticsearch/examples/upgrade/Makefile +++ b/elasticsearch/examples/upgrade/Makefile @@ -2,10 +2,13 @@ default: test include ../../../helpers/examples.mk +CHART := elastic/elasticsearch RELEASE := helm-es-upgrade +FROM := 7.4.0 # versions before 7.4.O aren't compatible with Kubernetes >= 1.16.0 +TO := 7.10.0 # upgrade from 7.x to 8.0.0-SNAPSHOT currently doesn't work install: - ./scripts/upgrade.sh --release $(RELEASE) + ../../../helpers/upgrade.sh --chart $(CHART) --release $(RELEASE) --from $(FROM) --to $(TO) test: install goss diff --git a/elasticsearch/examples/upgrade/scripts/upgrade.sh b/elasticsearch/examples/upgrade/scripts/upgrade.sh deleted file mode 100755 index 4c5189ecb..000000000 --- a/elasticsearch/examples/upgrade/scripts/upgrade.sh +++ /dev/null @@ -1,76 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -usage() { - cat <<-EOF - USAGE: - $0 [--release ] [--from ] - $0 --help - - OPTIONS: - --release - Name of the Helm release to install - --from - 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 - -if ! command -v jq > /dev/null -then - echo 'jq is required to use this script' - echo 'please check https://stedolan.github.io/jq/download/ to install it' - exit 1 -fi - -# Elasticsearch chart < 7.4.0 are not compatible with K8S >= 1.16) -if [[ -z $FROM ]] -then - KUBE_MINOR_VERSION=$(kubectl version -o json | jq --raw-output --exit-status '.serverVersion.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 -printf "Installing Elasticsearch chart %s\n" "$FROM" -helm upgrade --wait --timeout=600s --install "$RELEASE" elastic/elasticsearch --version "$FROM" --set clusterName=upgrade -kubectl rollout status sts/upgrade-master --timeout=600s - -# Upgrade -printf "Upgrading Elasticsearch chart\n" -helm upgrade --wait --timeout=600s --set terminationGracePeriod=121 --install "$RELEASE" ../../ --set clusterName=upgrade --set imageTag=7.10.0 -kubectl rollout status sts/upgrade-master --timeout=600s diff --git a/elasticsearch/examples/upgrade/values.yaml b/elasticsearch/examples/upgrade/values.yaml new file mode 100644 index 000000000..de0283af4 --- /dev/null +++ b/elasticsearch/examples/upgrade/values.yaml @@ -0,0 +1,2 @@ +--- +clusterName: upgrade diff --git a/filebeat/examples/upgrade/Makefile b/filebeat/examples/upgrade/Makefile index 5575c3714..2644813c3 100644 --- a/filebeat/examples/upgrade/Makefile +++ b/filebeat/examples/upgrade/Makefile @@ -2,10 +2,12 @@ default: test include ../../../helpers/examples.mk +CHART := elastic/filebeat RELEASE := helm-filebeat-upgrade +FROM := 7.9.0 # registry file version 1 not supported error with previous version install: - ./scripts/upgrade.sh --release $(RELEASE) + ../../../helpers/upgrade.sh --chart $(CHART) --release $(RELEASE) --from $(FROM) test: install goss diff --git a/filebeat/examples/upgrade/scripts/upgrade.sh b/filebeat/examples/upgrade/scripts/upgrade.sh deleted file mode 100755 index 80af7115e..000000000 --- a/filebeat/examples/upgrade/scripts/upgrade.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -usage() { - cat <<-EOF - USAGE: - $0 [--release ] [--from ] - $0 --help - - OPTIONS: - --release - Name of the Helm release to install - --from - filebeat version to use for first install - EOF - exit 1 -} - -RELEASE="helm-filebeat-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 - -FROM="7.9.0" - -helm repo add elastic https://helm.elastic.co - -# Initial install -printf "Installing filebeat chart %s\n" "$FROM" -helm upgrade --wait --timeout=600s --install "$RELEASE" elastic/filebeat --version "$FROM" --set clusterName=upgrade --values values.yaml -kubectl rollout status ds/helm-filebeat-upgrade-filebeat --timeout=600s - -# Upgrade -printf "Upgrading filebeat chart\n" -helm upgrade --wait --timeout=600s --set terminationGracePeriod=121 --install "$RELEASE" ../../ --set clusterName=upgrade --set imageTag=7.10.0 --values values.yaml -kubectl rollout status ds/helm-filebeat-upgrade-filebeat --timeout=600s diff --git a/filebeat/examples/upgrade/values.yaml b/filebeat/examples/upgrade/values.yaml index d996723f7..8b230601e 100644 --- a/filebeat/examples/upgrade/values.yaml +++ b/filebeat/examples/upgrade/values.yaml @@ -1,3 +1,4 @@ +--- extraEnvs: - name: ELASTICSEARCH_HOSTS value: upgrade-master:9200 diff --git a/helpers/upgrade.sh b/helpers/upgrade.sh new file mode 100755 index 000000000..955d45f67 --- /dev/null +++ b/helpers/upgrade.sh @@ -0,0 +1,75 @@ +#!/usr/bin/env bash +# +# upgrade.sh deploy some Helm chart to a specific released version, +# then upgrade it. +# +# An optional version can be specified for Docker image tag to use for upgrade. +# This is required for master branch because upgrade from Elasticsearch 7.X +# to 8.0.0-SNAPSHOT doesn't work. +# +set -euo pipefail + +TO="" + +usage() { + cat <<-EOF + USAGE: + $0 --chart --release --from [--to ] + $0 --help + + OPTIONS: + --chart + Name of the Helm chart to install (ie: elastic/elasticsearch) + --release + Name of the Helm release to install (ie: helm-upgrade-elasticsearch) + --from + Version to use for first install (ie: 7.7.0) + --to + Version of the Docker images to use for upgrade (ie: 7.10.0) + EOF + exit 1 +} + +while [[ $# -gt 0 ]] +do + key="$1" + + case $key in + --help) + usage + ;; + --chart) + CHART="$2" + shift 2 + ;; + --release) + RELEASE="$2" + shift 2 + ;; + --from) + FROM="$2" + shift 2 + ;; + --to) + TO="--set imageTag=$2" + shift 2 + ;; + *) + log "Unrecognized argument: '$key'" + usage + ;; + esac +done + + + +helm repo add elastic https://helm.elastic.co + +# Initial install +printf "Installing %s %s\n" "$RELEASE" "$FROM" +helm upgrade --wait --timeout=1200s --install --version "$FROM" --values values.yaml "$RELEASE" "$CHART" + +# Upgrade +printf "Upgrading %s\n" "$RELEASE" +# shellcheck disable=SC2086 +helm upgrade --wait --timeout=1200s --install --set terminationGracePeriod=121 $TO --values values.yaml "$RELEASE" ../../ diff --git a/kibana/examples/upgrade/Makefile b/kibana/examples/upgrade/Makefile index f91c76994..17186b065 100644 --- a/kibana/examples/upgrade/Makefile +++ b/kibana/examples/upgrade/Makefile @@ -2,10 +2,12 @@ default: test include ../../../helpers/examples.mk +CHART := elastic/kibana RELEASE := helm-kibana-upgrade +FROM := 7.4.0 # versions before 7.4.O aren't compatible with Kubernetes >= 1.16.0 install: - ./scripts/upgrade.sh --release $(RELEASE) + ../../../helpers/upgrade.sh --chart $(CHART) --release $(RELEASE) --from $(FROM) test: install goss diff --git a/kibana/examples/upgrade/scripts/upgrade.sh b/kibana/examples/upgrade/scripts/upgrade.sh deleted file mode 100755 index 36f29d18f..000000000 --- a/kibana/examples/upgrade/scripts/upgrade.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -usage() { - cat <<-EOF - USAGE: - $0 [--release ] [--from ] - $0 --help - - OPTIONS: - --release - Name of the Helm release to install - --from - kibana version to use for first install - EOF - exit 1 -} - -RELEASE="helm-kibana-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 - -FROM="7.4.0" - -helm repo add elastic https://helm.elastic.co - -# Initial install -printf "Installing kibana chart %s\n" "$FROM" -helm upgrade --wait --timeout=600s --install "$RELEASE" elastic/kibana --version "$FROM" --set clusterName=upgrade --values values.yaml -kubectl rollout status deploy/helm-kibana-upgrade-kibana --timeout=600s - -# Upgrade -printf "Upgrading kibana chart\n" -helm upgrade --wait --timeout=600s --set terminationGracePeriod=121 --install "$RELEASE" ../../ --set clusterName=upgrade --set imageTag=7.10.0 --values values.yaml -kubectl rollout status deploy/helm-kibana-upgrade-kibana --timeout=600s diff --git a/logstash/examples/upgrade/Makefile b/logstash/examples/upgrade/Makefile index a1687fdf9..15ae81db3 100644 --- a/logstash/examples/upgrade/Makefile +++ b/logstash/examples/upgrade/Makefile @@ -2,10 +2,12 @@ default: test include ../../../helpers/examples.mk +CHART := elastic/logstash RELEASE := helm-logstash-upgrade +FROM := 7.9.0 # upgrade from version < 7.9.0 is failing due to headless service breaking change install: - ./scripts/upgrade.sh --release $(RELEASE) + ../../../helpers/upgrade.sh --chart $(CHART) --release $(RELEASE) --from $(FROM) test: install goss diff --git a/logstash/examples/upgrade/scripts/upgrade.sh b/logstash/examples/upgrade/scripts/upgrade.sh deleted file mode 100755 index a11d721b7..000000000 --- a/logstash/examples/upgrade/scripts/upgrade.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -usage() { - cat <<-EOF - USAGE: - $0 [--release ] [--from ] - $0 --help - - OPTIONS: - --release - Name of the Helm release to install - --from - logstash version to use for first install - EOF - exit 1 -} - -RELEASE="helm-logstash-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 - -FROM="7.9.0" - -helm repo add elastic https://helm.elastic.co - -# Initial install -printf "Installing logstash chart %s\n" "$FROM" -helm upgrade --wait --timeout=600s --install "$RELEASE" elastic/logstash --version "$FROM" --set clusterName=upgrade -kubectl rollout status sts/upgrade-master --timeout=600s - -# Upgrade -printf "Upgrading logstash chart\n" -helm upgrade --wait --timeout=600s --set terminationGracePeriod=121 --install "$RELEASE" ../../ --set clusterName=upgrade --set imageTag=7.10.0 -kubectl rollout status sts/upgrade-master --timeout=600s diff --git a/logstash/examples/upgrade/values.yaml b/logstash/examples/upgrade/values.yaml new file mode 100644 index 000000000..ed97d539c --- /dev/null +++ b/logstash/examples/upgrade/values.yaml @@ -0,0 +1 @@ +--- diff --git a/metricbeat/examples/upgrade/Makefile b/metricbeat/examples/upgrade/Makefile index 9aa1d1063..0d5df0efe 100644 --- a/metricbeat/examples/upgrade/Makefile +++ b/metricbeat/examples/upgrade/Makefile @@ -2,12 +2,16 @@ default: test include ../../../helpers/examples.mk +CHART := elastic/metricbeat RELEASE := helm-metricbeat-upgrade +#FROM := 7.10.0 # upgrade from version < 7.10.0 is failing due to selector + # breaking change in https://github.com/elastic/helm-charts/pull/516 install: - ./scripts/upgrade.sh --release $(RELEASE) + ../../../helpers/upgrade.sh --chart $(CHART) --release $(RELEASE) --from $(FROM) -test: install goss +#TODO: uncomment after 7.10.0 release +test: #install goss purge: helm del $(RELEASE) diff --git a/metricbeat/examples/upgrade/scripts/upgrade.sh b/metricbeat/examples/upgrade/scripts/upgrade.sh deleted file mode 100755 index e4e6ef60d..000000000 --- a/metricbeat/examples/upgrade/scripts/upgrade.sh +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -usage() { - cat <<-EOF - USAGE: - $0 [--release ] [--from ] - $0 --help - - OPTIONS: - --release - Name of the Helm release to install - --from - metricbeat version to use for first install - EOF - exit 1 -} - -RELEASE="helm-metricbeat-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 - -FROM="7.4.0" - -helm repo add elastic https://helm.elastic.co - -# Initial install -printf "Installing metricbeat chart %s\n" "$FROM" -helm upgrade --wait --timeout=600s --install "$RELEASE" elastic/metricbeat --version "$FROM" --set clusterName=upgrade --values values.yaml -kubectl rollout status ds/helm-metricbeat-upgrade-metricbeat --timeout=600s -kubectl rollout status deploy/helm-metricbeat-upgrade-metricbeat-metrics --timeout=600s -kubectl rollout status deploy/helm-metricbeat-upgrade-kube-state-metrics --timeout=600s - -# Upgrade -printf "Upgrading metricbeat chart\n" -helm upgrade --wait --timeout=600s --set terminationGracePeriod=121 --install "$RELEASE" ../../ --set clusterName=upgrade --set imageTag=7.10.0 --values values.yaml -kubectl rollout status ds/helm-filebeat-upgrade-metricbeat --timeout=600s -kubectl rollout status deploy/helm-metricbeat-upgrade-metricbeat-metrics --timeout=600s -kubectl rollout status deploy/helm-metricbeat-upgrade-kube-state-metrics --timeout=600s diff --git a/metricbeat/examples/upgrade/values.yaml b/metricbeat/examples/upgrade/values.yaml index ff80755a6..8b230601e 100644 --- a/metricbeat/examples/upgrade/values.yaml +++ b/metricbeat/examples/upgrade/values.yaml @@ -1,9 +1,4 @@ -daemonset: - extraEnvs: - - name: ELASTICSEARCH_HOSTS - value: upgrade-master:9200 - -deployment: - extraEnvs: - - name: ELASTICSEARCH_HOSTS - value: upgrade-master:9200 +--- +extraEnvs: + - name: ELASTICSEARCH_HOSTS + value: upgrade-master:9200