Closed myii closed 5 years ago
salt['defaults.merge']
over .update
Regarding point raised by @noelmcloughlin above:
- {% do defaults.apache.update(oscode) %}
+ {% do salt['defaults.merge'](defaults['apache'], oscode) %}
This is easiest to explain using the recent issue encountered in https://github.com/saltstack-formulas/salt-formula/pull/395#issuecomment-457820419.
gitfs:
dulwich:
install_from_source: True
pygit2:
install_from_source: True
version: 0.23.0
git:
# if not false, should be state name
require_state: False
install_from_package: git
libgit2:
version: 0.23.0
install_from_source: True
build_parent_dir: /usr/src/
# hash necessary until github issue #9272 is addressed
download_hash: 683d1164e361e2a0a8d52652840e2340
gitpython:
install_from_source: False
osfamilymap.yaml#L18-L26
(for Debian
):
gitfs:
pygit2:
install_from_source: True
version: 0.22.1
git:
require_state: False
install_from_package: git
libgit2:
install_from_source: False
osmap.yaml#L20-L25
(for Ubuntu
):
gitfs:
pygit2:
install_from_source: False
git:
require_state: False
install_from_package: Null
The difference between the two methods:
--- Using `.update` throughout
+++ Using `salt['defaults.merge']` throughout
@@ -1,9 +1,22 @@
"gitfs": {
+ "dulwich": {
+ "install_from_source": true
+ },
+ "gitpython": {
+ "install_from_source": false
+ },
"pygit2": {
"git": {
"install_from_package": null,
"require_state": false
},
- "install_from_source": false
+ "install_from_source": false,
+ "libgit2": {
+ "build_parent_dir": "/usr/src/",
+ "download_hash": "683d1164e361e2a0a8d52652840e2340",
+ "install_from_source": false,
+ "version": "0.23.0"
+ },
+ "version": "0.22.1"
}
},
osfamilymap
update overwrites the entire gitfs
key, losing all of the dulwich
and gitpython
defaults, as well as losing most of the pygit2:libgit2
defaults.osmap
update overwrites the entire gitfs
key again, with further losses of pygit2:version
and the rest of pygit2:libgit2
.Of course, there are use-cases for using .update
, when overwriting an entire key is the required functionality.
@myii nice fix thanks
@aboe76 Thanks for the review and merge.
Regression
Regression mentioned on the # irc channel yesterday (2018-01-27):
My response to that:
Regression confirmation
Using a stripped down version of
pillar.example
:Here's the diff of the generated
map.jinja
before and after this commit (excluding the extralookup
key):Summary of changes
apache:lookup
as the penultimate merge in the map.salt['defaults.merge']
in place of.update
, to ensure merging (to avoid issues such as https://github.com/saltstack-formulas/salt-formula/pull/395#issuecomment-457820419).The diff with the "before" commit shows that the regression is resolved (excluding the extra
lookup
key):Update: The
centos-7
build failed the first time but passed when I bumped it.