Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions charts/cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ refer to the [CloudNativePG Documentation](https://cloudnative-pg.io/documentat
| cluster.walStorage.enabled | bool | `false` | |
| cluster.walStorage.size | string | `"1Gi"` | |
| cluster.walStorage.storageClass | string | `""` | |
| databases | list | `[]` | |
| fullnameOverride | string | `""` | Override the full name of the chart |
| imageCatalog.create | bool | `true` | Whether to provision an image catalog. If imageCatalog.images is empty this option will be ignored. |
| imageCatalog.images | list | `[]` | List of images to be provisioned in an image catalog. |
Expand Down
83 changes: 83 additions & 0 deletions charts/cluster/templates/databases.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{{- range .Values.databases }}
---
apiVersion: postgresql.cnpg.io/v1
kind: Database
metadata:
name: {{ include "cluster.fullname" $ }}-{{ .name | replace "_" "-" }}
namespace: {{ include "cluster.namespace" $ }}
{{- with $.Values.cluster.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
labels:
{{- include "cluster.labels" $ | nindent 4 }}
{{- with $.Values.cluster.additionalLabels }}
{{ toYaml . | nindent 4 }}
{{- end }}
spec:
name: {{ .name }}
cluster:
name: {{ include "cluster.fullname" $ }}
ensure: {{ .ensure | default "present" }}
owner: {{ .owner }}
template: {{ .template | default "template1" }}
encoding: {{ .encoding | default "UTF8" }}
databaseReclaimPolicy: {{ .databaseReclaimPolicy | default "retain" }}
{{- with .isTemplate }}
isTemplate: {{ . }}
{{- end }}
{{- with .allowConnections }}
allowConnections: {{ . }}
{{- end }}
{{- with .connectionLimit }}
connectionLimit: {{ . }}
{{- end }}
{{- with .tablespace }}
tablespace: {{ . }}
{{- end }}
{{- with .locale }}
locale: {{ . }}
{{- end }}
{{- with .localeProvider }}
localeProvider: {{ . }}
{{- end }}
{{- with .localeCollate }}
localeCollate: {{ . }}
{{- end }}
{{- with .localeCType }}
localeCType: {{ . }}
{{- end }}
{{- with .icuLocale }}
icuLocale: {{ . }}
{{- end }}
{{- with .icuRules }}
icuRules: {{ . }}
{{- end }}
{{- with .builtinLocale }}
builtinLocale: {{ . }}
{{- end }}
{{- with .collationVersion }}
collationVersion: {{ . | quote }}
{{- end }}
{{- with .schemas }}
schemas:
{{- range . }}
- name: {{ .name }}
owner: {{ .owner }}
ensure: {{ .ensure | default "present" }}
{{- end }}
{{- end }}
{{- with .extensions }}
extensions:
{{- range . }}
- name: {{ .name }}
{{- with .version }}
version: {{ . }}
{{- end }}
{{- with .schema }}
schema: {{ . }}
{{- end }}
ensure: {{ .ensure | default "present" }}
{{- end }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
apiVersion: postgresql.cnpg.io/v1
kind: Database
metadata:
name: database-parameters-cluster-default-db
spec:
name: default_db
cluster:
name: database-parameters-cluster
ensure: present
owner: test-owner
template: template1
encoding: UTF8
databaseReclaimPolicy: retain
---
apiVersion: postgresql.cnpg.io/v1
kind: Database
metadata:
name: database-parameters-cluster-test-db-icu
spec:
name: test-db-icu
cluster:
name: database-parameters-cluster
ensure: present
owner: test-owner
template: template0
encoding: UTF16
connectionLimit: 100
tablespace: test-space
databaseReclaimPolicy: delete
isTemplate: true
locale: "en_GB.utf8"
localeProvider: icu
localeCollate: "en_GB.utf8"
localeCType: "en_GB.utf8"
icuLocale: "en_GB"
icuRules: "en_GB"
collationVersion: "1"
schemas:
- name: test-schema
owner: test-owner
ensure: absent
extensions:
- name: pg_search
ensure: absent
version: "0.15.21"
schema: test-schema

---
apiVersion: postgresql.cnpg.io/v1
kind: Database
metadata:
name: database-parameters-cluster-test-db-builtin
spec:
name: test-db-builtin
cluster:
name: database-parameters-cluster
ensure: present
owner: test-owner
template: template0
encoding: UTF16
connectionLimit: 100
tablespace: test-space
databaseReclaimPolicy: delete
isTemplate: true
locale: "en_GB.utf8"
localeProvider: builtin
localeCollate: "en_GB.utf8"
localeCType: "en_GB.utf8"
builtinLocale: "en_GB.utf8"
collationVersion: "1"
schemas:
- name: test-schema
owner: test-owner
ensure: absent
extensions:
- name: pg_search
ensure: absent
version: "0.15.21"
schema: test-schema
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
type: postgresql
version:
postgresql: "17"

cluster:
instances: 1

databases:
- name: default_db
ensure: present
owner: test-owner

- name: test-db-icu
ensure: present
owner: test-owner
template: template0
encoding: UTF16
connectionLimit: 100
tablespace: test-space
databaseReclaimPolicy: delete
isTemplate: true
locale: "en_GB.utf8"
localeProvider: icu
localeCollate: "en_GB.utf8"
localeCType: "en_GB.utf8"
icuLocale: "en_GB"
icuRules: "en_GB"
collationVersion: "1"
schemas:
- name: test-schema
owner: test-owner
ensure: absent
extensions:
- name: pg_search
ensure: absent
version: "0.15.21"
schema: test-schema

- name: test-db-builtin
ensure: present
owner: test-owner
template: template0
encoding: UTF16
connectionLimit: 100
tablespace: test-space
databaseReclaimPolicy: delete
isTemplate: true
locale: "en_GB.utf8"
localeProvider: builtin
localeCollate: "en_GB.utf8"
localeCType: "en_GB.utf8"
builtinLocale: "en_GB.utf8"
collationVersion: "1"
schemas:
- name: test-schema
owner: test-owner
ensure: absent
extensions:
- name: pg_search
ensure: absent
version: "0.15.21"
schema: test-schema
31 changes: 31 additions & 0 deletions charts/cluster/test/database-management/chainsaw-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
name: database-management
spec:
timeouts:
apply: 1s
assert: 300s
cleanup: 60s
steps:
- name: database-parameters
timeouts:
apply: 1s
assert: 5s
cleanup: 30s
try:
- script:
content: |
helm upgrade \
--install \
--namespace $NAMESPACE \
--values ./01-database-parameters.yaml \
--wait \
database-parameters ../../
- assert:
file: ./01-database-parameters-assert.yaml
- name: cleanup
try:
- script:
content: |
helm uninstall --namespace $NAMESPACE database-parameters
3 changes: 3 additions & 0 deletions charts/cluster/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@
}
}
},
"databases": {
"type": "array"
},
"fullnameOverride": {
"type": "string"
},
Expand Down
30 changes: 30 additions & 0 deletions charts/cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,36 @@ backups:
# -- Retention policy for backups
retentionPolicy: "30d"

##
# Database management configuration
databases: []
# - name: app # -- Name of the database to be created.
# ensure: present # -- Ensure the PostgreSQL database is present or absent - defaults to "present".
# owner: app # -- Owner of the database, defaults to the value of the `name` key.
# template: template1 # -- Maps to the TEMPLATE parameter.
# encoding: UTF8 # -- Maps to the ENCODING parameter.
# connectionLimit: -1 # -- Maps to the CONNECTION LIMIT parameter. -1 (the default) means no limit.
# tablespace: "" # -- Maps to the TABLESPACE parameter and ALTER DATABASE.
# databaseReclaimPolicy: retain # -- One of: retain / delete (retain by default).
# schemas: [] # -- List of schemas to be created in the database.
# # - name: myschema
# # owner: app # -- Owner of the schema, defaults to the database owner.
# # ensure: present # -- Ensure the PostgreSQL schema is present or absent - defaults to "present".
# extensions: [] # -- List of extensions to be created in the database.
# # - name: pg_search
# # ensure: present # -- Ensure the PostgreSQL extension is present or absent - defaults to "present".
# # version: "0.15.21" # -- Version of the extension to be installed, if not specified the latest version will be used.
# # schema: "" # -- Schema where the extension will be installed, if not specified the extensions or current default object creation schema will be used.
# isTemplate: false # -- Maps to the IS_TEMPLATE parameter. If true, the database is considered a template for new databases.
# locale: "" # -- Maps to the LC_COLLATE and LC_CTYPE parameters
# localeProvider: "" # -- Maps to the LOCALE_PROVIDER parameter. Available from PostgreSQL 16.
# localeCollate: "" # -- Maps to the LC_COLLATE parameter
# localeCType: "" # -- Maps to the LC_CTYPE parameter
# icuLocale: "" # -- Maps to the ICU_LOCALE parameter. Available from PostgreSQL 15.
# icuRules: "" # -- Maps to the ICU_RULES parameter. Available from PostgreSQL 16.
# builtinLocale: "" # -- Maps to the BUILTIN_LOCALE parameter. Available from PostgreSQL 17.
# collationVersion: "" # -- Maps to the COLLATION_VERSION parameter.

imageCatalog:
# -- Whether to provision an image catalog. If imageCatalog.images is empty this option will be ignored.
create: true
Expand Down
Loading