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
This commit is contained in:
parent
18045a7070
commit
cc89e48141
@ -125,6 +125,7 @@ The driver respects the following cluster and template properties:
|
|||||||
|
|
||||||
The driver supports the following labels:
|
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
|
* monitoring_enabled: default is off, change to "true" to enable
|
||||||
* kube_dashboard_enabled: defalt is on, change to "false" to disable
|
* kube_dashboard_enabled: defalt is on, change to "false" to disable
|
||||||
* octavia_provider: default is "amphora", ovn is also an option
|
* octavia_provider: default is "amphora", ovn is also an option
|
||||||
|
@ -117,6 +117,11 @@ capi_helm_opts = [
|
|||||||
"volume binding and dynamic provisioning should occur."
|
"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(
|
cfg.StrOpt(
|
||||||
"app_cred_interface_type",
|
"app_cred_interface_type",
|
||||||
default="public",
|
default="public",
|
||||||
|
@ -625,6 +625,13 @@ class Driver(driver.Driver):
|
|||||||
f"Minimum {CONF.capi_helm.minimum_flavor_ram} MB required."
|
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):
|
def _get_csi_cinder_reclaim_policy(self, cluster):
|
||||||
return self._label(
|
return self._label(
|
||||||
cluster,
|
cluster,
|
||||||
@ -660,7 +667,7 @@ class Driver(driver.Driver):
|
|||||||
"""
|
"""
|
||||||
LOG.debug("Retrieve volume types from cinder for StorageClasses.")
|
LOG.debug("Retrieve volume types from cinder for StorageClasses.")
|
||||||
client = clients.OpenStackClients(context)
|
client = clients.OpenStackClients(context)
|
||||||
region_name = client.cinder_region_name()
|
availability_zone = self._get_csi_cinder_availability_zone(cluster)
|
||||||
c_client = client.cinder()
|
c_client = client.cinder()
|
||||||
volume_types = [i.name for i in c_client.volume_types.list()]
|
volume_types = [i.name for i in c_client.volume_types.list()]
|
||||||
# Use the default volume type if defined. Otherwise use the first
|
# 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),
|
"name": driver_utils.sanitized_name(volume_type),
|
||||||
"reclaimPolicy": reclaim_policy,
|
"reclaimPolicy": reclaim_policy,
|
||||||
"allowVolumeExpansion": allow_expansion,
|
"allowVolumeExpansion": allow_expansion,
|
||||||
"availabilityZone": region_name,
|
"availabilityZone": availability_zone,
|
||||||
"volumeType": volume_type,
|
"volumeType": volume_type,
|
||||||
"allowedTopologies": allowed_topologies,
|
"allowedTopologies": allowed_topologies,
|
||||||
"fstype": fstype,
|
"fstype": fstype,
|
||||||
|
@ -1957,11 +1957,10 @@ class ClusterAPIDriverTest(base.DbTestCase):
|
|||||||
)
|
)
|
||||||
mock_labels.assert_called_with(self.cluster_obj)
|
mock_labels.assert_called_with(self.cluster_obj)
|
||||||
|
|
||||||
@mock.patch("magnum.common.clients.OpenStackClients.cinder_region_name")
|
|
||||||
@mock.patch("magnum.common.clients.OpenStackClients.cinder")
|
@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"
|
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 = mock.MagicMock()
|
||||||
mock_vol_type_1.name = "type1"
|
mock_vol_type_1.name = "type1"
|
||||||
mock_vol_type_2 = mock.MagicMock()
|
mock_vol_type_2 = mock.MagicMock()
|
||||||
@ -1989,17 +1988,14 @@ class ClusterAPIDriverTest(base.DbTestCase):
|
|||||||
"type3", storage_classes["defaultStorageClass"]["volumeType"]
|
"type3", storage_classes["defaultStorageClass"]["volumeType"]
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
"middle_earth_east",
|
"middleeartheast",
|
||||||
storage_classes["additionalStorageClasses"][0]["availabilityZone"],
|
storage_classes["additionalStorageClasses"][0]["availabilityZone"],
|
||||||
)
|
)
|
||||||
|
|
||||||
@mock.patch("magnum.common.clients.OpenStackClients.cinder_region_name")
|
|
||||||
@mock.patch("magnum.common.clients.OpenStackClients.cinder")
|
@mock.patch("magnum.common.clients.OpenStackClients.cinder")
|
||||||
def test_get_storage_class_volume_type_not_available(
|
def test_get_storage_class_volume_type_not_available(self, mock_cinder):
|
||||||
self, mock_cinder, mock_osc_rn
|
|
||||||
):
|
|
||||||
CONF.capi_helm.csi_cinder_default_volume_type = "type4"
|
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 = mock.MagicMock()
|
||||||
mock_vol_type_1.name = "type1"
|
mock_vol_type_1.name = "type1"
|
||||||
mock_vol_type_2 = mock.MagicMock()
|
mock_vol_type_2 = mock.MagicMock()
|
||||||
@ -2023,13 +2019,10 @@ class ClusterAPIDriverTest(base.DbTestCase):
|
|||||||
self.cluster_obj,
|
self.cluster_obj,
|
||||||
)
|
)
|
||||||
|
|
||||||
@mock.patch("magnum.common.clients.OpenStackClients.cinder_region_name")
|
|
||||||
@mock.patch("magnum.common.clients.OpenStackClients.cinder")
|
@mock.patch("magnum.common.clients.OpenStackClients.cinder")
|
||||||
def test_get_storage_class_volume_type_not_defined(
|
def test_get_storage_class_volume_type_not_defined(self, mock_cinder):
|
||||||
self, mock_cinder, mock_osc_rn
|
|
||||||
):
|
|
||||||
CONF.capi_helm.csi_cinder_default_volume_type = None
|
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 = mock.MagicMock()
|
||||||
mock_vol_type_1.name = "__TYPE1__"
|
mock_vol_type_1.name = "__TYPE1__"
|
||||||
mock_vol_type_2 = mock.MagicMock()
|
mock_vol_type_2 = mock.MagicMock()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user