Skip to content
Snippets Groups Projects
Commit 1d2d03b7 authored by Zuul's avatar Zuul Committed by Gerrit Code Review
Browse files

Merge "Fallback to templating when only one source exists"

parents 63f9aa4e 86d9a533
No related branches found
No related tags found
No related merge requests found
...@@ -77,13 +77,27 @@ class ConfigCollector(object): ...@@ -77,13 +77,27 @@ class ConfigCollector(object):
result = set(self.files_in_destination) - ignored result = set(self.files_in_destination) - ignored
return list(result) return list(result)
def _find_matching_rule(self, relative_path): def _find_matching_rule(self, relative_path, sources):
# First match wins # First match wins
for rule in self.rules: for rule in self.rules:
if not rule.get('enabled', True): if not rule.get('enabled', True):
continue continue
glob_ = rule["glob"] glob_ = rule["glob"]
if glob.globmatch(relative_path, glob_, flags=glob.GLOBSTAR): if glob.globmatch(relative_path, glob_, flags=glob.GLOBSTAR):
requires_merge = (rule["strategy"] in
["merge_configs", "merge_yaml"])
# Fallback to templating when there is only one source. This
# allows you to have config files that template to invalid
# yaml/ini. This was allowed prior to config merging so
# improves backwards compatibility.
if requires_merge and len(sources) == 1:
# The rule can be used again to match a different file
# so don't modify in place.
rule = rule.copy()
rule["strategy"] = 'template'
# Strip parameters as they may not be compatible with
# template module.
rule['params'] = {}
return rule return rule
def partition_into_actions(self): def partition_into_actions(self):
...@@ -114,7 +128,7 @@ class ConfigCollector(object): ...@@ -114,7 +128,7 @@ class ConfigCollector(object):
if not os.path.exists(dirname): if not os.path.exists(dirname):
missing_directories.add(dirname) missing_directories.add(dirname)
rule = self._find_matching_rule(relative_path) rule = self._find_matching_rule(relative_path, sources)
if not rule: if not rule:
continue continue
......
---
fixes:
- |
When merging kolla config, fallback to templating when only one source file
exists. This allows you to use config that templates to invalid yaml/ini as
long as there isn't an environment override. This improves backwards
compatability where it was permitted to use such constructs.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment