diff --git a/config.yaml b/config.yaml index 1da1345..2aceeb2 100644 --- a/config.yaml +++ b/config.yaml @@ -37,3 +37,9 @@ options: description: | Availability zone to use with Cinder CSI. This is passed through to the parameters.availability field of the csi-cinder-default StorageClass. + + topology: + type: boolean + default: True + description: | + Whether to enable the Cinder CSI topology awareness \ No newline at end of file diff --git a/src/storage_manifests.py b/src/storage_manifests.py index ec16599..5a6a724 100644 --- a/src/storage_manifests.py +++ b/src/storage_manifests.py @@ -66,9 +66,8 @@ def __call__(self) -> Optional[AnyResource]: volumeBindingMode="WaitForFirstConsumer", ) ) - if az := self.manifests.config.get("availability-zone"): - sc.parameters.availability = az + sc.parameters = dict(availability=az) return sc @@ -105,6 +104,7 @@ def __init__(self, charm, charm_config, kube_control, integrator): ConfigRegistry(self), CreateStorageClass(self, "default"), # creates csi-cinder-default UpdateSecrets(self), # update secrets + UpdateControllerPlugin(self), ], ) self.integrator = integrator @@ -142,3 +142,20 @@ def evaluate(self) -> Optional[str]: if not self.config.get(prop): return f"Storage manifests waiting for definition of {prop}" return None + + +class UpdateControllerPlugin(Patch): + """Update the controller args in Deployments.""" + + def __call__(self, obj): + """Update the controller args in Deployments.""" + if not (obj.kind == "Deployment" and obj.metadata.name == "csi-cinder-controllerplugin"): + return + + for container in obj.spec.template.spec.containers: + if container.name == "csi-provisioner": + for i, val in enumerate(container.args): + if "feature-gates" in val.lower(): + topology = str(self.manifests.config.get("topology")).lower() + container.args[i] = f"feature-gates=Topology={topology}" + log.info("Configuring cinder topology awareness=%s", topology) diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py index b6c55af..8ef0308 100644 --- a/tests/unit/test_charm.py +++ b/tests/unit/test_charm.py @@ -164,6 +164,7 @@ def test_waits_for_kube_control(mock_create_kubeconfig, harness, caplog): "Creating storage class csi-cinder-default", "Setting secret for DaemonSet/csi-cinder-nodeplugin", "Setting secret for Deployment/csi-cinder-controllerplugin", + "Configuring cinder topology awareness=true", } caplog.clear()