Skip to content

Fix "No matching salt environment" for envs outside env_order (#70618) - #70695

Open
va000612 wants to merge 2 commits into
saltstack:3008.xfrom
va000612:fix/70618-lazyavailstates-ignore-env-order
Open

va000612 wants to merge 2 commits into
saltstack:3008.xfrom
va000612:fix/70618-lazyavailstates-ignore-env-order

Conversation

@va000612

@va000612 va000612 commented Nov 5, 2026

Copy link
Copy Markdown

What does this PR do?

Fixes No matching salt environment for environment '...' found being reported for fileserver environments that are not listed in env_order.

LazyAvailStates builds the list of available saltenvs from BaseHighState._get_envs(). When env_order is configured, _get_envs() returns only the environments listed in env_order, so any other environment on the fileserver is treated as unknown by render_highstate. This hits gitfs branches exposed through gitfs_saltenv_whitelist (for example feature/.*), which can't be listed statically in env_order. The master serves them correctly. fileserver.envs, fileserver.file_list and cp.list_states all show the env, and the sls is still rendered, but every run reports the error.

The fix:

  • _get_envs() takes a new restrict_to_env_order argument, default True, so existing behavior is unchanged. get_tops still uses it to order and limit top-file evaluation.
  • LazyAvailStates._fill calls _get_envs(restrict_to_env_order=False), so every environment known to the fileserver counts as available.
  • A non-existent env still errors.

What issues does this PR fix or reference?

Fixes: #70618

Previous Behavior

With env_order: [base, prod, staging, dev] and gitfs_saltenv_whitelist: [prod, staging, dev, 'feature/.*'], running salt-call state.show_sls mystate saltenv=feature/myfeature returned No matching salt environment for environment 'feature/myfeature' found, although salt-run fileserver.envs listed the branch.

New Behavior

The same command renders the sls with no error. Envs inside env_order behave as before, and an env that does not exist on the fileserver still errors.

Merge requirements satisfied?

  • Docs
  • Changelog: changelog/70618.fixed.md
  • Tests written/updated: tests/pytests/unit/state/test_lazy_avail_states.py

Testing

Unit tests (pytest --core-tests):

  • tests/pytests/unit/state/test_lazy_avail_states.py (new, 4 tests): _get_envs() is still limited to env_order by default; the unrestricted call includes envs outside env_order; an empty fileserver env list falls back to env_order; LazyAvailStates accepts an env outside env_order and still rejects a non-existent one.
  • tests/pytests/unit/state/test_state_options.py: 5 passed together with the above.

Manual reproduction and verification (master and minion, Salt 3008.5, Python 3.11, Rocky 8.10, gitfs_provider: gitpython, ssh:// remote):

Config:
gitfs_saltenv_whitelist: [prod, staging, dev, 'feature/.*']
env_order: [base, prod, staging, dev]
top_file_merging_strategy: merge_all

After pushing a new branch feature/seven and running salt-run fileserver.update:

Check Before After
salt-run fileserver.envs lists feature/seven same
salt-run fileserver.file_list saltenv=feature/seven mystate/init.sls same
salt-call state.show_sls mystate saltenv=feature/seven No matching salt environment renders
salt '<minion>' state.show_sls mystate saltenv=feature/seven No matching salt environment renders
show_sls ... saltenv=prod (in env_order) renders renders
show_sls ... saltenv=doesnotexist errors still errors

Without env_order the same setup rendered correctly before the patch (3008.4 pygit2 and GitPython, 3008.5 GitPython), which isolates env_order as the cause.

Commits signed with GPG?

No

@va000612
va000612 requested a review from a team as a code owner November 5, 2026 10:06
@twangboy twangboy added the test:full Run the full test suite label Nov 5, 2026
@twangboy
twangboy force-pushed the fix/70618-lazyavailstates-ignore-env-order branch from fd5b3d2 to e78edb9 Compare November 5, 2026 23:48
@twangboy twangboy added this to the Argon v3008.7 milestone Nov 5, 2026
twangboy
twangboy previously approved these changes Nov 5, 2026
va000612 and others added 2 commits November 12, 2026 11:36
…ack#70618)

LazyAvailStates builds the list of available saltenvs from
BaseHighState._get_envs(), which, when env_order is configured, returns only
the environments listed in env_order. Fileserver environments that are not
(and cannot be) listed there, such as gitfs branches exposed through
gitfs_saltenv_whitelist, were therefore reported as "No matching salt
environment for environment '...' found" by render_highstate, even though the
master served them.

Add a restrict_to_env_order argument to _get_envs() (default True, so top
file evaluation in get_tops is unchanged) and have LazyAvailStates ask for
the unrestricted list.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…stack#70618)

Covers the end-to-end path through ``state.show_sls`` and ``state.sls`` for
an environment that is served by the fileserver but not listed in
``env_order``. The existing unit tests exercise ``BaseHighState._get_envs``
and ``LazyAvailStates._fill`` in isolation; this integration test stands up
a real master + minion whose ``env_order`` is intentionally narrower than
its ``file_roots``, which is the configuration that reproduced the bug on
3008.x.

Pre-fix behaviour (reproduced on origin/3008.x f5180cd) is::

    salt-call state.show_sls mystate saltenv=feature_branch
    -> ["No matching salt environment for environment 'feature_branch' found"]

Post-fix the same call returns the rendered high-state. The suite also
asserts that envs inside ``env_order`` still render, and that a truly
unknown saltenv still produces the diagnostic so the fix does not silently
accept every env.

This branch was successfully deployed

1 active deployment
ci — 62640a40 Deployed Nov 12, 2026 by va000612 via Build Onedir Packages / RPM (arm64) #28826
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.

[Bug]: Automatic saltenv's from branches with wildcards not working as expected

3 participants