Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "none" as a pillar merging strategy #36435

Merged
merged 9 commits into from
Sep 23, 2016
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions conf/master
Original file line number Diff line number Diff line change
Expand Up @@ -694,9 +694,9 @@
#pillar_safe_render_error: True

# The pillar_source_merging_strategy option allows you to configure merging strategy
# between different sources. It accepts four values: recurse, aggregate, overwrite,
# or smart. Recurse will merge recursively mapping of data. Aggregate instructs
# aggregation of elements between sources that use the #!yamlex renderer. Overwrite
# between different sources. It accepts five values: none, recurse, aggregate, overwrite,
# or smart. None will not do any merging at all. Recurse will merge recursively mapping of data.
# Aggregate instructs aggregation of elements between sources that use the #!yamlex renderer. Overwrite
# will overwrite elements according the order in which they are processed. This is
# behavior of the 2014.1 branch and earlier. Smart guesses the best strategy based
# on the "renderer" setting and is the default value.
Expand Down
7 changes: 6 additions & 1 deletion doc/man/salt.7
Original file line number Diff line number Diff line change
Expand Up @@ -7571,9 +7571,14 @@ New in version 2014.7.0.
Default: \fBsmart\fP
.sp
The pillar_source_merging_strategy option allows you to configure merging
strategy between different sources. It accepts 4 values:
strategy between different sources. It accepts 5 values:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reference, you don't need to edit the man pages. They are automatically rebuilt on each release.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted:)

.INDENT 0.0
.IP \(bu 2
\fBnone\fP:
.sp
it will not do any merging at all and only parse the pillar data from the passed
environment and 'base' if no environment was specified.
.IP \(bu 2
\fBrecurse\fP:
.sp
it will merge recursively mapping of data. For example, theses 2 sources:
Expand Down
3 changes: 3 additions & 0 deletions doc/ref/configuration/master.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2791,6 +2791,9 @@ Default: ``smart``
The pillar_source_merging_strategy option allows you to configure merging
strategy between different sources. It accepts 4 values:

* ``none``:
it will not do any merging at all and only parse the pillar data from the passed environment and 'base' if no environment was specified.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please capitalize the first word in this sentence?


* ``recurse``:

it will merge recursively mapping of data. For example, theses 2 sources:
Expand Down
6 changes: 6 additions & 0 deletions salt/pillar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ def __init__(self, opts, grains, minion_id, saltenv, ext=None, functions=None,
self.actual_file_roots = opts['file_roots']
# use the local file client
self.opts = self.__gen_opts(opts, grains, saltenv=saltenv, ext=ext, pillarenv=pillarenv)
self.saltenv = saltenv
self.client = salt.fileclient.get_file_client(self.opts, True)

if opts.get('file_client', '') == 'local':
Expand Down Expand Up @@ -378,6 +379,11 @@ def get_tops(self):
]
else:
for saltenv in self._get_envs():
if self.opts.get('pillar_source_merging_strategy', None) == "none":
if self.saltenv and saltenv != self.saltenv:
continue
if not self.saltenv and not saltenv == 'base':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically we'd like to see these conditionals combined but here I think it enhances readability. Good call. 👍

continue
top = self.client.cache_file(
self.opts['state_top'],
saltenv
Expand Down
4 changes: 4 additions & 0 deletions salt/utils/dictupdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ def merge(obj_a, obj_b, strategy='smart', renderer='yaml', merge_lists=False):
merged = merge_aggregate(obj_a, obj_b)
elif strategy == 'overwrite':
merged = merge_overwrite(obj_a, obj_b, merge_lists)
elif strategy == 'none':
# If we do not want to merge, there is only one pillar passed, so we can safely use the default recurse,
# we just do not want to log an error
merged = merge_recurse(obj_a, obj_b)
else:
log.warning('Unknown merging strategy \'{0}\', '
'fallback to recurse'.format(strategy))
Expand Down