Skip to content

Refresh proxy minion pillar on saltutil.refresh_pillar - #69754

Merged
dwoz merged 4 commits into
saltstack:3006.xfrom
ggiesen:fix-58197-proxy-pillar-refresh
Aug 5, 2026
Merged

dwoz merged 4 commits into
saltstack:3006.xfrom
ggiesen:fix-58197-proxy-pillar-refresh

Conversation

@ggiesen

@ggiesen ggiesen commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Makes saltutil.refresh_pillar actually refresh pillar for a proxy minion without a restart. Two related, staged commits:

  1. 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).
  2. 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).

What issues does this PR fix or reference?

Fixes #58197
Fixes #59393

Previous Behavior

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).

Commits signed with GPG?

No

@ggiesen

ggiesen commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

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.

@charzl charzl self-assigned this Jul 10, 2026
@dwoz dwoz added the test:full Run the full test suite label Jul 10, 2026
@twangboy twangboy added this to the Sulphur v3006.28 milestone Jul 15, 2026
@dwoz
dwoz merged commit 2a0382b into saltstack:3006.x Aug 5, 2026
852 of 854 checks passed

This branch was previously deployed

1 inactive deployment
ci — e3e6a739 Deployed Jul 29, 2026 by ggiesen via Build Onedir Packages / Windows (x86) #25943
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants