diff --git a/docs/cluster-connection.md b/docs/cluster-connection.md index 8f1b922..98d432b 100644 --- a/docs/cluster-connection.md +++ b/docs/cluster-connection.md @@ -75,7 +75,19 @@ spec: > **Note:** The volume source can be any type that provides a file. -> **Note:** The Helm chart does not support extra volumes yet. +> **Tip:** When using the Helm chart, configure volumes via `extraVolumes` and `extraVolumeMounts` values: +> +> ```yaml +> app: +> extraVolumes: +> - name: db-credentials +> secret: +> secretName: db-credentials-secret +> extraVolumeMounts: +> - name: db-credentials +> mountPath: /mnt/secrets +> readOnly: true +> ``` ### Examples diff --git a/operator/src/main/helm/values.yaml b/operator/src/main/helm/values.yaml new file mode 100644 index 0000000..5c15947 --- /dev/null +++ b/operator/src/main/helm/values.yaml @@ -0,0 +1,6 @@ +--- +# Workaround: quarkus-helm generates `extraVolumeMounts: {}` (object) instead of `[]` (array) +# when the value path uses a container name filter like `containers.(name == ...)`. +# This merge file corrects the default value type. +app: + extraVolumeMounts: [] diff --git a/operator/src/main/kubernetes/kubernetes.yml b/operator/src/main/kubernetes/kubernetes.yml index 037464e..a3f8dc3 100644 --- a/operator/src/main/kubernetes/kubernetes.yml +++ b/operator/src/main/kubernetes/kubernetes.yml @@ -8,3 +8,7 @@ spec: spec: affinity: {} imagePullSecrets: [~] + volumes: [~] + containers: + - name: postgresql-operator + volumeMounts: [~] diff --git a/operator/src/main/resources/application.yml b/operator/src/main/resources/application.yml index 3b5f766..ecbfdfa 100644 --- a/operator/src/main/resources/application.yml +++ b/operator/src/main/resources/application.yml @@ -113,6 +113,22 @@ quarkus: paths: - (kind == Deployment).spec.template.spec.affinity description: Kubernetes affinity configuration for Pod scheduling + extra-volumes: + property: extraVolumes + value: + - null + paths: + - (kind == Deployment).spec.template.spec.volumes + expression: "{{- if eq (toYaml .Values.app.extraVolumes | trim) \"- {}\" }} null{{- else }}{{ toYaml .Values.app.extraVolumes | nindent 8 }}{{- end }}" + description: Extra volumes to add to the operator pod + extra-volume-mounts: + property: extraVolumeMounts + value: + - null + paths: + - (kind == Deployment).spec.template.spec.containers.(name == postgresql-operator).volumeMounts + expression: "{{- if eq (toYaml .Values.app.extraVolumeMounts | trim) \"- {}\" }} null{{- else }}{{- toYaml .Values.app.extraVolumeMounts | nindent 12 }}{{- end }}" + description: Extra volume mounts to add to the operator container console-color: property: envs.QUARKUS_CONSOLE_COLOR value-as-bool: ${quarkus.console.color} @@ -130,6 +146,12 @@ quarkus: "affinity": name: app.affinity type: object + "extraVolumeMounts": + name: app.extraVolumeMounts + type: array + "extraVolumes": + name: app.extraVolumes + type: array expressions: release-name-labels: expression: "{{ .Release.Name }}" diff --git a/operator/src/test/java/it/aboutbits/postgresql/helm/HelmTest.java b/operator/src/test/java/it/aboutbits/postgresql/helm/HelmTest.java index 7b864be..13a952d 100644 --- a/operator/src/test/java/it/aboutbits/postgresql/helm/HelmTest.java +++ b/operator/src/test/java/it/aboutbits/postgresql/helm/HelmTest.java @@ -92,6 +92,8 @@ void helmInstall_createsDeployment() throws IOException { Objects.requireNonNull(appValues, "appValues should not be null"); assertThat(appValues.get("image")).isNotNull(); + assertThat(appValues).containsKey("extraVolumes"); + assertThat(appValues).containsKey("extraVolumeMounts"); assertThat(chartPath.resolve("LICENSE")).exists(); assertThat(chartPath.resolve("README.md")).exists(); @@ -173,9 +175,11 @@ void helmInstall_createsDeployment() throws IOException { assertThat(deployment.getSpec()) .isNotNull() - .satisfies(spec -> - assertThat(spec.getTemplate().getSpec().getImagePullSecrets()).isEmpty() - ); + .satisfies(spec -> { + assertThat(spec.getTemplate().getSpec().getImagePullSecrets()).isEmpty(); + assertThat(spec.getTemplate().getSpec().getVolumes()).isEmpty(); + assertThat(spec.getTemplate().getSpec().getContainers().getFirst().getVolumeMounts()).isEmpty(); + }); var selector = deployment.getSpec().getSelector();