From cc89e48141b599880a3eae899bf2e31c4710723c Mon Sep 17 00:00:00 2001 From: scrungus Date: Mon, 25 Mar 2024 15:52:45 +0000 Subject: [PATCH] Use availability zone instead of Region for storage classes Using the RegionName instead of the availability zone to configure cinder storage classes causes errors. We provide a configurable availability zone option and a default of 'nova' (which should be on most standard deployments Change-Id: Ie4a6c26d42a85dae5cd95a1f0f220971e21ac691 --- README.rst | 1 + magnum_capi_helm/conf.py | 5 +++++ magnum_capi_helm/driver.py | 11 +++++++++-- magnum_capi_helm/tests/test_driver.py | 21 +++++++-------------- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/README.rst b/README.rst index 4618455..203ca5b 100644 --- a/README.rst +++ b/README.rst @@ -125,6 +125,7 @@ The driver respects the following cluster and template properties: The driver supports the following labels: +* csi_cinder_availability_zone: default is nova, operators can configure the default in magnum.conf * monitoring_enabled: default is off, change to "true" to enable * kube_dashboard_enabled: defalt is on, change to "false" to disable * octavia_provider: default is "amphora", ovn is also an option diff --git a/magnum_capi_helm/conf.py b/magnum_capi_helm/conf.py index 2e07fb8..4f049ff 100644 --- a/magnum_capi_helm/conf.py +++ b/magnum_capi_helm/conf.py @@ -117,6 +117,11 @@ capi_helm_opts = [ "volume binding and dynamic provisioning should occur." ), ), + cfg.StrOpt( + "csi_cinder_availability_zone", + default="nova", + help=("The default availability zone to use for Cinder volumes."), + ), cfg.StrOpt( "app_cred_interface_type", default="public", diff --git a/magnum_capi_helm/driver.py b/magnum_capi_helm/driver.py index c1bce45..4ea704c 100644 --- a/magnum_capi_helm/driver.py +++ b/magnum_capi_helm/driver.py @@ -625,6 +625,13 @@ class Driver(driver.Driver): f"Minimum {CONF.capi_helm.minimum_flavor_ram} MB required." ) + def _get_csi_cinder_availability_zone(self, cluster): + return self._label( + cluster, + "csi_cinder_availability_zone", + CONF.capi_helm.csi_cinder_availability_zone, + ) + def _get_csi_cinder_reclaim_policy(self, cluster): return self._label( cluster, @@ -660,7 +667,7 @@ class Driver(driver.Driver): """ LOG.debug("Retrieve volume types from cinder for StorageClasses.") client = clients.OpenStackClients(context) - region_name = client.cinder_region_name() + availability_zone = self._get_csi_cinder_availability_zone(cluster) c_client = client.cinder() volume_types = [i.name for i in c_client.volume_types.list()] # Use the default volume type if defined. Otherwise use the first @@ -694,7 +701,7 @@ class Driver(driver.Driver): "name": driver_utils.sanitized_name(volume_type), "reclaimPolicy": reclaim_policy, "allowVolumeExpansion": allow_expansion, - "availabilityZone": region_name, + "availabilityZone": availability_zone, "volumeType": volume_type, "allowedTopologies": allowed_topologies, "fstype": fstype, diff --git a/magnum_capi_helm/tests/test_driver.py b/magnum_capi_helm/tests/test_driver.py index 7866438..882a890 100644 --- a/magnum_capi_helm/tests/test_driver.py +++ b/magnum_capi_helm/tests/test_driver.py @@ -1957,11 +1957,10 @@ class ClusterAPIDriverTest(base.DbTestCase): ) mock_labels.assert_called_with(self.cluster_obj) - @mock.patch("magnum.common.clients.OpenStackClients.cinder_region_name") @mock.patch("magnum.common.clients.OpenStackClients.cinder") - def test_get_storage_classes(self, mock_cinder, mock_osc_rn): + def test_get_storage_classes(self, mock_cinder): CONF.capi_helm.csi_cinder_default_volume_type = "type3" - mock_osc_rn.return_value = "middle_earth_east" + CONF.capi_helm.csi_cinder_availability_zone = "middle_earth_east" mock_vol_type_1 = mock.MagicMock() mock_vol_type_1.name = "type1" mock_vol_type_2 = mock.MagicMock() @@ -1989,17 +1988,14 @@ class ClusterAPIDriverTest(base.DbTestCase): "type3", storage_classes["defaultStorageClass"]["volumeType"] ) self.assertEqual( - "middle_earth_east", + "middleeartheast", storage_classes["additionalStorageClasses"][0]["availabilityZone"], ) - @mock.patch("magnum.common.clients.OpenStackClients.cinder_region_name") @mock.patch("magnum.common.clients.OpenStackClients.cinder") - def test_get_storage_class_volume_type_not_available( - self, mock_cinder, mock_osc_rn - ): + def test_get_storage_class_volume_type_not_available(self, mock_cinder): CONF.capi_helm.csi_cinder_default_volume_type = "type4" - mock_osc_rn.return_value = "middle_earth_east" + CONF.capi_helm.csi_cinder_availability_zone = "middle_earth_east" mock_vol_type_1 = mock.MagicMock() mock_vol_type_1.name = "type1" mock_vol_type_2 = mock.MagicMock() @@ -2023,13 +2019,10 @@ class ClusterAPIDriverTest(base.DbTestCase): self.cluster_obj, ) - @mock.patch("magnum.common.clients.OpenStackClients.cinder_region_name") @mock.patch("magnum.common.clients.OpenStackClients.cinder") - def test_get_storage_class_volume_type_not_defined( - self, mock_cinder, mock_osc_rn - ): + def test_get_storage_class_volume_type_not_defined(self, mock_cinder): CONF.capi_helm.csi_cinder_default_volume_type = None - mock_osc_rn.return_value = "middle_earth_east" + CONF.capi_helm.csi_cinder_availability_zone = "middle_earth_east" mock_vol_type_1 = mock.MagicMock() mock_vol_type_1.name = "__TYPE1__" mock_vol_type_2 = mock.MagicMock()