diff --git a/config.yaml b/config.yaml index 753708d..b73ba4a 100644 --- a/config.yaml +++ b/config.yaml @@ -54,4 +54,12 @@ options: through to the parameters.reclaimPolicy field of the csi-cinder-default StorageClass. - Potential values are "Delete" or "Retain" \ No newline at end of file + 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 diff --git a/src/storage_manifests.py b/src/storage_manifests.py index 3853a7e..ae0aec1 100644 --- a/src/storage_manifests.py +++ b/src/storage_manifests.py @@ -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",