You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Refresh proxy minion pillar on saltutil.refresh_pillar - #69754
Makes saltutil.refresh_pillar actually refresh pillar for a proxy minion without a restart. Two related, staged commits:
Re-pack the proxy loader's __pillar__ after the pillar rebind, so already-loaded proxy modules see the refreshed pillar on their next call (Fixes #58197).
Rebuild the exec-module loaders after the rebind on proxy minions, so salt[...] calls in states/execution see the refreshed pillar on the first run instead of the second (Fixes #59393).
Minion.pillar_refresh compiles a fresh pillar and rebinds self.opts["pillar"] to a new dict. Two loader graphs then hold stale pillar on a proxy minion:
Proxy loader ([BUG] Salt-proxy module __pillar__ and opts["pillar"] not refreshed on saltutil.refresh_pillar #58197): the proxy module loader packs the pillar once, at init, by reference (self.proxy.pack["__pillar__"] = self.opts["pillar"], salt/metaproxy/proxy.py). Module dunders resolve through the loader pack at call time, so the rebind orphaning that dict leaves proxy modules serving the pillar they were first packed with until the proxy process restarts.
Exec-module loaders ([BUG] saltutil.refresh_pillar does not work for proxy minions #59393):pillar_refresh calls module_refresh()before the rebind, so the rebuilt functions/returners/executors/utils loaders snapshot the old pillar (loaders deep-copy opts at construction). On a regular minion this is masked because every job rebuilds loaders via gen_modules(); a proxy minion's job path never does, so exec-module __pillar__ stays one refresh behind. The user-visible symptom is running the same command twice and getting two different answers.
New Behavior
After the rebind, on a proxy minion only (gated on opts["proxy"]):
The proxy loader's pack["__pillar__"] is re-assigned to the freshly compiled pillar. This is an atomic reference swap and does not call reload_modules() or re-run <proxytype>.init(), so each module's connection state and __context__ are preserved. It mirrors the existing deltaproxy __grains__ re-pack ([BUG] Deltaproxy returns the same data for all controlled minions #68248).
module_refresh() is run a second time so the exec loaders rebuild from the now-current opts["pillar"].
Deltaproxy is covered by the same change: handle_event dispatches each sub-proxy's pillar_refresh to that sub-proxy instance, so self is the sub-proxy and its own loaders are refreshed against its own pillar. Regular minions are untouched (both gate conditions are falsy), so their pillar_refresh path is byte-identical to before.
Why not reorder instead of a second module_refresh? Reordering the compile ahead of the first module_refresh was rejected: module_refresh() recomputes opts["grains"], and compile_pillar consumes those grains, so a reorder would compile pillar against one-refresh-stale grains for every minion -- relocating the same bug class to grains.
Scope / known limitations
Intentionally out of scope (load-time snapshots that stay stale under any non-reload fix, and not asserted fresh by the tests): __opts__, __opts__["pillar"], and any value a proxy module copied out of pillar during init().
Trade-off note for reviewers: the #59393 fix runs a second full module_refresh per refresh_pillar on proxy minions (re-reads grains, rebuilds the exec loaders). This is a proxy-scoped, correctness-neutral cost on an occasional operation. An in-place re-pack of the four exec loaders (stage-1 style) would avoid the reload but is more code and touches each loader's context_dict; module_refresh was chosen for robustness (it also re-syncs schedule.functions). Happy to switch to the in-place form if you prefer.
Merge requirements satisfied?
Docs - not applicable (behavior now matches the saltutil.refresh_pillar docstring, which promises a pillar refresh with no proxy carve-out)
Changelog - changelog/58197.fixed.md
Tests written/updated - tests/pytests/functional/metaproxy/test_proxy_pillar_refresh.py (proxy loader re-pack, deltaproxy per-sub-proxy isolation, SaltClientError keeps pack identity, regular-minion guards, connection/__context__ preserved) and test_proxy_exec_pillar_refresh.py (exec-module __pillar__ fresh after one refresh, second module_refresh runs only on proxies), plus tests/pytests/unit/metaproxy/test_proxy_pillar_refresh_routing.py. Both fixes are pin-proofed (the direct tests fail with the respective fix reverted).
One thing worth making explicit about scope, since a proxy's connection config lives in pillar (opts["proxy"] = pillar["proxy"], metaproxy/proxy.py:92): this PR refreshes the pillar values that proxy modules read at call time, but it intentionally does not re-apply the proxy connection config or reconnect. opts["proxy"] stays at its init-time value (consistent with the live connection), so changing proxytype/host/credentials in pillar still requires a proxy restart -- re-running init() on a refresh would drop the live connection, which is the exact behaviour this avoids. (Note: __pillar__["proxy"] itself will show the refreshed value; the live connection deliberately does not follow it.)
Hot-reconfiguring a proxy connection from a pillar change feels like a separate, opt-in feature rather than something refresh_pillar should do implicitly -- happy to file a follow-up issue for it if that's wanted.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Makes
saltutil.refresh_pillaractually refresh pillar for a proxy minion without a restart. Two related, staged commits:__pillar__after the pillar rebind, so already-loaded proxy modules see the refreshed pillar on their next call (Fixes #58197).salt[...]calls in states/execution see the refreshed pillar on the first run instead of the second (Fixes #59393).What issues does this PR fix or reference?
Fixes #58197
Fixes #59393
Previous Behavior
Minion.pillar_refreshcompiles a fresh pillar and rebindsself.opts["pillar"]to a new dict. Two loader graphs then hold stale pillar on a proxy minion:self.proxy.pack["__pillar__"] = self.opts["pillar"],salt/metaproxy/proxy.py). Module dunders resolve through the loader pack at call time, so the rebind orphaning that dict leaves proxy modules serving the pillar they were first packed with until the proxy process restarts.saltutil.refresh_pillardoes not work for proxy minions #59393):pillar_refreshcallsmodule_refresh()before the rebind, so the rebuiltfunctions/returners/executors/utilsloaders snapshot the old pillar (loaders deep-copy opts at construction). On a regular minion this is masked because every job rebuilds loaders viagen_modules(); a proxy minion's job path never does, so exec-module__pillar__stays one refresh behind. The user-visible symptom is running the same command twice and getting two different answers.New Behavior
After the rebind, on a proxy minion only (gated on
opts["proxy"]):pack["__pillar__"]is re-assigned to the freshly compiled pillar. This is an atomic reference swap and does not callreload_modules()or re-run<proxytype>.init(), so each module's connection state and__context__are preserved. It mirrors the existing deltaproxy__grains__re-pack ([BUG] Deltaproxy returns the same data for all controlled minions #68248).module_refresh()is run a second time so the exec loaders rebuild from the now-currentopts["pillar"].Deltaproxy is covered by the same change:
handle_eventdispatches each sub-proxy'spillar_refreshto that sub-proxy instance, soselfis the sub-proxy and its own loaders are refreshed against its own pillar. Regular minions are untouched (both gate conditions are falsy), so theirpillar_refreshpath is byte-identical to before.Why not reorder instead of a second
module_refresh? Reordering the compile ahead of the firstmodule_refreshwas rejected:module_refresh()recomputesopts["grains"], andcompile_pillarconsumes those grains, so a reorder would compile pillar against one-refresh-stale grains for every minion -- relocating the same bug class to grains.Scope / known limitations
Intentionally out of scope (load-time snapshots that stay stale under any non-reload fix, and not asserted fresh by the tests):
__opts__,__opts__["pillar"], and any value a proxy module copied out of pillar duringinit().Trade-off note for reviewers: the #59393 fix runs a second full
module_refreshperrefresh_pillaron proxy minions (re-reads grains, rebuilds the exec loaders). This is a proxy-scoped, correctness-neutral cost on an occasional operation. An in-place re-pack of the four exec loaders (stage-1 style) would avoid the reload but is more code and touches each loader'scontext_dict;module_refreshwas chosen for robustness (it also re-syncsschedule.functions). Happy to switch to the in-place form if you prefer.Merge requirements satisfied?
saltutil.refresh_pillardocstring, which promises a pillar refresh with no proxy carve-out)changelog/58197.fixed.mdtests/pytests/functional/metaproxy/test_proxy_pillar_refresh.py(proxy loader re-pack, deltaproxy per-sub-proxy isolation, SaltClientError keeps pack identity, regular-minion guards, connection/__context__preserved) andtest_proxy_exec_pillar_refresh.py(exec-module__pillar__fresh after one refresh, secondmodule_refreshruns only on proxies), plustests/pytests/unit/metaproxy/test_proxy_pillar_refresh_routing.py. Both fixes are pin-proofed (the direct tests fail with the respective fix reverted).Commits signed with GPG?
No