diff --git a/elasticsearch/templates/bin/_register-repository.sh.tpl b/elasticsearch/templates/bin/_register-repository.sh.tpl index 983e8024d..3b940bbc9 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 15978c0c5..08dc82b7f 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: