From c1241918c2c34a97d08e3f7382fa1c51715e3891 Mon Sep 17 00:00:00 2001 From: Graham Steffaniak Date: Wed, 13 Jan 2021 19:43:46 +0000 Subject: [PATCH] Add elasticsearch ILM functionality Add functionality to delete indexes older than 14 days. ILM api will handle deleting indexes. Change-Id: I22c02af78b6ce979d0c70b420c106917b0fc5a4e --- elasticsearch/Chart.yaml | 2 +- .../templates/bin/_create_template.sh.tpl | 14 ++++++++++++++ .../templates/configmap-etc-templates.yaml | 3 +++ .../templates/job-elasticsearch-template.yaml | 6 ++++++ elasticsearch/values.yaml | 9 ++++++++- 5 files changed, 32 insertions(+), 2 deletions(-) diff --git a/elasticsearch/Chart.yaml b/elasticsearch/Chart.yaml index 808cd0b467..363c7f4665 100644 --- a/elasticsearch/Chart.yaml +++ b/elasticsearch/Chart.yaml @@ -15,7 +15,7 @@ apiVersion: v1 appVersion: v7.1.0 description: OpenStack-Helm ElasticSearch name: elasticsearch -version: 0.1.3 +version: 0.1.4 home: https://www.elastic.co/ sources: - https://github.com/elastic/elasticsearch diff --git a/elasticsearch/templates/bin/_create_template.sh.tpl b/elasticsearch/templates/bin/_create_template.sh.tpl index 6eb8736179..2ed3effb85 100644 --- a/elasticsearch/templates/bin/_create_template.sh.tpl +++ b/elasticsearch/templates/bin/_create_template.sh.tpl @@ -28,4 +28,18 @@ else echo "Policy {{$policy_name}} not created!" fi +{{ end }} + +{{ range $policy_name, $fields := .Values.conf.index_policies }} + +result=$(curl -K- <<< "--user ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}" \ +-XPUT "${ELASTICSEARCH_HOST}:${ELASTICSEARCH_PORT}/_ilm/policy/{{$policy_name}}" \ +-H 'Content-Type: application/json' -d @/tmp/{{$policy_name}}.json \ +| python -c "import sys, json; print(json.load(sys.stdin)['acknowledged'])") +if [ "$result" == "True" ]; then + echo "Policy {{$policy_name}} created!" +else + echo "Policy {{$policy_name}} not created!" +fi + {{ end }} \ No newline at end of file diff --git a/elasticsearch/templates/configmap-etc-templates.yaml b/elasticsearch/templates/configmap-etc-templates.yaml index 7f4d0f36f0..b8cf7c21c9 100644 --- a/elasticsearch/templates/configmap-etc-templates.yaml +++ b/elasticsearch/templates/configmap-etc-templates.yaml @@ -28,5 +28,8 @@ data: {{ range $policy_name, $fields := .Values.conf.snapshot_policies }} {{ $policy_name }}.json: {{ toJson $fields | b64enc }} {{ end }} +{{ range $policy_name, $fields := .Values.conf.index_policies }} + {{ $policy_name }}.json: {{ toJson $fields | b64enc }} +{{ end }} {{- end }} diff --git a/elasticsearch/templates/job-elasticsearch-template.yaml b/elasticsearch/templates/job-elasticsearch-template.yaml index 38ee62d9c3..ef05f85152 100644 --- a/elasticsearch/templates/job-elasticsearch-template.yaml +++ b/elasticsearch/templates/job-elasticsearch-template.yaml @@ -84,6 +84,12 @@ spec: subPath: {{$policy_name}}.json readOnly: true {{ end }} + {{ range $policy_name, $fields := .Values.conf.index_policies }} + - name: elasticsearch-templates-etc + mountPath: /tmp/{{$policy_name}}.json + subPath: {{$policy_name}}.json + readOnly: true + {{ end }} {{ if $mounts_elasticsearch_templates.volumeMounts }}{{ toYaml $mounts_elasticsearch_templates.volumeMounts | indent 12 }}{{ end }} volumes: - name: pod-tmp diff --git a/elasticsearch/values.yaml b/elasticsearch/values.yaml index b1f79f5f60..c2aa13132f 100644 --- a/elasticsearch/values.yaml +++ b/elasticsearch/values.yaml @@ -807,7 +807,14 @@ conf: disable_action: false retention: expire_after: 179d - + index_policies: + delete_all_indexes: + policy: + phases: + delete: + min_age: 14d + actions: + delete: {} endpoints: cluster_domain_suffix: cluster.local local_image_registry: