From ac907ba45fe6f146b7ee753b61c8d872557e929c Mon Sep 17 00:00:00 2001 From: reyesj2 <94730068+reyesj2@users.noreply.github.com> Date: Fri, 5 Jun 2026 16:42:08 -0500 Subject: [PATCH] fix elasticsearch template generation issue --- salt/elasticsearch/cluster.sls | 19 ++++++++++++++++++- salt/elasticsearch/template.map.jinja | 27 +++++++++++++++++++++++---- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/salt/elasticsearch/cluster.sls b/salt/elasticsearch/cluster.sls index e25aed36a..d20ee45ca 100644 --- a/salt/elasticsearch/cluster.sls +++ b/salt/elasticsearch/cluster.sls @@ -9,9 +9,12 @@ {% from 'elasticsearch/config.map.jinja' import ELASTICSEARCHMERGED %} {% from 'elasticsearch/template.map.jinja' import ES_INDEX_SETTINGS, SO_MANAGED_INDICES %} {% if GLOBALS.role != 'so-heavynode' %} -{% from 'elasticsearch/template.map.jinja' import ALL_ADDON_SETTINGS %} +{% from 'elasticsearch/template.map.jinja' import ALL_ADDON_SETTINGS, ADDON_INDICES %} {% endif %} +include: + - elasticsearch.enabled + escomponenttemplates: file.recurse: - name: /opt/so/conf/elasticsearch/templates/component @@ -35,6 +38,20 @@ so_index_template_dir: {%- endfor %} {%- endif %} +{% if GLOBALS.role != "so-heavynode" %} +# Clean up legacy and non-SO managed templates from the elasticsearch/templates/addon-index/ directory +addon_index_template_dir: + file.directory: + - name: /opt/so/conf/elasticsearch/templates/addon-index + - clean: True + {%- if ADDON_INDICES %} + - require: + {%- for index in ADDON_INDICES %} + - file: addon_index_template_{{index}} + {%- endfor %} + {%- endif %} +{% endif %} + # Auto-generate index templates for SO managed indices (directly defined in elasticsearch/defaults.yaml) # These index templates are for the core SO datasets and are always required {% for index, settings in ES_INDEX_SETTINGS.items() %} diff --git a/salt/elasticsearch/template.map.jinja b/salt/elasticsearch/template.map.jinja index e66057775..ed1b49abe 100644 --- a/salt/elasticsearch/template.map.jinja +++ b/salt/elasticsearch/template.map.jinja @@ -61,15 +61,25 @@ {% if ALL_ADDON_SETTINGS_ORIG.keys() | length > 0 %} {% for index in ALL_ADDON_SETTINGS_ORIG.keys() %} {% do ALL_ADDON_SETTINGS_GLOBAL_OVERRIDES.update({index: salt['defaults.merge'](ALL_ADDON_SETTINGS_ORIG[index], PILLAR_GLOBAL_OVERRIDES, in_place=False)}) %} +{# Explicitly excluding addon indices from ES_INDEX_SETTINGS_ORIG + When manager.soc_managed_annotations runs, new entries are added to the salt/elasticsearch/defaults.yaml file to support 'revert to default' functionality. + Subsequent map renders will then incorrectly include 'integration X' in 'ES_INDEX_SETTINGS_ORIG' due to being in the defaults.yaml file. #} +{% if index in ES_INDEX_SETTINGS_ORIG.keys() %} +{% do ES_INDEX_SETTINGS_ORIG.pop(index) %} +{% endif %} {% endfor %} {% endif %} {% set ES_INDEX_SETTINGS = {} %} -{% macro create_final_index_template(DEFINED_SETTINGS, GLOBAL_OVERRIDES, FINAL_INDEX_SETTINGS) %} +{% macro create_final_index_template(DEFINED_SETTINGS, GLOBAL_OVERRIDES, FINAL_INDEX_SETTINGS, EXCLUDE_INDICES=[]) %} {% do GLOBAL_OVERRIDES.update(salt['defaults.merge'](GLOBAL_OVERRIDES, ES_INDEX_PILLAR, in_place=False)) %} {% for index, settings in GLOBAL_OVERRIDES.items() %} +{% if index in EXCLUDE_INDICES %} +{% continue %} +{% endif %} + {# prevent this action from being performed on custom defined indices. #} {# the custom defined index is not present in either of the dictionaries and fails to reder. #} {% if index in DEFINED_SETTINGS and index in GLOBAL_OVERRIDES %} @@ -150,10 +160,19 @@ {% endfor %} {% endmacro %} -{{ create_final_index_template(ES_INDEX_SETTINGS_ORIG, ES_INDEX_SETTINGS_GLOBAL_OVERRIDES, ES_INDEX_SETTINGS) }} -{{ create_final_index_template(ALL_ADDON_SETTINGS_ORIG, ALL_ADDON_SETTINGS_GLOBAL_OVERRIDES, ALL_ADDON_SETTINGS) }} +{# Exclude addon integrations from final ES_INDEX_SETTINGS #} +{{ create_final_index_template(ES_INDEX_SETTINGS_ORIG, ES_INDEX_SETTINGS_GLOBAL_OVERRIDES, ES_INDEX_SETTINGS, ALL_ADDON_SETTINGS_ORIG.keys() | list ) }} + +{# Exclude SO managed indices, otherwise ALL_ADDON_SETTINGS will include pillar values + of core integrations without merging defaults, resulting in an overlapping, but bad index template being generated. #} +{{ create_final_index_template(ALL_ADDON_SETTINGS_ORIG, ALL_ADDON_SETTINGS_GLOBAL_OVERRIDES, ALL_ADDON_SETTINGS, ES_INDEX_SETTINGS_ORIG.keys() | list ) }} {% set SO_MANAGED_INDICES = [] %} {% for index, settings in ES_INDEX_SETTINGS.items() %} {% do SO_MANAGED_INDICES.append(index) %} -{% endfor %} \ No newline at end of file +{% endfor %} + +{% set ADDON_INDICES = [] %} +{% for index, settings in ALL_ADDON_SETTINGS.items() %} +{% do ADDON_INDICES.append(index) %} +{% endfor %}