Skip to content

Fix pillarenv targeting with isolated pillar compilation caches - #70467

Merged
dwoz merged 6 commits into
saltstack:3008.xfrom
charzl:charzl/fix-pillar-targeting-cache-banks
Nov 24, 2026
Merged

dwoz merged 6 commits into
saltstack:3008.xfrom
charzl:charzl/fix-pillar-targeting-cache-banks

Conversation

@charzl

@charzl charzl commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

Fix pillar targeting (-I, -J) for minions that use a pillarenv, including when pillar_cache is enabled.

Before, PillarCache stored the compiled pillar under <id>:<pillarenv>, but targeting reads <id>, so these minions never matched. Writing the environment result into <id> would also overwrite the compile cache used by requests without a pillarenv.

The two caches are now separate:

  • Compile cache: pillar_compile bank, using pillar.cache_driver when configured and pillar_cache_ttl. Only used when pillar_cache is on.
  • Targeting data: pillar/<id> in the default cache backend. The _pillar handlers (sync, async, RemoteFuncs) write it, like grains, including on compile cache hits.

Only a minion's regular pillar fetch updates the targeting data, because only that fetch replaces the pillar the minion holds. The minion marks those requests with a new snapshot field: startup, saltutil.refresh_pillar, proxy startup, and state.apply with the configured pillarenv and no pillar override. These do not update it:

  • one-off queries such as pillar.items pillarenv=prod
  • requests with pillar_override
  • state.apply pillarenv=prod (get_sls_opts flags runs whose pillarenv differs from the minion config)
  • direct compilation (pillar.show_pillar, runner queries)

Minions that do not send the field keep the old behavior, except that a request with pillar_override never updates the targeting data.

get_pillar returns PillarCache only when pillar_cache is on. pillar.show_pillar_cache and pillar.clear_pillar_cache now require pillar_cache, since they only handle the compile cache.

Upgrade notes

  • No config change needed. The caches only hold data that can be rebuilt. Grains, mine, keys and pillar files are not touched.
  • After upgrading, run saltutil.refresh_pillar (or restart the minions). Until then -I/-J still misses minions that use a pillarenv.
  • With pillar_cache: True the compile cache starts empty, so each minion/environment is compiled again on its next request. Refreshing many minions at once briefly raises the master load.
  • Old <id>:<pillarenv> files in the pillar bank are no longer used. They are not deleted.
  • pillar.clear_pillar_cache clears compile entries; cache.clear_pillar clears targeting data. The next regular pillar fetch of a minion restores it, even on a compile cache hit.
  • Minions not yet upgraded do not send the snapshot field, so a one-off pillarenv query from them still updates the targeting data.

Risks

  • Targeting data is only as fresh as the minion's last regular fetch.
  • After a downgrade, run cache.clear_pillar. Older versions read this data as a compile cache.

Testing

  • Unit tests for the handlers, the snapshot flag, get_sls_opts, get_pillar and the runners.
  • New integration tests (tests/pytests/integration/pillar/test_pillarenv_targeting.py) with a real master (pillar_cache: True) and a minion with pillarenv: dev: 8 passed locally. All 8 fail without this change.
  • Related unit tests pass. test_minion_manager_async_stop and test_minion_manager_destroy_closes_event_publisher fail locally on the base branch as well.
  • Not run locally: the nox lint sessions (the pinned filelock is not available on my package mirror). pylint on the changed files is clean.

Refs #69599

@charzl charzl added test:full Run the full test suite Argon v3008.0 labels Nov 4, 2026
@charzl charzl added this to the Potassium v3009.0 milestone Nov 4, 2026
@charzl
charzl marked this pull request as ready for review November 4, 2026 00:33
@charzl
charzl requested a review from a team as a code owner November 4, 2026 00:33
twangboy
twangboy previously approved these changes Nov 5, 2026
Comment thread salt/pillar/__init__.py Resolved
twangboy
twangboy previously approved these changes Nov 17, 2026
…etches

The previous commit wrote the minion data cache snapshot from every _pillar
request, so one-off queries (pillar.items pillarenv=prod) and requests with a
pillar override replaced what -I/-J match against, including for minions
that were not affected by the original bug.

RemotePillar and AsyncRemotePillar now send a "snapshot" field. The minion
sets it on its own regular fetches (startup, refresh_pillar, proxy startup,
highstate without an override); one-off callers leave it off. The master
refreshes the snapshot only when the field is set and no pillar_override is
present. Minions that predate the field keep the old behavior unless they send
an override.

pillar.show_pillar_cache and pillar.clear_pillar_cache now require
pillar_cache, since they only manage the compilation cache.
…larenv

state.apply pillarenv=prod fetches pillar through the same request as a
regular highstate, so the master stored the prod result for a minion that
keeps using its configured pillarenv.

get_sls_opts now flags opts when the run's pillarenv differs from the minion
config (explicit kwarg, localconfig or pillarenv_from_saltenv), and
State._gather_pillar sends no snapshot for such runs. A highstate with the
configured pillarenv and no pillar override still refreshes it.
Integration tests start a master with pillar_cache and a minion configured
with pillarenv: dev, and check -I/-J targeting after a regular refresh, after
one-off pillarenv and pillar override queries, and after state.apply with
another pillarenv. They also check that a regular state.apply restores the
targeting data and that compiled pillars of different environments stay
separate.

Unit tests cover the snapshot decision in all three _pillar handlers, the
flag sent by the minion refresh, and when get_pillar uses PillarCache.
pylint 3.1.1 on Python 3.10 hit a RecursionError while inferring the
operand of one comparison in test_targeting_cache.py. Compare the cache value
directly, like the other assertions in the file.
Keep the original opening line and describe the new cache layout: compiled
pillars live in the pillar_compile bank, keyed by minion id and pillarenv,
apart from the pillar snapshot that targeting reads.

This branch was previously deployed

1 inactive deployment
ci — 5ca7ab33 Deployed Nov 24, 2026 by charzl via Build Onedir Packages / Windows (amd64) #29616
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Argon v3008.0 test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: pillar masking in 3008 breaks the world

3 participants