diff --git a/charts/matrix-stack/source/common/persistentVolumeClaim.json b/charts/matrix-stack/source/common/persistentVolumeClaim.json index a39a5c7e..0c7afb03 100644 --- a/charts/matrix-stack/source/common/persistentVolumeClaim.json +++ b/charts/matrix-stack/source/common/persistentVolumeClaim.json @@ -16,6 +16,9 @@ "keep", "delete" ] + }, + "selector": { + "$ref": "file://common/labelSelector.json" } } } 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 3ef47eae..6432a466 100644 --- a/charts/matrix-stack/source/common/sub_schema_values.yaml.j2 +++ b/charts/matrix-stack/source/common/sub_schema_values.yaml.j2 @@ -225,6 +225,9 @@ networking: ## The size of a PersistentVolumeClaim to be constructed ## Ignored if existingClaim is provided size: 10Gi + + ## The PersistentVolumeClaim PV selector + # selector: {} {%- 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 995e8bf0..9fd98377 100644 --- a/charts/matrix-stack/templates/hookshot/hookshot_persistentvolumeclaim.yaml +++ b/charts/matrix-stack/templates/hookshot/hookshot_persistentvolumeclaim.yaml @@ -26,6 +26,10 @@ spec: resources: requests: storage: {{ .storage.size }} +{{- with .storage.selector }} + selector: + {{ toYaml . | nindent 4 }} +{{- end }} {{- end }} {{- end }} {{- end }} diff --git a/charts/matrix-stack/templates/postgres/pvc.yaml b/charts/matrix-stack/templates/postgres/pvc.yaml index b4c0c17c..2aa2bebe 100644 --- a/charts/matrix-stack/templates/postgres/pvc.yaml +++ b/charts/matrix-stack/templates/postgres/pvc.yaml @@ -26,6 +26,10 @@ spec: resources: requests: storage: {{ .storage.size }} +{{- with .storage.selector }} + selector: + {{ toYaml . | nindent 4 }} +{{- end }} {{- end }} {{- end -}} {{- end -}} diff --git a/charts/matrix-stack/templates/synapse/synapse_persistentvolumeclaim.yaml b/charts/matrix-stack/templates/synapse/synapse_persistentvolumeclaim.yaml index 18770d71..4d7dacdf 100644 --- a/charts/matrix-stack/templates/synapse/synapse_persistentvolumeclaim.yaml +++ b/charts/matrix-stack/templates/synapse/synapse_persistentvolumeclaim.yaml @@ -26,6 +26,10 @@ spec: resources: requests: storage: {{ .media.storage.size }} +{{- with .media.storage.selector }} + selector: + {{ toYaml . | nindent 4 }} +{{- end }} {{- end }} {{- end -}} {{- end -}} diff --git a/charts/matrix-stack/values.schema.json b/charts/matrix-stack/values.schema.json index 3b63661f..cd62a2f7 100644 --- a/charts/matrix-stack/values.schema.json +++ b/charts/matrix-stack/values.schema.json @@ -5537,6 +5537,55 @@ "keep", "delete" ] + }, + "selector": { + "type": "object", + "properties": { + "matchExpressions": { + "type": "array", + "items": { + "type": "object", + "required": [ + "key", + "operator" + ], + "properties": { + "key": { + "type": "string" + }, + "operator": { + "type": "string", + "enum": [ + "In", + "NotIn", + "Exists", + "DoesNotExist" + ] + }, + "values": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "additionalProperties": false + } + }, + "matchLabels": { + "type": [ + "object", + "null" + ], + "additionalProperties": { + "type": [ + "string", + "null" + ] + } + } + }, + "additionalProperties": false } }, "additionalProperties": false @@ -8256,6 +8305,55 @@ "keep", "delete" ] + }, + "selector": { + "type": "object", + "properties": { + "matchExpressions": { + "type": "array", + "items": { + "type": "object", + "required": [ + "key", + "operator" + ], + "properties": { + "key": { + "type": "string" + }, + "operator": { + "type": "string", + "enum": [ + "In", + "NotIn", + "Exists", + "DoesNotExist" + ] + }, + "values": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "additionalProperties": false + } + }, + "matchLabels": { + "type": [ + "object", + "null" + ], + "additionalProperties": { + "type": [ + "string", + "null" + ] + } + } + }, + "additionalProperties": false } }, "additionalProperties": false @@ -10052,6 +10150,55 @@ "keep", "delete" ] + }, + "selector": { + "type": "object", + "properties": { + "matchExpressions": { + "type": "array", + "items": { + "type": "object", + "required": [ + "key", + "operator" + ], + "properties": { + "key": { + "type": "string" + }, + "operator": { + "type": "string", + "enum": [ + "In", + "NotIn", + "Exists", + "DoesNotExist" + ] + }, + "values": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "additionalProperties": false + } + }, + "matchLabels": { + "type": [ + "object", + "null" + ], + "additionalProperties": { + "type": [ + "string", + "null" + ] + } + } + }, + "additionalProperties": false } }, "additionalProperties": false diff --git a/charts/matrix-stack/values.yaml b/charts/matrix-stack/values.yaml index 7ed91de2..b64ea97f 100644 --- a/charts/matrix-stack/values.yaml +++ b/charts/matrix-stack/values.yaml @@ -2020,6 +2020,9 @@ hookshot: ## Ignored if existingClaim is provided size: 10Gi + ## The PersistentVolumeClaim PV selector + # selector: {} + ## 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. @@ -3030,6 +3033,9 @@ postgres: ## Ignored if existingClaim is provided size: 10Gi + ## The PersistentVolumeClaim PV selector + # selector: {} + ## 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. @@ -3678,6 +3684,9 @@ synapse: ## Ignored if existingClaim is provided size: 10Gi + ## The PersistentVolumeClaim PV selector + # selector: {} + ## 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/1398.added.md b/newsfragments/1398.added.md new file mode 100644 index 00000000..158424e7 --- /dev/null +++ b/newsfragments/1398.added.md @@ -0,0 +1 @@ +Add support for configuring `PersistentVolumeClaim` `selector` properties. diff --git a/tests/manifests/test_pvcs.py b/tests/manifests/test_pvcs.py index 4601157a..4cb7aa59 100644 --- a/tests/manifests/test_pvcs.py +++ b/tests/manifests/test_pvcs.py @@ -161,3 +161,35 @@ async def test_individual_storageClassName_passed_through_to_created_pvcs(values assert expected_storageClassName == template["spec"]["storageClassName"], ( f"{template_id(template)} didn't respect the configured PVC storageClassName" ) + + +@pytest.mark.parametrize("values_file", values_files_to_test) +@pytest.mark.asyncio_cooperative +async def test_pvc_has_no_selector_by_default(templates): + for template in templates: + if template["kind"] in ["PersistentVolumeClaim"]: + pvc_spec = template["spec"] + assert "selectors" not in pvc_spec, ( + f"{template_id(template)} has a default selector when one isn't configured" + ) + + +@pytest.mark.parametrize("values_file", values_files_to_test) +@pytest.mark.asyncio_cooperative +async def test_pvc_gets_configured_selector(values, make_templates, release_name): + def set_selector(deployable_details: DeployableDetails): + selector = {"k8s.element.io/pvc-testing": "".join(random.choices(string.ascii_lowercase))} + deployable_details.set_helm_values(values, PropertyType.Storage, {"selector": {"matchLabels": selector}}) + + iterate_deployables_parts( + set_selector, + lambda deployable_details: deployable_details.has_storage, + ) + for template in await make_templates(values): + if template["kind"] in ["PersistentVolumeClaim"]: + pvc_spec = template["spec"] + assert "selector" in pvc_spec, f"{template_id(template)} doesn't have a selector when one is configured" + + 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"