Browse Source

Add support for Openstack integration

Sylvain Baubeau 9 years ago
parent
commit
b5f00c416b

+ 7 - 0
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') }}"

+ 3 - 0
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'"

+ 9 - 0
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)

+ 17 - 0
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 %}

+ 1 - 0
roles/openshift_common/meta/main.yml

@@ -15,3 +15,4 @@ dependencies:
 - { role: os_firewall }
 - { role: openshift_facts }
 - { role: openshift_repos }
+- { role: openshift_cloud_provider }

+ 31 - 1
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