diff options
-rw-r--r-- | roles/openshift_cloud_provider/defaults/main.yml | 7 | ||||
-rw-r--r-- | roles/openshift_cloud_provider/tasks/main.yml | 3 | ||||
-rw-r--r-- | roles/openshift_cloud_provider/tasks/openstack.yml | 9 | ||||
-rw-r--r-- | roles/openshift_cloud_provider/templates/openstack/cloud.conf.j2 | 17 | ||||
-rw-r--r-- | roles/openshift_common/meta/main.yml | 1 | ||||
-rwxr-xr-x | roles/openshift_facts/library/openshift_facts.py | 32 |
6 files changed, 68 insertions, 1 deletions
diff --git a/roles/openshift_cloud_provider/defaults/main.yml b/roles/openshift_cloud_provider/defaults/main.yml new file mode 100644 index 000000000..6c7403232 --- /dev/null +++ b/roles/openshift_cloud_provider/defaults/main.yml @@ -0,0 +1,7 @@ +--- +ocp_os_auth_url: "{{ lookup('env', 'OS_AUTH_URL') }}" +ocp_os_username: "{{ lookup('env', 'OS_USERNAME') }}" +ocp_os_password: "{{ lookup('env', 'OS_PASSWORD') }}" +ocp_os_tenant_id: "{{ lookup('env', 'OS_TENANT_ID') }}" +ocp_os_tenant_name: "{{ lookup('env', 'OS_TENANT_NAME') }}" +ocp_os_region: "{{ lookup('env', 'OS_REGION_NAME') }}" diff --git a/roles/openshift_cloud_provider/tasks/main.yml b/roles/openshift_cloud_provider/tasks/main.yml new file mode 100644 index 000000000..e14f944e8 --- /dev/null +++ b/roles/openshift_cloud_provider/tasks/main.yml @@ -0,0 +1,3 @@ +--- +- include: openstack.yml + when: "openshift_cloud_provider is defined and openshift_cloud_provider == 'openstack' and 'provider' in openshift and openshift.provider.name == 'openstack'" diff --git a/roles/openshift_cloud_provider/tasks/openstack.yml b/roles/openshift_cloud_provider/tasks/openstack.yml new file mode 100644 index 000000000..a56f1891a --- /dev/null +++ b/roles/openshift_cloud_provider/tasks/openstack.yml @@ -0,0 +1,9 @@ +- fail: + msg: "The Openstack integration requires OpenShift Enterprise 3.2 or Origin 1.2." + when: not openshift.common.version_gte_3_2_or_1_2 | bool + +- name: Create /etc/cloud.conf + template: + dest: /etc/cloud.conf + src: openstack/cloud.conf.j2 + when: ocp_os_auth_url and ocp_os_username and ocp_os_password and (ocp_os_tenant_id or ocp_os_tenant_name)
\ No newline at end of file diff --git a/roles/openshift_cloud_provider/templates/openstack/cloud.conf.j2 b/roles/openshift_cloud_provider/templates/openstack/cloud.conf.j2 new file mode 100644 index 000000000..388f3a735 --- /dev/null +++ b/roles/openshift_cloud_provider/templates/openstack/cloud.conf.j2 @@ -0,0 +1,17 @@ +[Global] +auth-url = {{ ocp_os_auth_url }} +username = {{ ocp_os_username }} +password = {{ ocp_os_password }} +{% if ocp_os_tenant_id %} +tenant-id = {{ ocp_os_tenant_id }} +{% else %} +tenant-name = {{ ocp_os_tenant_name }} +{% endif %} +{% if ocp_os_region %} +region = {{ ocp_os_region }} +{% endif %} +{% if ocp_os_lb_subnet_id is defined %} ++ ++[LoadBalancer] ++subnet-id = {{ ocp_os_lb_subnet_id }} ++{% endif %}
\ No newline at end of file diff --git a/roles/openshift_common/meta/main.yml b/roles/openshift_common/meta/main.yml index 81363ec68..d879db0aa 100644 --- a/roles/openshift_common/meta/main.yml +++ b/roles/openshift_common/meta/main.yml @@ -15,3 +15,4 @@ dependencies: - { role: os_firewall } - { role: openshift_facts } - { role: openshift_repos } +- { role: openshift_cloud_provider } diff --git a/roles/openshift_facts/library/openshift_facts.py b/roles/openshift_facts/library/openshift_facts.py index b3df46892..b06900681 100755 --- a/roles/openshift_facts/library/openshift_facts.py +++ b/roles/openshift_facts/library/openshift_facts.py @@ -328,6 +328,11 @@ def normalize_provider_facts(provider, metadata): facts = dict(name=provider, metadata=metadata, network=dict(interfaces=[], ipv6_enabled=False)) + if os.path.exists('/etc/cloud.conf'): + for arg in ('api_server_args', 'controller_args', 'kubelet_args'): + facts[arg] = {'cloud-provider': [provider], + 'cloud-config': ['/etc/cloud.conf']} + if provider == 'gce': facts = normalize_gce_facts(metadata, facts) elif provider == 'ec2': @@ -1076,6 +1081,30 @@ def merge_facts(orig, new, additive_facts_to_overwrite, protected_facts_to_overw return facts +def merge_provider_facts(facts): + """ Recursively merge provider facts dicts + + Args: + facts (dict): existing facts + Returns: + dict: the facts dict updated with the provider config + """ + if 'provider' not in facts: + return facts + if 'master' in facts: + for arg in ('api_server_args', 'controller_args'): + facts['master'][arg] = merge_facts( + facts['provider'].get(arg, {}), + facts['master'].get(arg, {}), + [], []) + if 'node' in facts: + facts['node']['kubelet_args'] = merge_facts( + facts['provider'].get('kubelet_args', {}), + facts['node'].get('kubelet_args', {}), + [], []) + return facts + + def save_local_facts(filename, facts): """ Save local facts @@ -1305,6 +1334,7 @@ class OpenShiftFacts(object): local_facts, additive_facts_to_overwrite, protected_facts_to_overwrite) + facts = merge_provider_facts(facts) facts['current_config'] = get_current_config(facts) facts = set_url_facts_if_unset(facts) facts = set_project_cfg_facts_if_unset(facts) @@ -1481,7 +1511,7 @@ class OpenShiftFacts(object): additive_facts_to_overwrite=None, openshift_env=None, protected_facts_to_overwrite=None): - """ Initialize the provider facts + """ Initialize the local facts Args: facts (dict): local facts to set |