Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LP#2039667] Provide charm config parameters on the default storage class #31

Merged
merged 4 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,22 @@ options:
The current release deployed is available by viewing
juju status vsphere-cloud-provider

storage-class-parameters:
type: string
description: |
Specify extra parmeters to the default storage class installed.
Each parameter is separated by commas and are key=value pairs

example)
storagepolicyname=vSAN Default Storage Policy
storagepolicyname=vSAN Default Storage Policy,datastoreurl=ds:///vmfs/volumes/vsan:52cdfa80721ff516-ea1e993113acfc77/

default: 'storagepolicyname=vSAN Default Storage Policy'

csi-migration:
description: |
Enables the CSIMigration feature of the storage-provider allowing
the driver plugin to migrate in-tree volumes to the out-of-tree provider.
type: string
default: "false"

2 changes: 1 addition & 1 deletion src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def _install_or_upgrade(self, event, config_hash=None):
controller.apply_manifests()
except ManifestClientError as e:
self.unit.status = WaitingStatus("Waiting for kube-apiserver")
log.warn(f"Encountered retryable installation error: {e}")
log.warning(f"Encountered retryable installation error: {e}")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removes a deprecated method call

event.defer()
return False
return True
Expand Down
14 changes: 13 additions & 1 deletion src/storage_manifests.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ def __init__(self, manifests: "Manifests", sc_type: str):
super().__init__(manifests)
self.type = sc_type

@property
def _params(self) -> Dict[str, str]:
parameter_config = self.manifests.config["storage-class-parameters"]
parameters = {}
for param in parameter_config.split(","):
try:
key, val = param.split("=", 1)
parameters[key] = val
except ValueError:
log.error("Storage class parameter missing '=' separator in '%s'", param)
return parameters

def __call__(self) -> Optional[AnyResource]:
"""Craft the storage class object."""
storage_name = STORAGE_CLASS_NAME.format(type=self.type)
Expand All @@ -141,7 +153,7 @@ def __call__(self) -> Optional[AnyResource]:
},
),
provisioner="csi.vsphere.vmware.com",
parameters=dict(storagepolicyname="vSAN Default Storage Policy"),
parameters=self._params,
)
)

Expand Down
26 changes: 26 additions & 0 deletions tests/unit/test_storage_manifests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2023 Canonical Ltd.
# See LICENSE file for licensing details.
#
# Learn more about testing at: https://juju.is/docs/sdk/testing


from unittest import mock

from storage_manifests import CreateStorageClass


def test_parse_parameter_config():
mock_manifests = mock.MagicMock()
mock_manifests.config = {"storage-class-parameters": "key=val,something=test with spaces"}
sc = CreateStorageClass(mock_manifests, "default")
assert sc._params == {"key": "val", "something": "test with spaces"}


def test_parse_parameter_invalid(caplog):
mock_manifests = mock.MagicMock()
mock_manifests.config = {"storage-class-parameters": "key=val,something"}
sc = CreateStorageClass(mock_manifests, "default")
assert sc._params == {"key": "val"}
error_logs = [rec for rec in caplog.records if rec.levelname == "ERROR"]
assert len(error_logs) == 1, "Expect one error"
assert error_logs[0].message == "Storage class parameter missing '=' separator in 'something'"
2 changes: 1 addition & 1 deletion upstream/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def __hash__(self) -> int:
return hash(self.name)

def __eq__(self, other) -> bool:
"""Comparible based on its name."""
"""Comparable based on its name."""
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixes misspelling

return isinstance(other, Release) and self.name == other.name

def __lt__(self, other) -> bool:
Expand Down