Skip to content

Commit

Permalink
Provide charm config to set the cinder-csi storage class as the defau…
Browse files Browse the repository at this point in the history
…lt (#8)
  • Loading branch information
addyess authored Jul 31, 2024
1 parent 6a28597 commit e0ade0d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 9 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,12 @@ options:
through to the parameters.reclaimPolicy field of the csi-cinder-default
StorageClass.
Potential values are "Delete" or "Retain"
Potential values are "Delete" or "Retain"
storage-class-default:
type: boolean
default: false
description: |
https://kubernetes.io/docs/tasks/administer-cluster/change-default-storage-class/
Whether to set the storage class for the Cinder CSI driver as the cluster default
6 changes: 5 additions & 1 deletion src/storage_manifests.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,16 @@ def __call__(self) -> Optional[AnyResource]:
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"
is_default: str = "true" if self.manifests.config.get("storage-class-default") else "false"

sc = from_dict(
dict(
apiVersion="storage.k8s.io/v1",
kind="StorageClass",
metadata=dict(name=storage_name),
metadata=dict(
name=storage_name,
annotations={"storageclass.kubernetes.io/is-default-class": is_default},
),
provisioner="cinder.csi.openstack.org",
reclaimPolicy=reclaim_policy.title(),
volumeBindingMode="WaitForFirstConsumer",
Expand Down

0 comments on commit e0ade0d

Please sign in to comment.