Skip to content

Commit

Permalink
fix: purge any cephfs storage classes installed by ops.manifest (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
addyess authored Feb 11, 2025
1 parent a3033be commit dba68cb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ops >= 1.2.0
ops.manifest >= 1.1.3, < 2.0
ops.manifest >= 1.5.0, < 2.0
jinja2
pyyaml

Expand Down
7 changes: 6 additions & 1 deletion src/manifests_cephfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import logging
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, cast

from lightkube.codecs import AnyResource
from lightkube.resources.core_v1 import Secret
Expand Down Expand Up @@ -174,6 +174,11 @@ def parameter_list(self) -> List[CephStorageClassParameters]:

def __call__(self) -> List[AnyResource]:
"""Craft the storage class object."""
if cast(SafeManifest, self.manifests).purgeable:
# If we are purging, we may not be able to create any storage classes
# Just return a fake storage class to satisfy delete_manifests method
# which will look up all storage classes installed by this app/manifest
return [StorageClass.from_dict(dict(metadata={}, provisioner=self.PROVISIONER))]
return [self.create(class_param) for class_param in self.parameter_list()]


Expand Down
15 changes: 15 additions & 0 deletions tests/unit/test_manifests_cephfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def test_ceph_provisioner_adjustment_modelled(caplog):
def test_ceph_storage_class_modelled(caplog):
caplog.set_level(logging.INFO)
manifest = mock.MagicMock()
manifest.purgeable = False
csc = CephStorageClass(manifest)
alt_ns = "diff-ns"

Expand Down Expand Up @@ -140,6 +141,20 @@ def test_ceph_storage_class_modelled(caplog):
assert f"Modelling storage class sc='{TEST_CEPH_FS_ALT.name}'" in caplog.text


def test_ceph_storage_class_purgeable(caplog):
caplog.set_level(logging.INFO)
manifest = mock.MagicMock()
manifest.purgeable = True
csc = CephStorageClass(manifest)

caplog.clear()
expected = StorageClass(
metadata=ObjectMeta(),
provisioner=CephStorageClass.PROVISIONER,
)
assert csc() == [expected]


def test_manifest_evaluation(caplog):
caplog.set_level(logging.INFO)
charm = mock.MagicMock()
Expand Down

0 comments on commit dba68cb

Please sign in to comment.