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
This commit is contained in:
Steve Wilkerson 2019-02-21 13:34:51 -06:00 committed by Chris Wedgwood
parent 47d429059c
commit f361fd6477
2 changed files with 36 additions and 19 deletions

View File

@ -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 }}

View File

@ -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: