summaryrefslogtreecommitdiffstats
path: root/roles
diff options
context:
space:
mode:
authorAndrew Butcher <abutcher@redhat.com>2015-11-12 10:46:25 -0500
committerAndrew Butcher <abutcher@redhat.com>2015-11-16 14:23:20 -0500
commit03e6ae850ce718c008636bd8db093f453e62ccf3 (patch)
tree1d3583b5e2ccbb8b2fbdc0f3c5ea824a79803063 /roles
parent947ea1eae90b678c93b8f8118904f6ce2e3026c8 (diff)
downloadopenshift-03e6ae850ce718c008636bd8db093f453e62ccf3.tar.gz
openshift-03e6ae850ce718c008636bd8db093f453e62ccf3.tar.bz2
openshift-03e6ae850ce718c008636bd8db093f453e62ccf3.tar.xz
openshift-03e6ae850ce718c008636bd8db093f453e62ccf3.zip
Refactor named certificates.
Diffstat (limited to 'roles')
-rwxr-xr-xroles/openshift_facts/library/openshift_facts.py34
-rw-r--r--roles/openshift_master/templates/master.yaml.v1.j27
2 files changed, 26 insertions, 15 deletions
diff --git a/roles/openshift_facts/library/openshift_facts.py b/roles/openshift_facts/library/openshift_facts.py
index 091ba4e2b..995d2c5fb 100755
--- a/roles/openshift_facts/library/openshift_facts.py
+++ b/roles/openshift_facts/library/openshift_facts.py
@@ -864,20 +864,29 @@ def apply_provider_facts(facts, provider_facts):
return facts
-def merge_facts(orig, new):
+def merge_facts(orig, new, overwrite_additive_facts):
""" Recursively merge facts dicts
Args:
orig (dict): existing facts
new (dict): facts to update
+ overwrite_additive_facts (bool): overwrite additive facts
Returns:
dict: the merged facts
"""
+ additive_facts = ['named_certificates']
facts = dict()
for key, value in orig.iteritems():
if key in new:
if isinstance(value, dict) and isinstance(new[key], dict):
- facts[key] = merge_facts(value, new[key])
+ facts[key] = merge_facts(value, new[key], overwrite_additive_facts)
+ elif key in additive_facts and not overwrite_additive_facts:
+ if isinstance(value, list) and isinstance(new[key], list):
+ new_fact = []
+ for item in copy.deepcopy(value) + copy.copy(new[key]):
+ if item not in new_fact:
+ new_fact.append(item)
+ facts[key] = new_fact
else:
facts[key] = copy.copy(new[key])
else:
@@ -961,13 +970,14 @@ class OpenShiftFacts(object):
role (str): role for setting local facts
filename (str): local facts file to use
local_facts (dict): local facts to set
+ overwrite_additive_facts (bool): overwrite additive facts
Raises:
OpenShiftFactsUnsupportedRoleError:
"""
known_roles = ['common', 'master', 'node', 'master_sdn', 'node_sdn', 'dns', 'etcd']
- def __init__(self, role, filename, local_facts):
+ def __init__(self, role, filename, local_facts, overwrite_additive_facts=False):
self.changed = False
self.filename = filename
if role not in self.known_roles:
@@ -976,25 +986,26 @@ class OpenShiftFacts(object):
)
self.role = role
self.system_facts = ansible_facts(module)
- self.facts = self.generate_facts(local_facts)
+ self.facts = self.generate_facts(local_facts, overwrite_additive_facts)
- def generate_facts(self, local_facts):
+ def generate_facts(self, local_facts, overwrite_additive_facts):
""" Generate facts
Args:
local_facts (dict): local_facts for overriding generated
defaults
+ overwrite_additive_facts (dict): overwrite additive facts
Returns:
dict: The generated facts
"""
- local_facts = self.init_local_facts(local_facts)
+ local_facts = self.init_local_facts(local_facts, overwrite_additive_facts)
roles = local_facts.keys()
defaults = self.get_defaults(roles)
provider_facts = self.init_provider_facts()
facts = apply_provider_facts(defaults, provider_facts)
- facts = merge_facts(facts, local_facts)
+ facts = merge_facts(facts, local_facts, overwrite_additive_facts)
facts['current_config'] = get_current_config(facts)
facts = set_url_facts_if_unset(facts)
facts = set_project_cfg_facts_if_unset(facts)
@@ -1132,11 +1143,12 @@ class OpenShiftFacts(object):
)
return provider_facts
- def init_local_facts(self, facts=None):
+ def init_local_facts(self, facts=None, overwrite_additive_facts=False):
""" Initialize the provider facts
Args:
facts (dict): local facts to set
+ overwrite_additive_facts (bool): overwrite additive facts
Returns:
dict: The result of merging the provided facts with existing
@@ -1154,7 +1166,7 @@ class OpenShiftFacts(object):
basestring):
facts_to_set[arg] = module.from_json(facts_to_set[arg])
- new_local_facts = merge_facts(local_facts, facts_to_set)
+ new_local_facts = merge_facts(local_facts, facts_to_set, overwrite_additive_facts)
for facts in new_local_facts.values():
keys_to_delete = []
for fact, value in facts.iteritems():
@@ -1184,6 +1196,7 @@ def main():
role=dict(default='common', required=False,
choices=OpenShiftFacts.known_roles),
local_facts=dict(default=None, type='dict', required=False),
+ overwrite_additive_facts=dict(default=False, type='bool', required=False),
),
supports_check_mode=True,
add_file_common_args=True,
@@ -1191,9 +1204,10 @@ def main():
role = module.params['role']
local_facts = module.params['local_facts']
+ overwrite_additive_facts = module.params['overwrite_additive_facts']
fact_file = '/etc/ansible/facts.d/openshift.fact'
- openshift_facts = OpenShiftFacts(role, fact_file, local_facts)
+ openshift_facts = OpenShiftFacts(role, fact_file, local_facts, overwrite_additive_facts)
file_params = module.params.copy()
file_params['path'] = fact_file
diff --git a/roles/openshift_master/templates/master.yaml.v1.j2 b/roles/openshift_master/templates/master.yaml.v1.j2
index bb12a0a0f..2a37c06d9 100644
--- a/roles/openshift_master/templates/master.yaml.v1.j2
+++ b/roles/openshift_master/templates/master.yaml.v1.j2
@@ -27,9 +27,6 @@ corsAllowedOrigins:
{% for custom_origin in openshift.master.custom_cors_origins | default("") %}
- {{ custom_origin }}
{% endfor %}
-{% for name in (named_certificates | map(attribute='names')) | list | oo_flatten %}
- - {{ name }}
-{% endfor %}
{% if 'disabled_features' in openshift.master %}
disabledFeatures: {{ openshift.master.disabled_features | to_json }}
{% endif %}
@@ -144,9 +141,9 @@ servingInfo:
keyFile: master.server.key
maxRequestsInFlight: 500
requestTimeoutSeconds: 3600
-{% if named_certificates %}
+{% if openshift.master.named_certificates %}
namedCertificates:
-{% for named_certificate in named_certificates %}
+{% for named_certificate in openshift.master.named_certificates %}
- certFile: {{ named_certificate['certfile'] }}
keyFile: {{ named_certificate['keyfile'] }}
names: