Skip to content

Top SLS compilation does not behave the same as Docs describe #12483

Closed

Description

@driskell

Hi

(This is taken from my comments on closed issue #5440 - @basepi recommended a new issue so here it is! Thanks.)

I have 4 environments, "base", "qa", "dev", "master", in that order defined in file_roots. These are branches in a git and I have my own deployment of this to the salt server (I do not use gitfs).

Each has a version of the top.sls file containing all environments (as you'd expect since it same file, just different revisions different branches)

The documentation describes that if an environment has info in top.sls in "base", it will always override all other top.sls. This is not the case - and checking the code there is no distinction between "base" and any other name, and no specific decision on ordering (and it seems alphabetical) - so in my case, even though in the top.sls and file_roots, "qa" is second down, because it is last alphabetically, that overrides all other top.sls files in all other environments.

Based on the docs, it seems to give the idea that "base" is a special name and is always authoritative. It also explicitly says that if an environment is defined in multiple top.sls files - the definition in the top.sls for that environment will be preferred. But the code seems to say otherwise.

The code seems to simply merge and overwrite, in alphabetical order. Which contradicts entirely the documentation.

For reference, from http://docs.saltstack.com/en/latest/ref/states/top.html:

The following is what lead me to think "base" was a special name (it doesn't say the FIRST environment wins, it says the "base" environment wins.)

21.24.15.3. HOW TOP FILES ARE COMPILED
...
1 . The base environment's top file is processed first. Any environment which is defined in the base top.sls as well as another environment's top file, will use the instance of the environment configured in base and ignore all other instances. In other words, the base top file is authoritative when defining environments.

The following is the bit saying a top.sls in an environment is authoritative for that environment if it contains config for it:

3 . For environments other than base, the top file in a given environment will be checked for a section matching the environment's name. If one is found, then it is used. Otherwise, the remaining (non-base) environments will be checked in alphabetical order. In the below example, the qa section in /srv/salt/dev/top.sls will be ignored, but if /srv/salt/qa/top.sls were cleared or removed, then the states configured for the qa environment in /srv/salt/dev/top.sls will be applied.

Although if I'm honest, point 3 does seem to contradict point 2 (below) - I would've expected point 2 to at least make an exception for point 3 - or point 3 come first

2 . If, for some reason, the base environment is not configured in the base environment's top file, then the other environments will be checked in alphabetical order. The first top file found to contain a section for the base environment wins, and the other top files' base sections are ignored. So, provided there is no base section in the base top file, with the below two top files the dev environment would win out, and the common.centos SLS would not be applied to CentOS hosts.

@basepi:

@driskell Could I convince you to open a new issue and insert all of this awesome information and detective work into that new issue? I think what we will want to do is bring the code in line with the documentation (I still haven't tested this myself, so I haven't verified that I see the same thing you do) if possible. I think the documentation's way is a good way, but we definitely need to get them in line with each other one way or another.

I agree the documentation is (mostly) a good way, and the behaviour should match. Assuming I haven't read the doc wrong though, and "base" is meant to be special and authoritative and overriding, then I think that should be configurable so I can call it something else, so maybe a "main_env: base" option with that as default.

Thanks guys!

Activity

  1. added this to the Approved milestone on May 2, 2014
  2. basepi commented on May 2, 2014

    @basepi
    Contributor

    Thanks for filing this!

  3. driskell commented on May 5, 2014

    @driskell
    ContributorAuthor

    Proposed a fix if it helps!

  4. basepi commented on May 5, 2014

    @basepi
    Contributor

    Awesome! I'll leave review of that to @thatch45. =)

  5. cachedout commented on May 13, 2014

    @cachedout
    Contributor

    Flagged as 'Fixed Pending Verification' while we wait for that review.

  6. driskell commented on Jun 11, 2014

    @driskell
    ContributorAuthor

    OK so the fix is not viable as I expected - though I think it was a good POC of what the docs say.

    Has there been any discussions on what should happen? Or what recommended approach for me to take?

    I think I can rename my environments aDev bQA cProd and things will work better, but that just seems a hack. Or I would need to take my top.sls out of Git and hold them separately, so that each one only contains directives for servers in its environments (thus merging doesn't overwrite anything). But I still worry about someone with access to QA accidentally using a production server name instead of QA and it overriding - so I'd have to use the aDev bQA cProd still.

    Maybe I'm approaching this completely wrong though.

  7. basepi commented on Jun 11, 2014

    @basepi
    Contributor

    I think what it comes down to is that we've never really had testing in place for this kind of workflow. In general we just recommend that people don't have conflicts across environments for their top.sls files, because it tends to be implicit, rather than explicit, which in my opinion isn't good (and is harder to maintain).

    So we just need to deep dive this and either change the documentation or get the actual compilation process in line with the documentation.

  8. driskell commented on Jun 20, 2014

    @driskell
    ContributorAuthor

    It seems that #9616 is a variation of this issue?

    Please let me know if you start discussing this. I am more than willing to accept something where you have an option to enable the top compilation described in the docs.

    I think it is important that not only states can be version controlled, but top.sls also. This workflow I used is exactly how I would proceed when using GitFS backend. But I do require top.sls to be in each branch and version controlled, so changes can be promoted along with state changes. Otherwise I end up merging in state changes from QA to Production but have to prevent top.sls merging too somehow... not even sure how you do this without a dirty hack :-(

    Jason

  9. driskell commented on Jun 20, 2014

    @driskell
    ContributorAuthor

    Also - I'm willing to help implement the proposed solution when one is decided.

  10. 60 remaining items

  11. encodedfox commented on Jun 23, 2015

    @encodedfox

    @cachedout I'll give it a review over the next hour or so. Thanks for the update!

  12. cachedout commented on Jun 23, 2015

    @cachedout
    Contributor

    @jmelfi Super. Be sure to configure things as described in the PR. It won't (or shouldn't) change behaviour out of the box. I'll be here if you have questions. Thanks for the testing help!

  13. DanyC97 commented on Jul 24, 2015

    @DanyC97

    wow, this was a long issue to read :)) Would love to see this merged soon, thx for the effort!

  14. added
    severity-critical
    on Jul 29, 2015
  15. modified the milestones: Be 1, Approved on Jul 29, 2015
  16. added
    fixed-pls-verify
    and removed
    pending-discussion
    on Aug 10, 2015
  17. cachedout commented on Aug 11, 2015

    @cachedout
    Contributor

    I have merged this fix into develop and it should be backported into the 2015.8 branch in the next day or two.

  18. basepi commented on Aug 11, 2015

    @basepi
    Contributor

    👍

  19. rallytime commented on Aug 11, 2015

    @rallytime
    Contributor

    Back-port is in #26214. :)

  20. encodedfox commented on Aug 11, 2015

    @encodedfox

    @cachedout sorry for a late reply here. I was able to get the sorting to work properly after using the PR work. Thanks you guys for this hard work. I've been working the last week on moving from our puppet code completely into saltstack.

    You guys are awesome!

  21. cachedout commented on Aug 11, 2015

    @cachedout
    Contributor

    @jmelfi I'm so glad! Thanks for testing this. For the time being, I am going to close this issue since we're using it to track progress toward our release. That doesn't mean, however, that people can't continue to post feedback here. We'll re-open it if we need to. Thanks again!

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

Metadata

Metadata

Assignees

Labels

CoreP1ZDZRELEASED - Berylliumbugfixed-pls-verifyseverity-criticalseverity-medium

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions