Browse Source

Merge pull request #6713 from tomassedovic/openstack-cinder-registry

Support creating OpenStack Cinder registry volume
Michael Gugino 7 years ago
parent
commit
fe7e4702fe

+ 15 - 17
playbooks/openstack/configuration.md

@@ -503,32 +503,30 @@ You can create one by running:
 openstack volume create --size <volume size in gb> <volume name>
 ```
 
-The volume needs to have a file system created before you put it to
-use.
+Alternatively, the playbooks can create the volume created automatically if you
+specify its name and size.
 
-Once the volume is created, [set up OpenStack credentials](#openstack-credential-configuration),
-and then set the following in `inventory/group_vars/OSEv3.yml`:
+In either case, you have to [set up OpenStack
+credentials](#openstack-credential-configuration), and then set the following
+in `inventory/group_vars/OSEv3.yml`:
 
 * `openshift_hosted_registry_storage_kind`: openstack
 * `openshift_hosted_registry_storage_access_modes`: ['ReadWriteOnce']
 * `openshift_hosted_registry_storage_openstack_filesystem`: xfs
-* `openshift_hosted_registry_storage_openstack_volumeID`: e0ba2d73-d2f9-4514-a3b2-a0ced507fa05
 * `openshift_hosted_registry_storage_volume_size`: 10Gi
 
-The **Cinder volume ID**, **filesystem** and **volume size** variables
-must correspond to the values in your volume. The volume ID must be
-the **UUID** of the Cinder volume, *not its name*.
+For a volume *you created*, you must also specify its **UUID** (it must be
+the UUID, not the volume's name):
 
-The volume can also be formatted if you configure it in
-`inventory/group_vars/all.yml`:
-
-* openshift_openstack_prepare_and_format_registry_volume: true
-
-Note that formatting **will destroy any data that's currently on the volume**!
+```
+openshift_hosted_registry_storage_openstack_volumeID: e0ba2d73-d2f9-4514-a3b2-a0ced507fa05
+```
 
-If you already have a provisioned OpenShift cluster, you can also run the
-registry setup playbook directly:
+If you want the volume *created automatically*, set the desired name instead:
 
 ```
-ansible-playbook -i inventory playbooks/provisioning/openstack/prepare-and-format-cinder-volume.yaml
+openshift_hosted_registry_storage_volume_name: registry
 ```
+
+The volume will be formatted automaticaly and it will be mounted to one of the
+infra nodes when the registry pod gets started.

+ 4 - 8
playbooks/openstack/sample-inventory/group_vars/OSEv3.yml

@@ -27,17 +27,13 @@ openshift_hosted_registry_wait: True
 #openshift_hosted_registry_storage_kind: openstack
 #openshift_hosted_registry_storage_access_modes: ['ReadWriteOnce']
 #openshift_hosted_registry_storage_openstack_filesystem: xfs
+#openshift_hosted_registry_storage_volume_size: 10Gi
 
-## NOTE(shadower): This won't work until the openshift-ansible issue #5657 is fixed:
-## https://github.com/openshift/openshift-ansible/issues/5657
-## If you're using the `openshift_openstack_cinder_hosted_registry_name` option from
-## `all.yml`, uncomment these lines:
-#openshift_hosted_registry_storage_openstack_volumeID: "{{ lookup('os_cinder', openshift_openstack_cinder_hosted_registry_name).id }}"
-#openshift_hosted_registry_storage_volume_size: "{{ openshift_openstack_cinder_hosted_registry_size_gb }}Gi"
+## If you want a Cinder volume created automaticaly, uncomment this:
+#openshift_hosted_registry_storage_volume_name: registry
 
-## If you're using a Cinder volume you've set up yourself, uncomment these lines:
+## If you're using a Cinder volume you've set up yourself, uncomment this:
 #openshift_hosted_registry_storage_openstack_volumeID: e0ba2d73-d2f9-4514-a3b2-a0ced507fa05
-#openshift_hosted_registry_storage_volume_size: 10Gi
 
 
 # NOTE(shadower): the hostname check seems to always fail because the

+ 0 - 11
playbooks/openstack/sample-inventory/group_vars/all.yml

@@ -133,17 +133,6 @@ openshift_openstack_docker_volume_size: "15"
 #openshift_openstack_master_server_group_policies: [anti-affinity]
 #openshift_openstack_infra_server_group_policies: [anti-affinity]
 
-## Create a Cinder volume and use it for the OpenShift registry.
-## NOTE: the openstack credentials and hosted registry options must be set in OSEv3.yml!
-#openshift_openstack_cinder_hosted_registry_name: cinder-registry
-#openshift_openstack_cinder_hosted_registry_size_gb: 10
-
-## Set up a filesystem on the cinder volume specified in `OSEv3.yaml`.
-## You need to specify the file system and volume ID in OSEv3 via
-## `openshift_hosted_registry_storage_openstack_filesystem` and
-## `openshift_hosted_registry_storage_openstack_volumeID`.
-## WARNING: This will delete any data on the volume!
-#openshift_openstack_prepare_and_format_registry_volume: False
 
 # The Classless Inter-Domain Routing (CIDR) for the OpenStack VM subnet.
 openshift_openstack_subnet_cidr: "192.168.99.0/24"

+ 25 - 0
roles/lib_utils/action_plugins/generate_pv_pvcs_list.py

@@ -54,7 +54,10 @@ class ActionModule(ActionBase):
         """Build pv dictionary for openstack storage type"""
         volume, size, labels, access_modes = self.build_common(varname=varname)
         filesystem = self.get_templated(str(varname) + '_openstack_filesystem')
+        volume_name = self.get_templated(str(varname) + '_volume_name')
         volume_id = self.get_templated(str(varname) + '_openstack_volumeID')
+        if volume_name and not volume_id:
+            volume_id = _try_cinder_volume_id_from_name(volume_name)
         return dict(
             name="{0}-volume".format(volume),
             capacity=size,
@@ -161,3 +164,25 @@ class ActionModule(ActionBase):
         result["persistent_volumes"] = persistent_volumes
         result["persistent_volume_claims"] = persistent_volume_claims
         return result
+
+
+def _try_cinder_volume_id_from_name(volume_name):
+    """Try to look up a Cinder volume UUID from its name.
+
+    Returns None on any failure (missing shade, auth, no such volume).
+    """
+    try:
+        import shade
+    except ImportError:
+        return None
+    try:
+        cloud = shade.openstack_cloud()
+    except shade.keystoneauth1.exceptions.ClientException:
+        return None
+    except shade.OpenStackCloudException:
+        return None
+    volume = cloud.get_volume(volume_name)
+    if volume:
+        return volume.id
+    else:
+        return None

+ 10 - 0
roles/openshift_openstack/tasks/create-registry-volume.yml

@@ -0,0 +1,10 @@
+---
+- name: Create the Cinder Registry volume
+  os_volume:
+    display_name: "{{ cinder_registry_volume_name }}"
+    size: "{{ cinder_registry_volume_size }}"
+    display_description: "Storage for the OpenShift registry"
+  register: cinder_registry_volume
+  vars:
+    cinder_registry_volume_name: "{{ hostvars[groups.infra_hosts.0].openshift_hosted_registry_storage_volume_name }}"
+    cinder_registry_volume_size: "{{ hostvars[groups.infra_hosts.0].openshift_hosted_registry_storage_volume_size | regex_replace('[A-Z]i$') }}"

+ 8 - 2
roles/openshift_openstack/tasks/provision.yml

@@ -98,5 +98,11 @@
   when:
   - openshift_openstack_stack_state == 'present'
 
-# TODO(shadower): create the registry and PV Cinder volumes if specified
-# and include the `prepare-and-format-cinder-volume` tasks to set it up
+- name: Create the Cinder volume for OpenShift Registry
+  include_tasks: create-registry-volume.yml
+  when:
+  - groups.infra_hosts is defined
+  - groups.infra_hosts.0 is defined
+  - hostvars[groups.infra_hosts.0].openshift_hosted_registry_storage_volume_name is defined
+  - hostvars[groups.infra_hosts.0].openshift_hosted_registry_storage_volume_size is defined
+  - hostvars[groups.infra_hosts.0].openshift_hosted_registry_storage_openstack_volumeID is not defined