Skip to content

Support top_file_merging_strategy=same equivalent for pillar #28682

Closed

Description

@knuta

I have a similar use-case as what introduced top_file_merging_strategy=same (see #12483), and use it to ensure that only the top file of my current saltenv gets used. This allows me to keep identical topfiles in each environment, simply by using '{{ env }}:' instead of hardcoding the environment names in the topfiles. I can then easily merge my new topfiles into my base environment when testing is complete.

git_pillar describes a similar use-case (see https://docs.saltstack.com/en/latest/ref/pillar/all/salt.pillar.git_pillar.html), where env is used as a placeholder to keep a generic topfile in the base gitfs_base branch, and "{{ env }}:" is used in the topfile. This doesn't solve my problem, though, since I want to allow testing of alternate topfiles, and also do not use git_pillar (I prefer files, since this allows testing before commiting).

An ideal solution for me would be something like this:

  • Configuring the master with pillar_top_file_merging_strategy=same will make the master only use the topfile from the current saltenv. This should work in both state.highstate as well as pillar.items and friends.
  • The saltenv is passed to the template (currently, templates in the pillar always have saltenv set to 'base', which is both useless and confusing)

In addition to solving my problem, I believe this would also solve the use-cases described in #20506 as well as the one presented in the comments of #4389.

Activity

  1. added
    Feature
    Core
    on Nov 10, 2015
  2. added this to the Approved milestone on Nov 10, 2015
  3. jfindlay commented on Nov 10, 2015

    @jfindlay
    Contributor

    @knuta, thanks for the well-researched issue. This is something I have wanted to do as well.

  4. ealphonse commented on May 12, 2016

    @ealphonse

    I agree it makes sense that the pillar facility matches the salt side. I use the much wanted top_file_merging_strategy=same option to stage my code deployments (salt + pillar files) but as pillar tops are merged, I end up with conflicting pillar files with merged values between QA and production for example.

    Having the possibility to use the same setting for both sides would allow a simple workflow for continuous deployment pipelines.

    Is this functionality planned?

  5. added
    P2
    and removed on Jun 8, 2016
  6. ealphonse commented on Jun 23, 2016

    @ealphonse

    Hello @jfindlay , hello @knuta,

    I do not know if this feature is in the process of begin implemented, but I wonder what could be the impact of the pillarenv option on this.

    If I understand correctly from the specifications given above, pillar_top_file_merging_strategy=same would allow to only use pillar data from the same env as specified by the saltenv option. This behavior would be equivalent to specify pillarenv=env, the later being more versatile as the env could be different as exemplified in #18808.

    On the other hand, the pillarenv option looks more like a hack for now as it is not well documented (what does it do exactly, what is its purpose), and seems to be implemented on a feature-request basis and not where applicable: for instance, missing for pillar.items and saltmod.state, so it works if commands are run by hand but not if they are automated with orchestrate.

    Both solutions I guess aim at allowing to version code and data.

    So, do you see them as redondant or do they serve different purposes? Do you plan to implement them both? And more generally what is Saltstack vision on code and data versioning?

    Thank you in advance for your feedback,
    Regards,

    Erick

  7. jfindlay commented on Jun 23, 2016

    @jfindlay
    Contributor

    @ealphonse, I know of no immediate plans for pillarenv work, but I agree that it could be more robust than it currently is. Any ideas or code you can contribute to this effort would be very appreciated.

  8. ealphonse commented on Jun 24, 2016

    @ealphonse

    Thank you @jfindlay, I understand.

    I like the pillar_top_file_merging_strategy=same better: it is an explicit configuration of how one uses Saltstack environments, rather than implicit, that is if you forget to set pillarenv somewhere, it is a bug.

    I do not think that forcing pairing of the salt env and the pillar env is too limiting. I have a limited point of view based on my use-cases of course, but I never really could make a good use of merging environments, even though 100% of our processes are managed by Saltstack. More importantly, if you do use merging environments, you cannot version your top files, and versioning is a requirement in continuous deployment pipelines for example.

    In details, I see environments as logical separations of processes: server life cycle, software maintenance, business processes, continuous deployment pipelines and their stages, etc. For each process, code and data are matched by their env name (the saltenv key as proposed above), never merged or mixed up.

    For instance, I would not create pillar envs to specify different configurations for the same code / saltenv as described in #21359, but specify different entries in the same pillar dictionary: specify dynamic pillar data from the command line and use jinja to select the right entry, like pillar[dynamic_pillar_var]...
    The same goes with the salt / code side: I prefer to simply use the filesystem hierachy, inside each env, to "merge" things by hand if needed.

    So, actually, I do not know how to avoid merging issues between versions without an option like this. I would say both implementations will do, but pillar_top_file_merging_strategy=same seems simpler and more robust.

    Probably not the help you were asking for, but what do you think?

  9. added
    ZD
    P1
    on Jul 21, 2016
  10. 23 remaining items

  11. knuta commented on Jan 24, 2017

    @knuta
    ContributorAuthor

    It looks like the introduction of pillar_source_merging_strategy=none (introduced in 2016.3.4) may be a solution for my use-case. I'll update and/or close this issue when I have a chance to try it.

  12. terminalmage commented on Jan 24, 2017

    @terminalmage
    Contributor

    @knuta I interpreted "make the master only use the topfile from the current saltenv" to mean that you wanted the pillarenv to match the saltenv. Given that using pillarenv will only consider pillar data from the specified pillarenv, adding an option to pin pillarenv to saltenv seemed to match the use case.

  13. ealphonse commented on Jan 24, 2017

    @ealphonse

    If I understand correctly pillar_source_merging_strategy only concerns how you deal with merging two sources, either from the same environment or from different ones. You may still want pillar_source_merging_strategy=recurse and pillarenv_from_saltenv=True.

    The doc is not clear about that, though. For instance, when you have these two files in the base env:

    foo: 42
    bar:
        element1: True
    ---------------------------
    bar:
        element2: True
    baz: quux
    

    Does pillar_source_merging_strategy=none complain, overwrite?

    As for the option, IMHO, pillarenv_from_saltenv=True fits well the case where you only use envs to version your code and data.

  14. terminalmage commented on Jan 24, 2017

    @terminalmage
    Contributor

    @ealphonse Seems easy enough to test. Given that we use a merge function in salt.utils.dictupdate to merge data, my educated guess is that you'd end up with:

    {
        foo: 42
        bar: {
            element1: True,
            element2: True
        },
        baz: quux
    }
  15. added
    P2
    and removed
    P1
    on Jan 24, 2017
  16. ealphonse commented on Jan 30, 2017

    @ealphonse

    Thank you for the clarification @terminalmage. And thank you for the option. It will be a great addition to orchestrate to implement data versionning with pillarenv_from_saltenv. I hope it will make it to the next release.

  17. meggiebot commented on Feb 6, 2017

    @meggiebot

    I'm going to close this since we haven't received a response from the submitter on this feature. If there are any concerns with the @terminalmage's explanation or code we can reopen this.

    #38404 will be included in the Nitrogen release.

  18. jcmcken commented on Oct 31, 2017

    @jcmcken
    Contributor

    @meggiebot @terminalmage I think this issue should be re-opened. The pillarenv_from_saltenv option doesn't solve the problem, as far as I understand it.

    If we're just talking about git pillars, the very confusing thing about all this is Salt can't make up its mind whether its the branch that determines the environment or whether it's the top file setting. Here's a simple example:

    I have a 'master' branch which maps to the 'base' environment. This is applied to my production nodes.

    I want to test a new pillar setting for 'base', so I create a new branch off of 'master' with those changes called "new-settings".

    I push up these changes, and on a test minion I set "pillarenv" to "new-settings". I execute a "salt-call pillar.get ". Nothing returns. This is because I added the setting to 'base' in the pillar YAML, but the environment is now 'new-settings'. I have no choice now but to completely duplicate the 'base' YAML tree as a new tree 'new-settings'. This is extremely cumbersome and prone to error, no?

    What would be better is if I could specify a pillar merging strategy just like top_file_merging_strategy that first applied 'base', and then tried to apply environment-specific settings. That, or have a separate setting that let's me specify that my pillar env is 'base', but my branch is 'new-settings'. (honestly, the latter is better, since it's more explicit about what's happening -- I don't really trust the merging behavior)

    Am I missing something here? Is there some other way that people are doing this?

  19. terminalmage commented on Nov 2, 2017

    @terminalmage
    Contributor

    @jcmcken I believe that what you're looking for would involve setting the branch to __env__ as described here. Scroll down once you've clicked that link.

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

Metadata

Metadata

Assignees

Labels

CoreFeatureP2PillarZRELEASED - 2017.7.0rc1

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions