From b5f00c416b767b167bbd3d8f61f2b9a534aa5432 Mon Sep 17 00:00:00 2001 From: Sylvain Baubeau Date: Mon, 16 Nov 2015 17:24:43 +0100 Subject: Add support for Openstack integration --- roles/openshift_cloud_provider/defaults/main.yml | 7 +++++ roles/openshift_cloud_provider/tasks/main.yml | 3 ++ roles/openshift_cloud_provider/tasks/openstack.yml | 9 ++++++ .../templates/openstack/cloud.conf.j2 | 17 ++++++++++++ roles/openshift_common/meta/main.yml | 1 + roles/openshift_facts/library/openshift_facts.py | 32 +++++++++++++++++++++- 6 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 roles/openshift_cloud_provider/defaults/main.yml create mode 100644 roles/openshift_cloud_provider/tasks/main.yml create mode 100644 roles/openshift_cloud_provider/tasks/openstack.yml create mode 100644 roles/openshift_cloud_provider/templates/openstack/cloud.conf.j2 (limited to 'roles') 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 0f25881f1..5648c179e 100755 --- a/roles/openshift_facts/library/openshift_facts.py +++ b/roles/openshift_facts/library/openshift_facts.py @@ -296,6 +296,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': @@ -997,6 +1002,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 @@ -1209,6 +1238,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) @@ -1376,7 +1406,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 -- cgit v1.2.3