From f361fd647729dc35a85457514c161c896c6b7010 Mon Sep 17 00:00:00 2001 From: Steve Wilkerson Date: Thu, 21 Feb 2019 13:34:51 -0600 Subject: [PATCH] Elasticsearch: Add check to job for registering snapshot repo This updates the script used to register the elasticsearch snapshot repositories. It will first gather a list of all currently registered repositories, then check for the existence of each configured repository. If the repository exists, the job will not attempt to register the repository again. If it doesn't exist, the job will then register the desired repository Change-Id: I2cfd3c44f1b2b4a54c9b07be79c2c87af77c540e --- .../templates/bin/_register-repository.sh.tpl | 53 ++++++++++++------- elasticsearch/values.yaml | 2 +- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/elasticsearch/templates/bin/_register-repository.sh.tpl b/elasticsearch/templates/bin/_register-repository.sh.tpl index 983e8024d6..3b940bbc96 100644 --- a/elasticsearch/templates/bin/_register-repository.sh.tpl +++ b/elasticsearch/templates/bin/_register-repository.sh.tpl @@ -19,25 +19,42 @@ limitations under the License. set -ex +function contains() { + [[ $1 =~ (^|[[:space:]])$2($|[[:space:]]) ]] && return 0 || return 1 +} + +function register_snapshot_repository() { + result=$(curl -K- <<< "--user ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}" \ + "${ELASTICSEARCH_HOST}/_snapshot/$1" \ + -H 'Content-Type: application/json' -d' + { + "type": "s3", + "settings": { + "endpoint": "'"$RGW_HOST"'", + "protocol": "http", + "bucket": "'"$S3_BUCKET"'", + "access_key": "'"$S3_ACCESS_KEY"'", + "secret_key": "'"$S3_SECRET_KEY"'" + } + }' | python -c "import sys, json; print json.load(sys.stdin)['acknowledged']") + if [ "$result" == "True" ]; + then + echo "Snapshot repository $1 created!"; + else + echo "Snapshot repository $1 not created!"; + exit 1; + fi +} + +# Get names of all current snapshot repositories +snapshot_repos=$(curl -K- <<< "--user ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}" \ + "${ELASTICSEARCH_HOST}"/_cat/repositories?format=json | jq -r '.[].id') + +# Create snapshot repositories if they don't exist {{ range $repository := $envAll.Values.conf.elasticsearch.snapshots.repositories }} -result=$(curl -K- <<< "--user ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}" \ - "${ELASTICSEARCH_HOST}/_snapshot/{{$repository.name}}" \ - -H 'Content-Type: application/json' -d' - { - "type": "s3", - "settings": { - "endpoint": "'"$RGW_HOST"'", - "protocol": "http", - "bucket": "'"$S3_BUCKET"'", - "access_key": "'"$S3_ACCESS_KEY"'", - "secret_key": "'"$S3_SECRET_KEY"'" - } - }' | python -c "import sys, json; print json.load(sys.stdin)['acknowledged']") -if [ "$result" == "True" ]; -then - echo "Snapshot repository {{$repository.name}} created!"; +if contains "$snapshot_repos" {{$repository.name}}; then + echo "Snapshot repository {{$repository.name}} exists!" else - echo "Snapshot repository {{$repository.name}} not created!"; - exit 1; + register_snapshot_repository {{$repository.name}} fi {{ end }} diff --git a/elasticsearch/values.yaml b/elasticsearch/values.yaml index 15978c0c55..08dc82b7f3 100644 --- a/elasticsearch/values.yaml +++ b/elasticsearch/values.yaml @@ -28,7 +28,7 @@ images: helm_tests: docker.io/openstackhelm/heat:newton prometheus_elasticsearch_exporter: docker.io/justwatch/elasticsearch_exporter:1.0.1 dep_check: quay.io/stackanetes/kubernetes-entrypoint:v0.3.1 - snapshot_repository: docker.io/openstackhelm/heat:newton + snapshot_repository: docker.io/port/ceph-config-helper:v1.10.3 image_repo_sync: docker.io/docker:17.07.0 pull_policy: "IfNotPresent" local_registry: