Skip to content

Add __env__ substitution inside file and pillar root paths#61531

Merged
Ch3LL merged 9 commits into
saltstack:masterfrom
nicholasmhughes:add-dynamic-file-root-paths
Feb 15, 2022
Merged

Add __env__ substitution inside file and pillar root paths#61531
Ch3LL merged 9 commits into
saltstack:masterfrom
nicholasmhughes:add-dynamic-file-root-paths

Conversation

@nicholasmhughes

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds __env__ substitution inside file and pillar root paths

What issues does this PR fix or reference?

Addresses the spirit of this issue: #55747, but not the exact implementation of the resulting PR (#55812)... which may be abandoned at this time.

Previous Behavior

The __env__ designation could be used as a key underneath the file_roots or pillar_roots configuration to provide a "catch-all" root location to provide minions with random saltenv and/or pillarenv set. The configuration below would send minions with saltenv set to base, foo, and bar to the same location:

file_roots:
  __env__:
    - /srv/salt

However, there wasn't a way to dynamically set a different path location for each environment. The configuration below would be literally interpreted as /srv/__env__/salt for each environment.

file_roots:
  __env__:
    - /srv/__env__/salt

New Behavior

This PR takes dynamic environments one step further so __env__ can also be used in the file_roots and pillar_roots paths. It will be replaced with the actual saltenv or pillarenv and searched for states and/or data to provide to the minion. For instance, this configuration:

file_roots:
  __env__:
    - /srv/__env__/salt

is now equivalent to this static configuration:

file_roots:
  base:
    - /srv/base/salt
  foo:
    - /srv/foo/salt
  bar:
    - /srv/bar/salt

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

Yes

Please review Salt's Contributing Guide for best practices.

See GitHub's page on GPG signing for more information about signing commits with GPG.

@nicholasmhughes nicholasmhughes requested a review from a team as a code owner January 27, 2022 13:22
@nicholasmhughes nicholasmhughes requested review from MKLeb and removed request for a team January 27, 2022 13:22
Comment thread salt/fileserver/roots.py Outdated
@nicholasmhughes

Copy link
Copy Markdown
Contributor Author

re-run all

@MKLeb

MKLeb commented Jan 31, 2022

Copy link
Copy Markdown
Contributor

@nicholasmhughes Sorry, CI is currently broken but there is a PR up to fix it. I'll rerun after that is merged and then likely approve this.

@nicholasmhughes

Copy link
Copy Markdown
Contributor Author

re-run pr-ubuntu-2004-arm64-py3-pytest

@nicholasmhughes

Copy link
Copy Markdown
Contributor Author

re-run pr-centos-7-x86_64-py3-pycryptodome-pytest

@nicholasmhughes

Copy link
Copy Markdown
Contributor Author

re-run pr-centos-8-x86_64-py3-pytest

@MKLeb

MKLeb commented Feb 1, 2022

Copy link
Copy Markdown
Contributor

test failure looks unrelated, will review then

@MKLeb MKLeb self-requested a review February 1, 2022 23:06
MKLeb
MKLeb previously approved these changes Feb 1, 2022
@nicholasmhughes

Copy link
Copy Markdown
Contributor Author

re-run pr-ubuntu-2004-arm64-py3-pytest

@nicholasmhughes

Copy link
Copy Markdown
Contributor Author

re-run pr-centos-7-x86_64-py3-m2crypto-pytest

@nicholasmhughes

Copy link
Copy Markdown
Contributor Author

@MKLeb is everything good with this PR?

@MKLeb

MKLeb commented Feb 8, 2022

Copy link
Copy Markdown
Contributor

Looks good on my end. I've sent it around internally to have others take a look as well, but if there are no concerns then it should be good to go.

Comment thread tests/pytests/functional/fileserver/test_roots.py Outdated
Comment thread tests/pytests/functional/fileserver/test_roots.py Outdated
Comment thread tests/pytests/functional/fileserver/test_roots.py Outdated
@MKLeb

MKLeb commented Feb 8, 2022

Copy link
Copy Markdown
Contributor

Sorry, just took another look at the test code. A couple of simple changes to make it more "pytest-y" if you will.

@MKLeb MKLeb self-requested a review February 8, 2022 16:36
Comment thread tests/pytests/functional/fileserver/test_roots.py Outdated
Comment thread tests/pytests/functional/fileserver/test_roots.py Outdated
@nicholasmhughes

Copy link
Copy Markdown
Contributor Author

re-run pr-arch-lts-x86_64-py3-pytest

1 similar comment
@nicholasmhughes

Copy link
Copy Markdown
Contributor Author

re-run pr-arch-lts-x86_64-py3-pytest

@morgana2313

morgana2313 commented Aug 26, 2022

Copy link
Copy Markdown
Contributor

I'm happy to see my ideas from #55747 were implemented and merged! 👍

I think this new __env__ behaviour should also land in the pillar.stack:

ext_pillar:
  - stack:
      pillar:environment:
        __env__: /path/__env__/pillar/stack.cfg
        __env__: /path2/__env__/pillar/stack.cfg

My PR #55812 shows how this might be accomplished:

- stack_config_files += cfgs
+ stack_config_files += [cfg.replace("__env__", pillarenv) for cfg in cfgs]

@nicholasmhughes would you be willing to cooperate on this?

@nicholasmhughes

Copy link
Copy Markdown
Contributor Author

@morgana2313 , happy to help in any way I can! Feel free to reach out on Slack if it's easier to coordinate that way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants