From 213eabe7a20e68dacc70a8ac2899c8237039f54c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=83=D0=BB=D0=B0=D1=82=20=D0=93=D0=B0=D1=84=D1=83?= =?UTF-8?q?=D1=80=D0=BE=D0=B2?= <67165594+paraddise@users.noreply.github.com> Date: Fri, 3 May 2024 18:59:05 +0500 Subject: [PATCH] Added Image Catalog Reference Signed-off-by: Bulat Gafurov <67165594+paraddise@users.noreply.github.com> --- charts/cluster/README.md | 1 + charts/cluster/docs/Getting Started.md | 9 +++++---- charts/cluster/examples/image-catalog.yaml | 10 ++++++++++ charts/cluster/templates/NOTES.txt | 4 ++++ charts/cluster/templates/_helpers.tpl | 16 ++++++++++++++++ charts/cluster/templates/cluster.yaml | 2 +- charts/cluster/values.yaml | 7 +++++++ 7 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 charts/cluster/examples/image-catalog.yaml diff --git a/charts/cluster/README.md b/charts/cluster/README.md index ff59e34ef..c5d7d7340 100644 --- a/charts/cluster/README.md +++ b/charts/cluster/README.md @@ -152,6 +152,7 @@ refer to the [CloudNativePG Documentation](https://cloudnative-pg.io/documentat | cluster.certificates | object | `{}` | The configuration for the CA and related certificates. See: https://cloudnative-pg.io/documentation/current/cloudnative-pg.v1/#postgresql-cnpg-io-v1-CertificatesConfiguration | | cluster.enableSuperuserAccess | bool | `true` | When this option is enabled, the operator will use the SuperuserSecret to update the postgres user password. If the secret is not present, the operator will automatically create one. When this option is disabled, the operator will ignore the SuperuserSecret content, delete it when automatically created, and then blank the password of the postgres user by setting it to NULL. | | cluster.imageName | string | `""` | Name of the container image, supporting both tags (:) and digests for deterministic and repeatable deployments: :@sha256: | +| cluster.imageCatalogRef | object | `{}` | Reference to `ImageCatalog` of `ClusterImageCatalog`, if specified takes precedence over `cluster.imageName` | | cluster.imagePullPolicy | string | `"IfNotPresent"` | Image pull policy. One of Always, Never or IfNotPresent. If not defined, it defaults to IfNotPresent. Cannot be updated. More info: https://kubernetes.io/docs/concepts/containers/images#updating-images | | cluster.imagePullSecrets | list | `[]` | The list of pull secrets to be used to pull the images. See: https://cloudnative-pg.io/documentation/current/cloudnative-pg.v1/#postgresql-cnpg-io-v1-LocalObjectReference | | cluster.initdb | object | `{}` | BootstrapInitDB is the configuration of the bootstrap process when initdb is used. See: https://cloudnative-pg.io/documentation/current/bootstrap/ See: https://cloudnative-pg.io/documentation/current/cloudnative-pg.v1/#postgresql-cnpg-io-v1-bootstrapinitdb | diff --git a/charts/cluster/docs/Getting Started.md b/charts/cluster/docs/Getting Started.md index 54dad419d..4f142e8fe 100644 --- a/charts/cluster/docs/Getting Started.md +++ b/charts/cluster/docs/Getting Started.md @@ -1,6 +1,6 @@ # Getting Started -The CNPG cluster chart follows a convention over configuration approach. This means that the chart will create a reasonable +The CNPG cluster chart follows a convention over configuration approach. This means that the chart will create a reasonable CNPG setup with sensible defaults. However, you can override these defaults to create a more customized setup. Note that you still need to configure backups and monitoring separately. The chart will not install a Prometheus stack for you. @@ -44,7 +44,7 @@ are likely looking for the `standalone` option. ### Backup configuration -Most importantly you should configure your backup storage. +Most importantly you should configure your backup storage. CNPG implements disaster recovery via [Barman](https://pgbarman.org/). The following section configures the barman object store where backups will be stored. Barman performs backups of the cluster filesystem base backup and WALs. Both are @@ -76,10 +76,11 @@ There are several important cluster options. Here are the most important ones: `cluster.instances` - The number of instances in the cluster. Defaults to `1`, but you should set this to `3` for production. `cluster.imageName` - This allows you to override the Docker image used for the cluster. The chart will choose a default - for you based on the setting you chose for `type`. If you need to run a configuration that is not supported, you can + for you based on the setting you chose for `type`. If you need to run a configuration that is not supported, you can create your own Docker image. You can use the [postgres-containers](https://github.com/cloudnative-pg/postgres-containers) repository for a starting point. You will likely need to set your own repository access credentials via: `cluster.imagePullPolicy` and `cluster.imagePullSecrets`. +`cluster.imageCatalogRef` - This allows you to specify version from ImageCatalog or ClusterImageCatalog. If both `cluster.imageName` and `cluster.imageCatalogRef`, later takes precedence. `cluster.storage.size` - The size of the persistent volume claim for the cluster. Defaults to `8Gi`. Every instance will have it's own persistent volume claim. `cluster.storage.storageClass` - The storage class to use for the persistent volume claim. @@ -93,7 +94,7 @@ There are several important cluster options. Here are the most important ones: cluster: postgresql: max_connections: "200" - shared_buffers: "2GB" + shared_buffers: "2GB" ``` `cluster.initSQL` - Allows you to run custom SQL queries during the cluster initialization. This is useful for creating extensions, schemas and databases. Note that these are as a superuser. diff --git a/charts/cluster/examples/image-catalog.yaml b/charts/cluster/examples/image-catalog.yaml new file mode 100644 index 000000000..3201bd33c --- /dev/null +++ b/charts/cluster/examples/image-catalog.yaml @@ -0,0 +1,10 @@ +mode: standalone +cluster: + instances: 1 + imageCatalogRef: + apiGroup: postgresql.cnpg.io + kind: ClusterImageCatalog + name: postgresql + major: 16 +backups: + enabled: false diff --git a/charts/cluster/templates/NOTES.txt b/charts/cluster/templates/NOTES.txt index dd5142ecc..c76b2090f 100644 --- a/charts/cluster/templates/NOTES.txt +++ b/charts/cluster/templates/NOTES.txt @@ -47,7 +47,11 @@ Configuration ┝━━━━━━━━━━━━━━━━━━━┿━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┥ │ Cluster mode │ {{ (printf "%-54s" .Values.mode) }} │ │ Type │ {{ (printf "%-54s" .Values.type) }} │ +{{- if .Values.cluster.imageCatalogRef }} +| Image | {{ include "cluster.color-info" (printf "%-54s" (printf "%s/%s:%v" .Values.cluster.imageCatalogRef.kind .Values.cluster.imageCatalogRef.name .Values.cluster.imageCatalogRef.major)) }} │ +{{- else }} │ Image │ {{ include "cluster.color-info" (printf "%-54s" (include "cluster.imageName" .)) }} │ +{{- end }} │ Instances │ {{ include (printf "%s%s" "cluster.color-" $redundancyColor) (printf "%-54s" (toString .Values.cluster.instances)) }} │ │ Backups │ {{ include (printf "%s%s" "cluster.color-" (ternary "ok" "error" .Values.backups.enabled)) (printf "%-54s" (ternary "Enabled" "Disabled" .Values.backups.enabled)) }} │ │ Backup Provider │ {{ (printf "%-54s" (title .Values.backups.provider)) }} │ diff --git a/charts/cluster/templates/_helpers.tpl b/charts/cluster/templates/_helpers.tpl index db3c253e5..158eaa0bf 100644 --- a/charts/cluster/templates/_helpers.tpl +++ b/charts/cluster/templates/_helpers.tpl @@ -68,3 +68,19 @@ If a custom imageName is available, use it, otherwise use the defaults based on {{ fail "Invalid cluster type!" }} {{- end }} {{- end -}} + +{{/* +Cluster Image +If imageCatalogRef defined, use it, otherwice calculate ordinary imageName. +*/}} +{{- define "cluster.image" }} +{{- if .Values.cluster.imageCatalogRef }} + {{- with .Values.cluster.imageCatalogRef }} +imageCatalogRef: + {{- toYaml . | nindent 2 -}} + {{- end }} +{{- else }} +imageName: {{ include "cluster.imageName" . }} +{{- end }} +{{- end }} + diff --git a/charts/cluster/templates/cluster.yaml b/charts/cluster/templates/cluster.yaml index 5ff0bb2fa..58ac7a763 100644 --- a/charts/cluster/templates/cluster.yaml +++ b/charts/cluster/templates/cluster.yaml @@ -13,7 +13,7 @@ metadata: {{- end }} spec: instances: {{ .Values.cluster.instances }} - imageName: {{ include "cluster.imageName" . }} + {{- include "cluster.image" . | nindent 2 }} imagePullPolicy: {{ .Values.cluster.imagePullPolicy }} {{- with .Values.cluster.imagePullSecrets}} imagePullSecrets: diff --git a/charts/cluster/values.yaml b/charts/cluster/values.yaml index 7dad93eea..272a0995f 100644 --- a/charts/cluster/values.yaml +++ b/charts/cluster/values.yaml @@ -85,6 +85,13 @@ cluster: # :@sha256: imageName: "" # Default value depends on type (postgresql/postgis/timescaledb) + # -- Image Catalog Reference + imageCatalogRef: {} + # apiGroup: postgresql.cnpg.io + # kind: ClusterImageCatalog + # name: postgresql + # major: 16 + # -- Image pull policy. One of Always, Never or IfNotPresent. If not defined, it defaults to IfNotPresent. Cannot be updated. # More info: https://kubernetes.io/docs/concepts/containers/images#updating-images imagePullPolicy: IfNotPresent