diff --git a/charts/matrix-stack/source/common/persistentVolumeClaim.json b/charts/matrix-stack/source/common/persistentVolumeClaim.json index 0c7afb03..c419d98c 100644 --- a/charts/matrix-stack/source/common/persistentVolumeClaim.json +++ b/charts/matrix-stack/source/common/persistentVolumeClaim.json @@ -19,6 +19,9 @@ }, "selector": { "$ref": "file://common/labelSelector.json" + }, + "volumeName": { + "type": "string" } } } diff --git a/charts/matrix-stack/source/common/sub_schema_values.yaml.j2 b/charts/matrix-stack/source/common/sub_schema_values.yaml.j2 index 6432a466..5c4ed5b5 100644 --- a/charts/matrix-stack/source/common/sub_schema_values.yaml.j2 +++ b/charts/matrix-stack/source/common/sub_schema_values.yaml.j2 @@ -228,6 +228,9 @@ networking: ## The PersistentVolumeClaim PV selector # selector: {} + + ## The PersistentVolumeClaim PV name + # volumeName: {%- endif %} ## The StorageClass to be used by {{ 'all constructed PersistentVolumeClaims by default' if global else 'the constructed PersistentVolumeClaim' }}. diff --git a/charts/matrix-stack/templates/hookshot/hookshot_persistentvolumeclaim.yaml b/charts/matrix-stack/templates/hookshot/hookshot_persistentvolumeclaim.yaml index 9fd98377..1c8fef49 100644 --- a/charts/matrix-stack/templates/hookshot/hookshot_persistentvolumeclaim.yaml +++ b/charts/matrix-stack/templates/hookshot/hookshot_persistentvolumeclaim.yaml @@ -26,6 +26,9 @@ spec: resources: requests: storage: {{ .storage.size }} +{{- with .storage.volumeName }} + volumeName: {{ . }} +{{- end }} {{- with .storage.selector }} selector: {{ toYaml . | nindent 4 }} diff --git a/charts/matrix-stack/templates/postgres/pvc.yaml b/charts/matrix-stack/templates/postgres/pvc.yaml index 2aa2bebe..88b1e5fe 100644 --- a/charts/matrix-stack/templates/postgres/pvc.yaml +++ b/charts/matrix-stack/templates/postgres/pvc.yaml @@ -26,6 +26,9 @@ spec: resources: requests: storage: {{ .storage.size }} +{{- with .storage.volumeName }} + volumeName: {{ . }} +{{- end }} {{- with .storage.selector }} selector: {{ toYaml . | nindent 4 }} diff --git a/charts/matrix-stack/templates/synapse/synapse_persistentvolumeclaim.yaml b/charts/matrix-stack/templates/synapse/synapse_persistentvolumeclaim.yaml index 4d7dacdf..d02bd49e 100644 --- a/charts/matrix-stack/templates/synapse/synapse_persistentvolumeclaim.yaml +++ b/charts/matrix-stack/templates/synapse/synapse_persistentvolumeclaim.yaml @@ -26,6 +26,9 @@ spec: resources: requests: storage: {{ .media.storage.size }} +{{- with .media.storage.volumeName }} + volumeName: {{ . }} +{{- end }} {{- with .media.storage.selector }} selector: {{ toYaml . | nindent 4 }} diff --git a/charts/matrix-stack/values.schema.json b/charts/matrix-stack/values.schema.json index cd62a2f7..27099484 100644 --- a/charts/matrix-stack/values.schema.json +++ b/charts/matrix-stack/values.schema.json @@ -5586,6 +5586,9 @@ } }, "additionalProperties": false + }, + "volumeName": { + "type": "string" } }, "additionalProperties": false @@ -8354,6 +8357,9 @@ } }, "additionalProperties": false + }, + "volumeName": { + "type": "string" } }, "additionalProperties": false @@ -10199,6 +10205,9 @@ } }, "additionalProperties": false + }, + "volumeName": { + "type": "string" } }, "additionalProperties": false diff --git a/charts/matrix-stack/values.yaml b/charts/matrix-stack/values.yaml index b64ea97f..ab648287 100644 --- a/charts/matrix-stack/values.yaml +++ b/charts/matrix-stack/values.yaml @@ -2023,6 +2023,9 @@ hookshot: ## The PersistentVolumeClaim PV selector # selector: {} + ## The PersistentVolumeClaim PV name + # volumeName: + ## The StorageClass to be used by the constructed PersistentVolumeClaim. ## The top-level storage.storageClassName value is used, if not provided (or the cluster default if neither are provided). ## If changed after initial usage the PersistentVolumeClaim could be recreated causing data-loss. @@ -3036,6 +3039,9 @@ postgres: ## The PersistentVolumeClaim PV selector # selector: {} + ## The PersistentVolumeClaim PV name + # volumeName: + ## The StorageClass to be used by the constructed PersistentVolumeClaim. ## The top-level storage.storageClassName value is used, if not provided (or the cluster default if neither are provided). ## If changed after initial usage the PersistentVolumeClaim could be recreated causing data-loss. @@ -3687,6 +3693,9 @@ synapse: ## The PersistentVolumeClaim PV selector # selector: {} + ## The PersistentVolumeClaim PV name + # volumeName: + ## The StorageClass to be used by the constructed PersistentVolumeClaim. ## The top-level storage.storageClassName value is used, if not provided (or the cluster default if neither are provided). ## If changed after initial usage the PersistentVolumeClaim could be recreated causing data-loss. diff --git a/newsfragments/1400.added.md b/newsfragments/1400.added.md new file mode 100644 index 00000000..d9a37538 --- /dev/null +++ b/newsfragments/1400.added.md @@ -0,0 +1 @@ +Add support for configuring `PersistentVolumeClaim` `volumeName` property. diff --git a/tests/manifests/test_pvcs.py b/tests/manifests/test_pvcs.py index 4cb7aa59..e34c2468 100644 --- a/tests/manifests/test_pvcs.py +++ b/tests/manifests/test_pvcs.py @@ -193,3 +193,37 @@ async def test_pvc_gets_configured_selector(values, make_templates, release_name deployable_details = template_to_deployable_details(template) expected_selector = deployable_details.get_helm_values(values, PropertyType.Storage)["selector"] assert pvc_spec["selector"] == expected_selector, f"{template_id(template)} has an unexpected selector" + + +@pytest.mark.parametrize("values_file", values_files_to_test) +@pytest.mark.asyncio_cooperative +async def test_pvc_has_no_volumeName_by_default(templates): + for template in templates: + if template["kind"] in ["PersistentVolumeClaim"]: + pvc_spec = template["spec"] + assert "volumeName" not in pvc_spec, ( + f"{template_id(template)} has a default volumeName when one isn't configured" + ) + + +@pytest.mark.parametrize("values_file", values_files_to_test) +@pytest.mark.asyncio_cooperative +async def test_pvc_gets_configured_volumeName(values, make_templates, release_name): + def set_volumeName(deployable_details: DeployableDetails): + volumeName = "".join(random.choices(string.ascii_lowercase)) + deployable_details.set_helm_values(values, PropertyType.Storage, {"volumeName": volumeName}) + + iterate_deployables_parts( + set_volumeName, + lambda deployable_details: deployable_details.has_storage, + ) + for template in await make_templates(values): + if template["kind"] in ["PersistentVolumeClaim"]: + pvc_spec = template["spec"] + assert "volumeName" in pvc_spec, f"{template_id(template)} doesn't have a volumeName when one is configured" + + deployable_details = template_to_deployable_details(template) + expected_volumeName = deployable_details.get_helm_values(values, PropertyType.Storage)["volumeName"] + assert pvc_spec["volumeName"] == expected_volumeName, ( + f"{template_id(template)} has an unexpected volumeName" + )