diff --git a/salt/elasticfleet/manager.sls b/salt/elasticfleet/manager.sls index fbef61e1f..9a27ea6e9 100644 --- a/salt/elasticfleet/manager.sls +++ b/salt/elasticfleet/manager.sls @@ -68,6 +68,15 @@ so-elastic-fleet-package-upgrade: - require: - http: wait_for_so-kibana +# initial so-elasticsearch-templates run is earlier, but it can skip over templates that have component templates not yet installed to avoid elasticsearch rejecting the template. +so-elasticsearch-templates-after-fleet-packages: + cmd.run: + - name: /usr/sbin/so-elasticsearch-templates-load + - cwd: /opt/so + - unless: test -f /opt/so/state/estemplates.txt + - require: + - cmd: so-elastic-fleet-package-upgrade + so-elastic-fleet-integration-upgrade: cmd.run: - name: /usr/sbin/so-elastic-fleet-integration-upgrade @@ -101,6 +110,7 @@ so-elastic-fleet-addon-integrations: - name: /usr/sbin/so-elastic-fleet-optional-integrations-load - require: - http: wait_for_so-kibana + - cmd: so-elasticsearch-templates-after-fleet-packages {% if ELASTICFLEETMERGED.config.defend_filters.enable_auto_configuration %} so-elastic-defend-manage-filters-file-watch: diff --git a/salt/elasticfleet/tools/sbin_jinja/so-elastic-fleet-package-upgrade b/salt/elasticfleet/tools/sbin_jinja/so-elastic-fleet-package-upgrade index 1b1b79e56..8a63859e5 100644 --- a/salt/elasticfleet/tools/sbin_jinja/so-elastic-fleet-package-upgrade +++ b/salt/elasticfleet/tools/sbin_jinja/so-elastic-fleet-package-upgrade @@ -10,6 +10,7 @@ PKG_LOAD_FAILURES=0 PKG_LOAD_FAILURES_NAMES=() +PKG_UPGRADED=0 cleanup_elasticsearch_fleet_transforms() { local transforms transform_id attempt @@ -49,6 +50,7 @@ if INSTALLED_VERSION=$(elastic_fleet_package_version_check "{{ PACKAGE }}") && L PKG_LOAD_FAILURES_NAMES+=("{{ PACKAGE }}") elif INSTALLED_VERSION=$(elastic_fleet_package_version_check "{{ PACKAGE }}") && [ "$INSTALLED_VERSION" == "$LATEST_VERSION" ]; then echo "{{ PACKAGE }} integration upgraded to version $LATEST_VERSION." + PKG_UPGRADED=$((PKG_UPGRADED + 1)) else echo "ERROR: {{ PACKAGE }} integration still at ${INSTALLED_VERSION:-unknown}; expected $LATEST_VERSION" PKG_LOAD_FAILURES=$((PKG_LOAD_FAILURES + 1)) @@ -62,6 +64,11 @@ else fi {%- endfor %} +if [ $PKG_UPGRADED -gt 0 ]; then + echo "Elasticsearch template statefiles cleared after $PKG_UPGRADED package upgrade(s), so templates can reload." + rm -f /opt/so/state/estemplates.txt /opt/so/state/addon_estemplates.txt +fi + if [ $PKG_LOAD_FAILURES -gt 0 ]; then echo "ERROR: Failed to upgrade $PKG_LOAD_FAILURES package(s):" for PKG in "${PKG_LOAD_FAILURES_NAMES[@]}"; do diff --git a/salt/manager/tools/sbin/soup b/salt/manager/tools/sbin/soup index 672941bee..b0fb42e8e 100755 --- a/salt/manager/tools/sbin/soup +++ b/salt/manager/tools/sbin/soup @@ -2145,7 +2145,13 @@ main() { check_saltmaster_status postupgrade_changes [[ $is_airgap -eq 0 ]] && unmount_update - + + if [[ "$es_version" != "$target_es_version" ]]; then + # Run final elasticsearch state on manager to ensure addon index templates are created/regenerated and loaded + echo "Running final elasticsearch state at $(date +"%T.%6N"), after upgrade to $POSTVERSION" + salt-call state.apply elasticsearch queue=True + fi + echo "" echo "Upgrade to $NEWVERSION complete."