From 5c40b607e609f93842d9dd3e9d4b2a70b45f844d Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Fri, 29 Nov 2024 13:17:55 +0100 Subject: [PATCH] Add option to handle absent cross_az_attach At the moment volumes for workers are gonna be spawn in a default AZ completely disregarding user request for Availability Zone. In a design where cross_az_attach is disabled, an attempt to add a volume to worker has high failure percentage due to fallback to the default scheduling zone, unless allow_availability_zone_fallback is disabled. This patch adds a configuration option `cross_az_attach` which is set to True by default to align with Nova typical behavior. It will define AZ to be set to `nova` according to a CSI default [1]. When `cross_az_attach` is set to False, AZ for the volume will be set to the cluster AZ value. This ensures that volume will be created in a same zone as workers are preventing failures. [1] https://github.com/kubernetes/cloud-provider-openstack/blob/d228854cf58e7b4ed93d5e7ba68ab639450e3449/docs/cinder-csi-plugin/using-cinder-csi-plugin.md#supported-parameters Relates-to: #366 --- docs/user/configs.md | 11 +++++++++++ magnum_cluster_api/conf.py | 14 ++++++++++++++ magnum_cluster_api/resources.py | 10 ++++++++++ 3 files changed, 35 insertions(+) diff --git a/docs/user/configs.md b/docs/user/configs.md index 9cb1c5a9..7553e90f 100644 --- a/docs/user/configs.md +++ b/docs/user/configs.md @@ -108,3 +108,14 @@ Options under this group are used for configuring Openstack authentication for C : If set, then the server's certificate will not be verified. **Type**: `boolean` **Default value**: `False` + +## cinder +Options under this group are used for configuring OpenStack Cinder behavior. + +`cross_az_attach` + +: When set to False, Cluster Availability Zone will be used to create a volume. + For that Availability Zone names in Cinder and Nova should match. + Otherwise, default `nova` Availability Zone will be used for volumes. + **Type**: `boolean` + **Default value**: `True` diff --git a/magnum_cluster_api/conf.py b/magnum_cluster_api/conf.py index 3edfadb9..cd844350 100644 --- a/magnum_cluster_api/conf.py +++ b/magnum_cluster_api/conf.py @@ -21,6 +21,8 @@ name="capi_client", title="Options for the Cluster API client" ) +cinder_group = cfg.OptGroup(name="cinder", title="Options for the Cinder client") + manila_client_group = cfg.OptGroup( name="manila_client", title="Options for the Manila client" ) @@ -98,6 +100,17 @@ ), ] +cinder_opts = [ + cfg.BoolOpt( + "cross_az_attach", + default=True, + help=_( + "In case of multiple availability zones, allows to create and " + "attach volumes from random AZ to worker nodes. When set to False " + "Availability Zone names in Cinder and Nova should match." + ), + ) +] manila_client_opts = [ cfg.StrOpt( @@ -157,6 +170,7 @@ (auto_scaling_group, auto_scaling_opts), (capi_client_group, capi_client_opts), (capi_client_group, common_security_opts), + (cinder_group, cinder_opts), (manila_client_group, manila_client_opts), (manila_client_group, common_security_opts), (proxy_group, proxy_opts), diff --git a/magnum_cluster_api/resources.py b/magnum_cluster_api/resources.py index 7c917f96..d4858b31 100644 --- a/magnum_cluster_api/resources.py +++ b/magnum_cluster_api/resources.py @@ -296,6 +296,15 @@ def get_object(self) -> pykube.ConfigMap: if cinder.is_enabled(self.cluster): volume_types = osc.cinder().volume_types.list() default_volume_type = osc.cinder().volume_types.default() + # Default is set in accordance to the CSI: + # https://github.com/kubernetes/cloud-provider-openstack/blob/d228854cf58e7b4ed93d5e7ba68ab639450e3449/docs/cinder-csi-plugin/using-cinder-csi-plugin.md#supported-parameters + # If allow_availability_zone_fallback is set to False in Cinder + # and "nova" AZ is not present in Cinder, CSI request will fail. + volume_availability_zone = "nova" + if not CONF.cinder.cross_az_attach: + volume_availability_zone = self.cluster.labels.get( + "availability_zone", volume_availability_zone + ) data = { **data, **{ @@ -333,6 +342,7 @@ def get_object(self) -> pykube.ConfigMap: "provisioner": "cinder.csi.openstack.org", "parameters": { "type": vt.name, + "availability": volume_availability_zone, }, "reclaimPolicy": "Delete", "volumeBindingMode": "Immediate",