Skip to content

Commit

Permalink
Merge pull request #5 from VariableDeclared/pjds/topology
Browse files Browse the repository at this point in the history
Fix availability zones and topology configuration
  • Loading branch information
addyess authored Mar 27, 2024
2 parents 2d00c38 + faa4987 commit 89ab579
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
6 changes: 6 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 19 additions & 2 deletions src/storage_manifests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
1 change: 1 addition & 0 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 89ab579

Please sign in to comment.