Skip to content

Commit

Permalink
Merge pull request #6 from canonical/bug/lp2071824/config-reclaim-policy
Browse files Browse the repository at this point in the history
Charm config to set the reclaim policy on the default storage class
  • Loading branch information
addyess authored Jul 3, 2024
2 parents 89ab579 + e280095 commit 6a28597
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [pull_request]
jobs:
call-inclusive-naming-check:
name: Inclusive Naming
uses: canonical-web-and-design/Inclusive-naming/.github/workflows/woke.yaml@main
uses: canonical/inclusive-naming/.github/workflows/woke.yaml@main
with:
fail-on-error: "true"

Expand Down
14 changes: 13 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,16 @@ options:
type: boolean
default: True
description: |
Whether to enable the Cinder CSI topology awareness
Whether to enable the Cinder CSI topology awareness
reclaim-policy:
type: string
default: "Delete"
description: |
https://kubernetes.io/docs/concepts/storage/storage-classes/#reclaim-policy
The reclaim policy for the PVCs created by the CSI driver. This is passed
through to the parameters.reclaimPolicy field of the csi-cinder-default
StorageClass.
Potential values are "Delete" or "Retain"
2 changes: 2 additions & 0 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ def available_data(self):

def evaluate(self) -> Optional[str]:
"""Determine if configuration is valid."""
if self.config["reclaim-policy"].title() not in ["Delete", "Retain"]:
return "reclaim-policy should be either 'Delete' or 'Retain'"
return None
4 changes: 3 additions & 1 deletion src/storage_manifests.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ def __call__(self) -> Optional[AnyResource]:
"""Craft the storage class object."""
storage_name = STORAGE_CLASS_NAME.format(type=self.type)
log.info(f"Creating storage class {storage_name}")
reclaim_policy: str = self.manifests.config.get("reclaim-policy") or "Delete"

sc = from_dict(
dict(
apiVersion="storage.k8s.io/v1",
kind="StorageClass",
metadata=dict(name=storage_name),
provisioner="cinder.csi.openstack.org",
reclaimPolicy="Delete",
reclaimPolicy=reclaim_policy.title(),
volumeBindingMode="WaitForFirstConsumer",
)
)
Expand Down

0 comments on commit 6a28597

Please sign in to comment.