Skip to content

Prevent unnecessary duplicate pillar compilation - #41679

Merged
cachedout merged 6 commits into
saltstack:2016.11from
terminalmage:get-top-file-envs
Jun 21, 2017
Merged

cachedout merged 6 commits into
saltstack:2016.11from
terminalmage:get-top-file-envs

Conversation

@terminalmage

Copy link
Copy Markdown
Contributor

The salt.state.HighState class' dunder init spawns a salt.state.State instance, which in its own dunder init will compile fresh pillar data. However, there are two cases in particular where this results in unnecessary duplicate pillar compilation:

  1. When states are run using salt-call
  2. When custom types are synced using saltutil.sync_*

To prevent this duplicate pillar generation, the salt.state.State and salt.state.HighState classes have been modified to accept a new initial_pillar argument (the latter only to pass through to the salt.state.State instance). If initial_pillar is set to a non-None value, then the salt.state.State instance will skip compiling pillar data and use the value passed instead.

The state and saltutil execution modules now use this initial_pillar argument where applicable. There were actually a few functions in the state execution module which did not support saltenv/pillarenv, and the usage of these values has now been normalized. (Note to @rallytime for merge-forwards: _get_opts() now accepts double-asterisk kwargs instead of having the kwargs dict passed to it.)

In addition, to differentiate initial pillar data from CLI pillar override data, I have changed references to the pillar argument in pillar compilation (and all calls to salt.pillar.get_pillar) to pillar_override. This makes instantiating salt.states.State instances make more sense, as it is confusing when you are passing pillar and initial_pillar arguments. Passing pillar_override and initial_pillar is more explicit, and also paves the way for the planned eventual changes to pillar compilation which will allow the Pillar classes/subclasses to be seeded with initial data.

@ghost

ghost commented Jun 9, 2017

Copy link
Copy Markdown

@terminalmage, thanks for your PR! By analyzing the history of the files in this pull request, we identified @DmitryKuzmenko, @cachedout and @jacksontj to be potential reviewers.

@rallytime

Copy link
Copy Markdown
Contributor

@terminalmage

Copy link
Copy Markdown
Contributor Author

@rallytime I just updated the tests. FYI for merge-forwards, you'll need to move the changes to the default __opts__ to setup_loader_modules.

@l2ol33rt

Copy link
Copy Markdown
Contributor

@terminalmage finally got around to running this against my own environment and tests. This is much better! Thanks for working with me on this, looking forward to upgrading the rest of my minions 👍

@terminalmage

Copy link
Copy Markdown
Contributor Author

@l2ol33rt Awesome. Thanks for testing it out and providing feedback. Glad we got this taken care of. I think we're close to getting it merged but it will unfortunately not make it into 2016.11.6.

@l2ol33rt

Copy link
Copy Markdown
Contributor

You're welcome!

And no worries, I've got no problem running off a specific commit ID.

@terminalmage terminalmage added the pending-changes The pull request needs additional changes before it can be merged label Jun 16, 2017
@terminalmage terminalmage removed the pending-changes The pull request needs additional changes before it can be merged label Jun 16, 2017
@terminalmage

Copy link
Copy Markdown
Contributor Author

Some tests need to be updated again to reflect the changes I made on Friday to the saltenv/pillarenv normalization.

@terminalmage
terminalmage force-pushed the get-top-file-envs branch 2 times, most recently from 659dcdf to 9594a78 Compare June 21, 2017 03:54
This differentiates CLI pillar override with an eventual future
"initial_pillar" argument which will seed the Pillar class with initial
data.
This allows for salt.state.State() instances to have their initial
pillar data passed into them, rather than calling _gather_pillar() to
compile fresh pillar data. This allows for the __pillar__ dunder to be
used directly for salt-call (when the pillarenv is unchanged). Since the
__pillar__ is compiled at the beginning of a salt-call, this prevents
duplicate pillar rendering from happening when salt-call is invoked.
This modifies the "state" exec module to use __pillar__ as the pillar
data for the state run rather than compiling fresh pillar, unless the
pillarenv has been changed from the configured value, keeping salt-call
from unnecessarily compiling pillar a second time.

It also normalizes saltenv/pillarenv support in functions that should
have had it but did not.
This prevents an unnecessary pillar compile when syncing custom types,
in cases where the saltenv is not specified.
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.

4 participants