From ac0fbb2396344d31808496c6d1cf6b7735a34f3b Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Thu, 30 May 2024 16:34:10 +0300 Subject: [PATCH 01/14] Added support for imageCatalogRef MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Булат Гафуров <67165594+paraddise@users.noreply.github.com> Signed-off-by: Itay Grudev --- charts/cluster/README.md | 1 + .../cluster/examples/image-catalog-ref.yaml | 12 +++++++ charts/cluster/templates/_helpers.tpl | 31 +++++++++++++++++++ charts/cluster/templates/cluster.yaml | 2 +- charts/cluster/values.yaml | 5 +++ 5 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 charts/cluster/examples/image-catalog-ref.yaml diff --git a/charts/cluster/README.md b/charts/cluster/README.md index ff59e34ef..6a2fa2b46 100644 --- a/charts/cluster/README.md +++ b/charts/cluster/README.md @@ -151,6 +151,7 @@ refer to the [CloudNativePG Documentation](https://cloudnative-pg.io/documentat | cluster.annotations | object | `{}` | | | 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.imageCatalogRef | object | `{}` | Reference to `ImageCatalog` of `ClusterImageCatalog`, if specified takes precedence over `cluster.imageName` | | cluster.imageName | string | `""` | Name of the container image, supporting both tags (:) and digests for deterministic and repeatable deployments: :@sha256: | | 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 | diff --git a/charts/cluster/examples/image-catalog-ref.yaml b/charts/cluster/examples/image-catalog-ref.yaml new file mode 100644 index 000000000..55e58e795 --- /dev/null +++ b/charts/cluster/examples/image-catalog-ref.yaml @@ -0,0 +1,12 @@ +type: postgresql +mode: standalone +version: + major: 16 + timescaledb: 2.15 +cluster: + instances: 1 + imageCatalogRef: + kind: ImageCatalog + name: my-image-catalog +backups: + enabled: false diff --git a/charts/cluster/templates/_helpers.tpl b/charts/cluster/templates/_helpers.tpl index db3c253e5..956ea2b48 100644 --- a/charts/cluster/templates/_helpers.tpl +++ b/charts/cluster/templates/_helpers.tpl @@ -68,3 +68,34 @@ 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.name }} +imageCatalogRef: + apiGroup: postgresql.cnpg.io + {{- toYaml .Values.cluster.imageCatalogRef | nindent 2 }} + major: {{ .Values.version.major }} +{{- else if and .Values.imageCatalog.create (not (empty .Values.imageCatalog.images )) }} +imageCatalogRef: + apiGroup: postgresql.cnpg.io + kind: ImageCatalog + name: {{ include "cluster.fullname" . }} + major: {{ .Values.version.major }} +{{- else }} + {{- if empty .Values.cluster.imageName -}} + {{- if and .Values.imageCatalog.create (eq .Values.type "timescaledb") -}} +imageCatalogRef: + apiGroup: postgresql.cnpg.io + kind: ImageCatalog + name: {{ include "cluster.fullname" . }}-timescaledb-ha + major: {{ .Values.version.major }} + {{- end }} + {{- else }} +imageName: {{ include "cluster.imageName" . }} + {{- end }} +{{- end }} +{{- end }} \ No newline at end of file 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 c0c10c512..ac47ac660 100644 --- a/charts/cluster/values.yaml +++ b/charts/cluster/values.yaml @@ -90,6 +90,11 @@ cluster: # :@sha256: imageName: "" # Default value depends on type (postgresql/postgis/timescaledb) + # -- Reference to `ImageCatalog` of `ClusterImageCatalog`, if specified takes precedence over `cluster.imageName` + imageCatalogRef: {} + #kind: ImageCatalog + #name: postgresql + # -- 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 From c0ed873d6732c7cca0b2d1c792c2997deaba62a0 Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Thu, 30 May 2024 16:35:28 +0300 Subject: [PATCH 02/14] Added support for custom ImageCatalog Signed-off-by: Itay Grudev --- charts/cluster/examples/image-catalog.yaml | 14 ++++++++++++++ charts/cluster/templates/image-catalog.yaml | 12 ++++++++++++ charts/cluster/values.yaml | 11 +++++++++++ 3 files changed, 37 insertions(+) create mode 100644 charts/cluster/examples/image-catalog.yaml create mode 100644 charts/cluster/templates/image-catalog.yaml diff --git a/charts/cluster/examples/image-catalog.yaml b/charts/cluster/examples/image-catalog.yaml new file mode 100644 index 000000000..04909130d --- /dev/null +++ b/charts/cluster/examples/image-catalog.yaml @@ -0,0 +1,14 @@ +type: postgresql +mode: standalone +version: + major: 16 + timescaledb: 2.15 +cluster: + instances: 1 +backups: + enabled: false +imageCatalog: + create: true + images: + - major: 16 + image: my-custom-postgres-image:mytag diff --git a/charts/cluster/templates/image-catalog.yaml b/charts/cluster/templates/image-catalog.yaml new file mode 100644 index 000000000..6dc707222 --- /dev/null +++ b/charts/cluster/templates/image-catalog.yaml @@ -0,0 +1,12 @@ +{{ if and .Values.imageCatalog.create (not (empty .Values.imageCatalog.images )) }} +apiVersion: postgresql.cnpg.io/v1 +kind: ImageCatalog +metadata: + name: {{ include "cluster.fullname" . }} +spec: + images: + {{- range $image := .Values.imageCatalog.images }} + - image: {{ $image.image }} + major: {{ $image.major }} + {{- end }} +{{- end }} diff --git a/charts/cluster/values.yaml b/charts/cluster/values.yaml index ac47ac660..a94fe6c36 100644 --- a/charts/cluster/values.yaml +++ b/charts/cluster/values.yaml @@ -9,6 +9,10 @@ fullnameOverride: "" # * `postgis` type: postgresql +version: + # -- PostgreSQL major version to use + major: 16 + ### # -- Cluster mode of operation. Available modes: # * `standalone` - default mode. Creates new or updates an existing CNPG cluster. @@ -287,6 +291,13 @@ backups: # -- Retention policy for backups retentionPolicy: "30d" +imageCatalog: + # -- Whether to provision an image catalog. If imageCatalog.images is empty this option will be ignored. + create: true + # -- List of images to be provisioned in an image catalog. + images: [] + #- image: ghcr.io/your_repo/your_image:your_tag + # major: 16 pooler: # -- Whether to enable PgBouncer From 56be81512b1da6b024389e3c6cd947e8fbee5527 Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Thu, 30 May 2024 16:35:37 +0300 Subject: [PATCH 03/14] Added support for TimescaleDB Signed-off-by: Itay Grudev --- charts/cluster/README.md | 15 ++++-- charts/cluster/examples/timescaledb.yaml | 9 ++++ charts/cluster/templates/NOTES.txt | 39 +++++++++------ charts/cluster/templates/_helpers.tpl | 46 +++++++++++++++-- charts/cluster/templates/cluster.yaml | 6 +-- .../image-catalog-timescaledb-ha.yaml | 18 +++++++ charts/cluster/values.schema.json | 50 +++++++++++++++++++ charts/cluster/values.yaml | 9 +++- 8 files changed, 163 insertions(+), 29 deletions(-) create mode 100644 charts/cluster/examples/timescaledb.yaml create mode 100644 charts/cluster/templates/image-catalog-timescaledb-ha.yaml diff --git a/charts/cluster/README.md b/charts/cluster/README.md index 6a2fa2b46..b67c58ac0 100644 --- a/charts/cluster/README.md +++ b/charts/cluster/README.md @@ -143,6 +143,8 @@ refer to the [CloudNativePG Documentation](https://cloudnative-pg.io/documentat | backups.scheduledBackups[0].method | string | `"barmanObjectStore"` | Backup method, can be `barmanObjectStore` (default) or `volumeSnapshot` | | backups.scheduledBackups[0].name | string | `"daily-backup"` | Scheduled backup name | | backups.scheduledBackups[0].schedule | string | `"0 0 0 * * *"` | Schedule in cron format | +| backups.secret.create | bool | `true` | Whether to create a secret for the backup credentials | +| backups.secret.name | string | `""` | Name of the backup credentials secret | | backups.wal.compression | string | `"gzip"` | WAL compression method. One of `` (for no compression), `gzip`, `bzip2` or `snappy`. | | backups.wal.encryption | string | `"AES256"` | Whether to instruct the storage provider to encrypt WAL files. One of `` (use the storage container default), `AES256` or `aws:kms`. | | backups.wal.maxParallel | int | `1` | Number of WAL files to be archived or restored in parallel. | @@ -163,8 +165,8 @@ refer to the [CloudNativePG Documentation](https://cloudnative-pg.io/documentat | cluster.monitoring.podMonitor.enabled | bool | `true` | Whether to enable the PodMonitor | | cluster.monitoring.prometheusRule.enabled | bool | `true` | Whether to enable the PrometheusRule automated alerts | | cluster.monitoring.prometheusRule.excludeRules | list | `[]` | Exclude specified rules | -| cluster.postgresGID | int | `26` | The GID of the postgres user inside the image, defaults to 26 | -| cluster.postgresUID | int | `26` | The UID of the postgres user inside the image, defaults to 26 | +| cluster.postgresGID | int | `-1` | The GID of the postgres user inside the image, defaults to 26 | +| cluster.postgresUID | int | `-1` | The UID of the postgres user inside the image, defaults to 26 | | cluster.postgresql | object | `{}` | Configuration of the PostgreSQL server. See: https://cloudnative-pg.io/documentation/current/cloudnative-pg.v1/#postgresql-cnpg-io-v1-PostgresConfiguration | | cluster.primaryUpdateMethod | string | `"switchover"` | Method to follow to upgrade the primary server during a rolling update procedure, after all replicas have been successfully updated. It can be switchover (default) or in-place (restart). | | cluster.primaryUpdateStrategy | string | `"unsupervised"` | Strategy to follow to upgrade the primary server during a rolling update procedure, after all replicas have been successfully updated: it can be automated (unsupervised - default) or manual (supervised) | @@ -175,6 +177,8 @@ refer to the [CloudNativePG Documentation](https://cloudnative-pg.io/documentat | cluster.storage.storageClass | string | `""` | | | cluster.superuserSecret | string | `""` | | | 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. | | mode | string | `"standalone"` | Cluster mode of operation. Available modes: * `standalone` - default mode. Creates new or updates an existing CNPG cluster. * `replica` - Creates a replica cluster from an existing CNPG cluster. # TODO * `recovery` - Same as standalone but creates a cluster from a backup, object store or via pg_basebackup. | | nameOverride | string | `""` | Override the name of the chart | | pooler.enabled | bool | `false` | Whether to enable PgBouncer | @@ -211,7 +215,12 @@ refer to the [CloudNativePG Documentation](https://cloudnative-pg.io/documentat | recovery.s3.path | string | `"/"` | | | recovery.s3.region | string | `""` | | | recovery.s3.secretKey | string | `""` | | -| type | string | `"postgresql"` | Type of the CNPG database. Available types: * `postgresql` * `postgis` | +| recovery.secret.create | bool | `true` | Whether to create a secret for the backup credentials | +| recovery.secret.name | string | `""` | Name of the backup credentials secret | +| type | string | `"postgresql"` | Type of the CNPG database. Available types: * `postgresql` * `postgis` * `timescaledb` | +| version.major | int | `16` | PostgreSQL major version to use | +| version.postgis | float | `3.4` | If using PostGIS, specify the version | +| version.timescaledb | float | `2.15` | If using TimescaleDB, specify the version | ## Maintainers diff --git a/charts/cluster/examples/timescaledb.yaml b/charts/cluster/examples/timescaledb.yaml new file mode 100644 index 000000000..be891e489 --- /dev/null +++ b/charts/cluster/examples/timescaledb.yaml @@ -0,0 +1,9 @@ +type: timescaledb +mode: standalone +version: + major: 15 + timescaledb: 2.15 +cluster: + instances: 1 +backups: + enabled: false diff --git a/charts/cluster/templates/NOTES.txt b/charts/cluster/templates/NOTES.txt index dd5142ecc..e8ec29d2c 100644 --- a/charts/cluster/templates/NOTES.txt +++ b/charts/cluster/templates/NOTES.txt @@ -37,26 +37,33 @@ Configuration {{- $redundancyColor = "ok" -}} {{- end }} -{{ $scheduledBackups := (first .Values.backups.scheduledBackups).name }} +{{- $scheduledBackups := (first .Values.backups.scheduledBackups).name -}} {{- range (rest .Values.backups.scheduledBackups) -}} {{ $scheduledBackups = printf "%s, %s" $scheduledBackups .name }} {{- end -}} -╭───────────────────┬────────────────────────────────────────────────────────╮ -│ Configuration │ Value │ -┝━━━━━━━━━━━━━━━━━━━┿━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┥ -│ Cluster mode │ {{ (printf "%-54s" .Values.mode) }} │ -│ Type │ {{ (printf "%-54s" .Values.type) }} │ -│ Image │ {{ include "cluster.color-info" (printf "%-54s" (include "cluster.imageName" .)) }} │ -│ 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)) }} │ -│ Scheduled Backups │ {{ (printf "%-54s" $scheduledBackups) }} │ -│ Storage │ {{ (printf "%-54s" .Values.cluster.storage.size) }} │ -│ Storage Class │ {{ (printf "%-54s" (default "Default" .Values.cluster.storage.storageClass)) }} │ -│ PGBouncer │ {{ (printf "%-54s" (ternary "Enabled" "Disabled" .Values.pooler.enabled)) }} │ -│ Monitoring │ {{ include (printf "%s%s" "cluster.color-" (ternary "ok" "error" .Values.cluster.monitoring.enabled)) (printf "%-54s" (ternary "Enabled" "Disabled" .Values.cluster.monitoring.enabled)) }} │ -╰───────────────────┴────────────────────────────────────────────────────────╯ +{{- $image := (include "cluster.image" .) | fromYaml -}} +{{- if $image.imageCatalogRef -}} + {{- $image = printf "%s: %s(%d)" $image.imageCatalogRef.kind $image.imageCatalogRef.name (int .Values.version.major) -}} +{{- else if $image.imageName -}} + {{- $image = $image.imageName -}} +{{- end }} + +╭───────────────────┬──────────────────────────────────────────────────────────╮ +│ Configuration │ Value │ +┝━━━━━━━━━━━━━━━━━━━┿━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┥ +│ Cluster mode │ {{ (printf "%-56s" .Values.mode) }} │ +│ Type │ {{ (printf "%-56s" .Values.type) }} │ +│ Image │ {{ include "cluster.color-info" (printf "%-56s" $image) }} │ +│ Instances │ {{ include (printf "%s%s" "cluster.color-" $redundancyColor) (printf "%-56s" (toString .Values.cluster.instances)) }} │ +│ Backups │ {{ include (printf "%s%s" "cluster.color-" (ternary "ok" "error" .Values.backups.enabled)) (printf "%-56s" (ternary "Enabled" "Disabled" .Values.backups.enabled)) }} │ +│ Backup Provider │ {{ (printf "%-56s" (title .Values.backups.provider)) }} │ +│ Scheduled Backups │ {{ (printf "%-56s" $scheduledBackups) }} │ +│ Storage │ {{ (printf "%-56s" .Values.cluster.storage.size) }} │ +│ Storage Class │ {{ (printf "%-56s" (default "Default" .Values.cluster.storage.storageClass)) }} │ +│ PGBouncer │ {{ (printf "%-56s" (ternary "Enabled" "Disabled" .Values.pooler.enabled)) }} │ +│ Monitoring │ {{ include (printf "%s%s" "cluster.color-" (ternary "ok" "error" .Values.cluster.monitoring.enabled)) (printf "%-56s" (ternary "Enabled" "Disabled" .Values.cluster.monitoring.enabled)) }} │ +╰───────────────────┴──────────────────────────────────────────────────────────╯ {{ if not .Values.backups.enabled }} {{- include "cluster.color-error" "Warning! Backups not enabled. Recovery will not be possible! Do not use this configuration in production.\n" }} diff --git a/charts/cluster/templates/_helpers.tpl b/charts/cluster/templates/_helpers.tpl index 956ea2b48..9cae65965 100644 --- a/charts/cluster/templates/_helpers.tpl +++ b/charts/cluster/templates/_helpers.tpl @@ -51,6 +51,18 @@ app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/part-of: cloudnative-pg {{- end }} +{{/* +Whether we need to use TimescaleDB defualts +*/}} +{{- define "cluster.useTimescaleDBDefaults" -}} +{{- and (eq .Values.type "timescaledb") + .Values.imageCatalog.create + (not .Values.cluster.imageCatalogRef.name) + (empty .Values.imageCatalog.images) + (eq ((include "cluster.image" . | fromYaml).imageCatalogRef).name (printf "%s-timescaledb-ha" (include "cluster.fullname" .))) +-}} +{{- end -}} + {{/* Cluster Image Name If a custom imageName is available, use it, otherwise use the defaults based on the .Values.type @@ -59,11 +71,9 @@ If a custom imageName is available, use it, otherwise use the defaults based on {{- if .Values.cluster.imageName -}} {{- .Values.cluster.imageName -}} {{- else if eq .Values.type "postgresql" -}} - {{- "ghcr.io/cloudnative-pg/postgresql:15.2" -}} + {{- printf "ghcr.io/cloudnative-pg/postgresql:%s" .Values.version.major -}} {{- else if eq .Values.type "postgis" -}} - {{- "ghcr.io/cloudnative-pg/postgis:14" -}} - {{- else if eq .Values.type "timescaledb" -}} - {{ fail "You need to provide your own cluster.imageName as an official timescaledb image doesn't exist yet." }} + {{- printf "ghcr.io/cloudnative-pg/postgis:%s-%s" .Values.version.major .Values.version.postgis -}} {{- else -}} {{ fail "Invalid cluster type!" }} {{- end }} @@ -98,4 +108,30 @@ imageCatalogRef: imageName: {{ include "cluster.imageName" . }} {{- end }} {{- end }} -{{- end }} \ No newline at end of file +{{- end }} + +{{/* +Postgres UID +*/}} +{{- define "cluster.postgresUID" -}} + {{- if ge (int .Values.cluster.postgresUID) 0 -}} + {{- .Values.cluster.postgresUID }} + {{- else if and (eq (include "cluster.useTimescaleDBDefaults" .) "true") (eq .Values.type "timescaledb") -}} + {{- 1000 -}} + {{- else -}} + {{- 26 -}} + {{- end -}} +{{- end -}} + +{{/* +Postgres GID +*/}} +{{- define "cluster.postgresGID" -}} + {{- if ge (int .Values.cluster.postgresGID) 0 -}} + {{- .Values.cluster.postgresGID }} + {{- else if and (eq (include "cluster.useTimescaleDBDefaults" .) "true") (eq .Values.type "timescaledb") -}} + {{- 1000 -}} + {{- else -}} + {{- 26 -}} + {{- end -}} +{{- end -}} diff --git a/charts/cluster/templates/cluster.yaml b/charts/cluster/templates/cluster.yaml index 58ac7a763..7a458f228 100644 --- a/charts/cluster/templates/cluster.yaml +++ b/charts/cluster/templates/cluster.yaml @@ -15,12 +15,12 @@ spec: instances: {{ .Values.cluster.instances }} {{- include "cluster.image" . | nindent 2 }} imagePullPolicy: {{ .Values.cluster.imagePullPolicy }} - {{- with .Values.cluster.imagePullSecrets}} + {{- with .Values.cluster.imagePullSecrets }} imagePullSecrets: {{- . | toYaml | nindent 4 }} {{- end }} - postgresUID: {{ .Values.cluster.postgresUID }} - postgresGID: {{ .Values.cluster.postgresGID }} + postgresUID: {{ include "cluster.postgresUID" . }} + postgresGID: {{ include "cluster.postgresGID" . }} storage: size: {{ .Values.cluster.storage.size }} storageClass: {{ .Values.cluster.storage.storageClass }} diff --git a/charts/cluster/templates/image-catalog-timescaledb-ha.yaml b/charts/cluster/templates/image-catalog-timescaledb-ha.yaml new file mode 100644 index 000000000..d1cb46661 --- /dev/null +++ b/charts/cluster/templates/image-catalog-timescaledb-ha.yaml @@ -0,0 +1,18 @@ +{{- if and .Values.imageCatalog.create (not .Values.imageCatalog.images) (not .Values.cluster.imageCatalogRef.name) (eq .Values.type "timescaledb") -}} +apiVersion: postgresql.cnpg.io/v1 +kind: ImageCatalog +metadata: + name: {{ include "cluster.fullname" . }}-timescaledb-ha +spec: + images: + - major: 12 + image: timescale/timescaledb-ha:pg15-ts{{ .Values.version.timescaledb }} + - major: 13 + image: timescale/timescaledb-ha:pg15-ts{{ .Values.version.timescaledb }} + - major: 14 + image: timescale/timescaledb-ha:pg15-ts{{ .Values.version.timescaledb }} + - major: 15 + image: timescale/timescaledb-ha:pg15-ts{{ .Values.version.timescaledb }} + - major: 16 + image: timescale/timescaledb-ha:pg16-ts{{ .Values.version.timescaledb }} +{{ end }} diff --git a/charts/cluster/values.schema.json b/charts/cluster/values.schema.json index 46c874b1d..745a4dc29 100644 --- a/charts/cluster/values.schema.json +++ b/charts/cluster/values.schema.json @@ -137,6 +137,17 @@ } } }, + "secret": { + "type": "object", + "properties": { + "create": { + "type": "boolean" + }, + "name": { + "type": "string" + } + } + }, "wal": { "type": "object", "properties": { @@ -176,6 +187,9 @@ "enableSuperuserAccess": { "type": "boolean" }, + "imageCatalogRef": { + "type": "object" + }, "imageName": { "type": "string" }, @@ -267,6 +281,17 @@ "fullnameOverride": { "type": "string" }, + "imageCatalog": { + "type": "object", + "properties": { + "create": { + "type": "boolean" + }, + "images": { + "type": "array" + } + } + }, "mode": { "type": "string" }, @@ -431,11 +456,36 @@ "type": "string" } } + }, + "secret": { + "type": "object", + "properties": { + "create": { + "type": "boolean" + }, + "name": { + "type": "string" + } + } } } }, "type": { "type": "string" + }, + "version": { + "type": "object", + "properties": { + "major": { + "type": "integer" + }, + "postgis": { + "type": "number" + }, + "timescaledb": { + "type": "number" + } + } } } } diff --git a/charts/cluster/values.yaml b/charts/cluster/values.yaml index a94fe6c36..6043526ca 100644 --- a/charts/cluster/values.yaml +++ b/charts/cluster/values.yaml @@ -7,11 +7,16 @@ fullnameOverride: "" # -- Type of the CNPG database. Available types: # * `postgresql` # * `postgis` +# * `timescaledb` type: postgresql version: # -- PostgreSQL major version to use major: 16 + # -- If using TimescaleDB, specify the version + timescaledb: 2.15 + # -- If using PostGIS, specify the version + postgis: 3.4 ### # -- Cluster mode of operation. Available modes: @@ -112,10 +117,10 @@ cluster: storageClass: "" # -- The UID of the postgres user inside the image, defaults to 26 - postgresUID: 26 + postgresUID: -1 # -- The GID of the postgres user inside the image, defaults to 26 - postgresGID: 26 + postgresGID: -1 # -- Resources requirements of every generated Pod. # Please refer to https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ for more information. From 1bfc4ea2d8d33c04114f1f3babf5ec91080f644f Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Thu, 30 May 2024 16:43:17 +0300 Subject: [PATCH 04/14] Corrected lint issues Signed-off-by: Itay Grudev --- charts/cluster/values.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/charts/cluster/values.yaml b/charts/cluster/values.yaml index 6043526ca..24af6069d 100644 --- a/charts/cluster/values.yaml +++ b/charts/cluster/values.yaml @@ -101,8 +101,8 @@ cluster: # -- Reference to `ImageCatalog` of `ClusterImageCatalog`, if specified takes precedence over `cluster.imageName` imageCatalogRef: {} - #kind: ImageCatalog - #name: postgresql + # kind: ImageCatalog + # name: postgresql # -- 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 @@ -301,8 +301,8 @@ imageCatalog: create: true # -- List of images to be provisioned in an image catalog. images: [] - #- image: ghcr.io/your_repo/your_image:your_tag - # major: 16 + # - image: ghcr.io/your_repo/your_image:your_tag + # major: 16 pooler: # -- Whether to enable PgBouncer From ed7994ab596b488e82c4e7247b145deee57bc100 Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Thu, 30 May 2024 21:16:12 +0300 Subject: [PATCH 05/14] Alternative postgresql version approach allowing for minor version in the specs Signed-off-by: Itay Grudev --- charts/cluster/README.md | 6 ++-- charts/cluster/examples/timescaledb.yaml | 4 +-- charts/cluster/templates/NOTES.txt | 2 +- charts/cluster/templates/_helpers.tpl | 32 +++++++++---------- .../image-catalog-timescaledb-ha.yaml | 2 +- charts/cluster/values.schema.json | 10 +++--- charts/cluster/values.yaml | 6 ++-- 7 files changed, 30 insertions(+), 32 deletions(-) diff --git a/charts/cluster/README.md b/charts/cluster/README.md index 76af259a3..187677928 100644 --- a/charts/cluster/README.md +++ b/charts/cluster/README.md @@ -218,9 +218,9 @@ refer to the [CloudNativePG Documentation](https://cloudnative-pg.io/documentat | recovery.secret.create | bool | `true` | Whether to create a secret for the backup credentials | | recovery.secret.name | string | `""` | Name of the backup credentials secret | | type | string | `"postgresql"` | Type of the CNPG database. Available types: * `postgresql` * `postgis` * `timescaledb` | -| version.major | int | `16` | PostgreSQL major version to use | -| version.postgis | float | `3.4` | If using PostGIS, specify the version | -| version.timescaledb | float | `2.15` | If using TimescaleDB, specify the version | +| version.postgis | string | `"3.4"` | If using PostGIS, specify the version | +| version.postgresql | string | `"16"` | PostgreSQL major version to use | +| version.timescaledb | string | `"2.15"` | If using TimescaleDB, specify the version | ## Maintainers diff --git a/charts/cluster/examples/timescaledb.yaml b/charts/cluster/examples/timescaledb.yaml index be891e489..328b6c1eb 100644 --- a/charts/cluster/examples/timescaledb.yaml +++ b/charts/cluster/examples/timescaledb.yaml @@ -1,8 +1,8 @@ type: timescaledb mode: standalone version: - major: 15 - timescaledb: 2.15 + postgresql: "15.7" + timescaledb: "2.15" cluster: instances: 1 backups: diff --git a/charts/cluster/templates/NOTES.txt b/charts/cluster/templates/NOTES.txt index e8ec29d2c..c23563cef 100644 --- a/charts/cluster/templates/NOTES.txt +++ b/charts/cluster/templates/NOTES.txt @@ -44,7 +44,7 @@ Configuration {{- $image := (include "cluster.image" .) | fromYaml -}} {{- if $image.imageCatalogRef -}} - {{- $image = printf "%s: %s(%d)" $image.imageCatalogRef.kind $image.imageCatalogRef.name (int .Values.version.major) -}} + {{- $image = printf "%s: %s(%s)" $image.imageCatalogRef.kind $image.imageCatalogRef.name (include "cluster.postgresqlMajor" .) -}} {{- else if $image.imageName -}} {{- $image = $image.imageName -}} {{- end }} diff --git a/charts/cluster/templates/_helpers.tpl b/charts/cluster/templates/_helpers.tpl index 9cae65965..0bfa47fa5 100644 --- a/charts/cluster/templates/_helpers.tpl +++ b/charts/cluster/templates/_helpers.tpl @@ -55,12 +55,14 @@ app.kubernetes.io/part-of: cloudnative-pg Whether we need to use TimescaleDB defualts */}} {{- define "cluster.useTimescaleDBDefaults" -}} -{{- and (eq .Values.type "timescaledb") - .Values.imageCatalog.create - (not .Values.cluster.imageCatalogRef.name) - (empty .Values.imageCatalog.images) - (eq ((include "cluster.image" . | fromYaml).imageCatalogRef).name (printf "%s-timescaledb-ha" (include "cluster.fullname" .))) --}} +{{ and (eq .Values.type "timescaledb") .Values.imageCatalog.create (empty .Values.cluster.imageCatalogRef.name) (empty .Values.imageCatalog.images) (empty .Values.cluster.imageName) }} +{{- end -}} + +{{/* +Get the PostgreSQL major version from .Values.version.postgresql +*/}} +{{- define "cluster.postgresqlMajor" -}} +{{ index (regexSplit "\\." (toString .Values.version.postgresql) 2) 0 }} {{- end -}} {{/* @@ -71,9 +73,9 @@ If a custom imageName is available, use it, otherwise use the defaults based on {{- if .Values.cluster.imageName -}} {{- .Values.cluster.imageName -}} {{- else if eq .Values.type "postgresql" -}} - {{- printf "ghcr.io/cloudnative-pg/postgresql:%s" .Values.version.major -}} + {{- printf "ghcr.io/cloudnative-pg/postgresql:%s" .Values.version.postgresql -}} {{- else if eq .Values.type "postgis" -}} - {{- printf "ghcr.io/cloudnative-pg/postgis:%s-%s" .Values.version.major .Values.version.postgis -}} + {{- printf "ghcr.io/cloudnative-pg/postgis:%s-%s" .Values.version.postgresql .Values.version.postgis -}} {{- else -}} {{ fail "Invalid cluster type!" }} {{- end }} @@ -88,25 +90,21 @@ If imageCatalogRef defined, use it, otherwice calculate ordinary imageName. imageCatalogRef: apiGroup: postgresql.cnpg.io {{- toYaml .Values.cluster.imageCatalogRef | nindent 2 }} - major: {{ .Values.version.major }} + major: {{ include "cluster.postgresqlMajor" . }} {{- else if and .Values.imageCatalog.create (not (empty .Values.imageCatalog.images )) }} imageCatalogRef: apiGroup: postgresql.cnpg.io kind: ImageCatalog name: {{ include "cluster.fullname" . }} - major: {{ .Values.version.major }} -{{- else }} - {{- if empty .Values.cluster.imageName -}} - {{- if and .Values.imageCatalog.create (eq .Values.type "timescaledb") -}} + major: {{ include "cluster.postgresqlMajor" . }} +{{- else if eq (include "cluster.useTimescaleDBDefaults" .) "true" -}} imageCatalogRef: apiGroup: postgresql.cnpg.io kind: ImageCatalog name: {{ include "cluster.fullname" . }}-timescaledb-ha - major: {{ .Values.version.major }} - {{- end }} - {{- else }} + major: {{ include "cluster.postgresqlMajor" . }} +{{- else }} imageName: {{ include "cluster.imageName" . }} - {{- end }} {{- end }} {{- end }} diff --git a/charts/cluster/templates/image-catalog-timescaledb-ha.yaml b/charts/cluster/templates/image-catalog-timescaledb-ha.yaml index d1cb46661..d611171e1 100644 --- a/charts/cluster/templates/image-catalog-timescaledb-ha.yaml +++ b/charts/cluster/templates/image-catalog-timescaledb-ha.yaml @@ -1,4 +1,4 @@ -{{- if and .Values.imageCatalog.create (not .Values.imageCatalog.images) (not .Values.cluster.imageCatalogRef.name) (eq .Values.type "timescaledb") -}} +{{- if eq (include "cluster.useTimescaleDBDefaults" .) "true" -}} apiVersion: postgresql.cnpg.io/v1 kind: ImageCatalog metadata: diff --git a/charts/cluster/values.schema.json b/charts/cluster/values.schema.json index 745a4dc29..7a5547000 100644 --- a/charts/cluster/values.schema.json +++ b/charts/cluster/values.schema.json @@ -476,14 +476,14 @@ "version": { "type": "object", "properties": { - "major": { - "type": "integer" - }, "postgis": { - "type": "number" + "type": "string" + }, + "postgresql": { + "type": "string" }, "timescaledb": { - "type": "number" + "type": "string" } } } diff --git a/charts/cluster/values.yaml b/charts/cluster/values.yaml index 24af6069d..337bbe107 100644 --- a/charts/cluster/values.yaml +++ b/charts/cluster/values.yaml @@ -12,11 +12,11 @@ type: postgresql version: # -- PostgreSQL major version to use - major: 16 + postgresql: "16" # -- If using TimescaleDB, specify the version - timescaledb: 2.15 + timescaledb: "2.15" # -- If using PostGIS, specify the version - postgis: 3.4 + postgis: "3.4" ### # -- Cluster mode of operation. Available modes: From 141926245fd4bbb7d21615253cbf6e2dfe846109 Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Thu, 30 May 2024 21:40:52 +0300 Subject: [PATCH 06/14] Added versions to relevant examples Signed-off-by: Itay Grudev --- charts/cluster/examples/basic.yaml | 2 ++ charts/cluster/examples/image-catalog-ref.yaml | 4 ++-- charts/cluster/examples/image-catalog.yaml | 4 ++-- charts/cluster/examples/postgis.yaml | 5 ++++- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/charts/cluster/examples/basic.yaml b/charts/cluster/examples/basic.yaml index 5b608c267..730612c2f 100644 --- a/charts/cluster/examples/basic.yaml +++ b/charts/cluster/examples/basic.yaml @@ -1,4 +1,6 @@ mode: standalone +version: + postgresql: "16" cluster: instances: 1 backups: diff --git a/charts/cluster/examples/image-catalog-ref.yaml b/charts/cluster/examples/image-catalog-ref.yaml index 55e58e795..e4833a3b6 100644 --- a/charts/cluster/examples/image-catalog-ref.yaml +++ b/charts/cluster/examples/image-catalog-ref.yaml @@ -1,8 +1,8 @@ type: postgresql mode: standalone version: - major: 16 - timescaledb: 2.15 + major: "16" + timescaledb: "2.15" cluster: instances: 1 imageCatalogRef: diff --git a/charts/cluster/examples/image-catalog.yaml b/charts/cluster/examples/image-catalog.yaml index 04909130d..c610229b0 100644 --- a/charts/cluster/examples/image-catalog.yaml +++ b/charts/cluster/examples/image-catalog.yaml @@ -1,8 +1,8 @@ type: postgresql mode: standalone version: - major: 16 - timescaledb: 2.15 + major: "16" + timescaledb: "2.15" cluster: instances: 1 backups: diff --git a/charts/cluster/examples/postgis.yaml b/charts/cluster/examples/postgis.yaml index 6c686dc62..168ac9fbf 100644 --- a/charts/cluster/examples/postgis.yaml +++ b/charts/cluster/examples/postgis.yaml @@ -1,6 +1,9 @@ type: postgis mode: standalone +version: + postgresql: "16" + postgis: "3.4" cluster: instances: 1 backups: - enabled: false \ No newline at end of file + enabled: false From 9ce2833d66a4138fa281381e3da4f6bfbdff64d1 Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Wed, 3 Jul 2024 16:50:41 +0300 Subject: [PATCH 07/14] lint: removed trailing spaces after merge commit Signed-off-by: Itay Grudev --- charts/cluster/values.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/cluster/values.yaml b/charts/cluster/values.yaml index 9306a06d1..6b88229ba 100644 --- a/charts/cluster/values.yaml +++ b/charts/cluster/values.yaml @@ -115,7 +115,7 @@ cluster: storage: size: 8Gi storageClass: "" - + walStorage: size: 1Gi storageClass: "" From d080597ca109f0dce66bac1a2a1666b8aa39cfab Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Wed, 4 Sep 2024 10:23:26 +0300 Subject: [PATCH 08/14] Update charts/cluster/templates/_helpers.tpl Co-authored-by: Philippe Scorsolini Signed-off-by: Itay Grudev --- charts/cluster/templates/_helpers.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/cluster/templates/_helpers.tpl b/charts/cluster/templates/_helpers.tpl index 0bfa47fa5..96726fdfe 100644 --- a/charts/cluster/templates/_helpers.tpl +++ b/charts/cluster/templates/_helpers.tpl @@ -52,7 +52,7 @@ app.kubernetes.io/part-of: cloudnative-pg {{- end }} {{/* -Whether we need to use TimescaleDB defualts +Whether we need to use TimescaleDB defaults */}} {{- define "cluster.useTimescaleDBDefaults" -}} {{ and (eq .Values.type "timescaledb") .Values.imageCatalog.create (empty .Values.cluster.imageCatalogRef.name) (empty .Values.imageCatalog.images) (empty .Values.cluster.imageName) }} From 3dffac6e4ad8806fe5b987ff99f3edd2112a6498 Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Sat, 7 Sep 2024 19:36:19 +0300 Subject: [PATCH 09/14] Separated backup paths within the MinIO bucket Signed-off-by: Itay Grudev --- .../postgresql-minio-backup-restore/00-minio_cleanup.yaml | 2 +- .../01-standalone_cluster.yaml | 2 +- .../04-post_backup_data_write.yaml | 2 +- .../05-recovery_backup_cluster.yaml | 4 ++-- .../07-recovery_object_store_cluster.yaml | 4 ++-- .../09-recovery_backup_pitr_cluster.yaml | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/charts/cluster/test/postgresql-minio-backup-restore/00-minio_cleanup.yaml b/charts/cluster/test/postgresql-minio-backup-restore/00-minio_cleanup.yaml index 3c06f4159..97cfc7389 100644 --- a/charts/cluster/test/postgresql-minio-backup-restore/00-minio_cleanup.yaml +++ b/charts/cluster/test/postgresql-minio-backup-restore/00-minio_cleanup.yaml @@ -13,4 +13,4 @@ spec: args: - | mc alias set myminio https://minio.minio.svc.cluster.local minio minio123 - mc rm --recursive --force myminio/mybucket + mc rm --recursive --force myminio/mybucket/postgresql-minio-backup-restore diff --git a/charts/cluster/test/postgresql-minio-backup-restore/01-standalone_cluster.yaml b/charts/cluster/test/postgresql-minio-backup-restore/01-standalone_cluster.yaml index efebd75ec..d55832170 100644 --- a/charts/cluster/test/postgresql-minio-backup-restore/01-standalone_cluster.yaml +++ b/charts/cluster/test/postgresql-minio-backup-restore/01-standalone_cluster.yaml @@ -18,7 +18,7 @@ backups: encryption: "" s3: bucket: "mybucket" - path: "/v1" + path: "/postgresql-minio-backup-restore/v1" accessKey: "minio" secretKey: "minio123" region: "local" diff --git a/charts/cluster/test/postgresql-minio-backup-restore/04-post_backup_data_write.yaml b/charts/cluster/test/postgresql-minio-backup-restore/04-post_backup_data_write.yaml index 0571dbdd6..2e56595de 100644 --- a/charts/cluster/test/postgresql-minio-backup-restore/04-post_backup_data_write.yaml +++ b/charts/cluster/test/postgresql-minio-backup-restore/04-post_backup_data_write.yaml @@ -49,7 +49,7 @@ spec: command: ['sh', '-c'] args: - | - apk --no-cache add postgresql-client kubectl + apk --no-cache add postgresql-client kubectl coreutils DB_URI=$(echo $DB_URI | sed "s|/\*|/|" ) DATE_NO_BAD_TABLE=$(date --rfc-3339=ns) sleep 30 diff --git a/charts/cluster/test/postgresql-minio-backup-restore/05-recovery_backup_cluster.yaml b/charts/cluster/test/postgresql-minio-backup-restore/05-recovery_backup_cluster.yaml index 7279e1e81..449e524f8 100644 --- a/charts/cluster/test/postgresql-minio-backup-restore/05-recovery_backup_cluster.yaml +++ b/charts/cluster/test/postgresql-minio-backup-restore/05-recovery_backup_cluster.yaml @@ -19,7 +19,7 @@ recovery: encryption: "" s3: bucket: "mybucket" - path: "/v1" + path: "/postgresql-minio-backup-restore/v1" accessKey: "minio" secretKey: "minio123" region: "local" @@ -39,7 +39,7 @@ backups: encryption: "" s3: bucket: "mybucket" - path: "/v1" + path: "/postgresql-minio-backup-restore/v2" accessKey: "minio" secretKey: "minio123" region: "local" diff --git a/charts/cluster/test/postgresql-minio-backup-restore/07-recovery_object_store_cluster.yaml b/charts/cluster/test/postgresql-minio-backup-restore/07-recovery_object_store_cluster.yaml index d6dafdc64..230d5ba1d 100644 --- a/charts/cluster/test/postgresql-minio-backup-restore/07-recovery_object_store_cluster.yaml +++ b/charts/cluster/test/postgresql-minio-backup-restore/07-recovery_object_store_cluster.yaml @@ -19,7 +19,7 @@ recovery: encryption: "" s3: bucket: "mybucket" - path: "/v1" + path: "/postgresql-minio-backup-restore/v1" accessKey: "minio" secretKey: "minio123" region: "local" @@ -39,7 +39,7 @@ backups: encryption: "" s3: bucket: "mybucket" - path: "/v1" + path: "/postgresql-minio-backup-restore/v2" accessKey: "minio" secretKey: "minio123" region: "local" diff --git a/charts/cluster/test/postgresql-minio-backup-restore/09-recovery_backup_pitr_cluster.yaml b/charts/cluster/test/postgresql-minio-backup-restore/09-recovery_backup_pitr_cluster.yaml index 3fa2bbd03..449e524f8 100644 --- a/charts/cluster/test/postgresql-minio-backup-restore/09-recovery_backup_pitr_cluster.yaml +++ b/charts/cluster/test/postgresql-minio-backup-restore/09-recovery_backup_pitr_cluster.yaml @@ -19,7 +19,7 @@ recovery: encryption: "" s3: bucket: "mybucket" - path: "/v1" + path: "/postgresql-minio-backup-restore/v1" accessKey: "minio" secretKey: "minio123" region: "local" @@ -39,7 +39,7 @@ backups: encryption: "" s3: bucket: "mybucket" - path: "/v2" + path: "/postgresql-minio-backup-restore/v2" accessKey: "minio" secretKey: "minio123" region: "local" From ad73d24036e712af840deb278096218d3e16c7a0 Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Sun, 8 Sep 2024 16:57:07 +0300 Subject: [PATCH 10/14] Removed kubectl from a test steps that don't use it Signed-off-by: Itay Grudev --- .../test/postgresql-minio-backup-restore/02-data_write.yaml | 2 +- charts/cluster/test/postgresql-pg_basebackup/01-data_write.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/cluster/test/postgresql-minio-backup-restore/02-data_write.yaml b/charts/cluster/test/postgresql-minio-backup-restore/02-data_write.yaml index 8e231df66..e674d8b53 100644 --- a/charts/cluster/test/postgresql-minio-backup-restore/02-data_write.yaml +++ b/charts/cluster/test/postgresql-minio-backup-restore/02-data_write.yaml @@ -18,6 +18,6 @@ spec: command: ['sh', '-c'] args: - | - apk --no-cache add postgresql-client kubectl + apk --no-cache add postgresql-client DB_URI=$(echo $DB_URI | sed "s|/\*|/|" ) psql "$DB_URI" -c "CREATE TABLE mygoodtable (id serial PRIMARY KEY);" diff --git a/charts/cluster/test/postgresql-pg_basebackup/01-data_write.yaml b/charts/cluster/test/postgresql-pg_basebackup/01-data_write.yaml index fc5f0c8c9..cc5a743ad 100644 --- a/charts/cluster/test/postgresql-pg_basebackup/01-data_write.yaml +++ b/charts/cluster/test/postgresql-pg_basebackup/01-data_write.yaml @@ -25,6 +25,6 @@ spec: command: ['sh', '-c'] args: - | - apk --no-cache add postgresql-client kubectl + apk --no-cache add postgresql-client psql "$DB_URI" -c "CREATE DATABASE mygooddb;" psql "$DB_URI/mygooddb" -c "CREATE TABLE mygoodtable (id serial PRIMARY KEY);" From 711baec5d833a6443a8a4cb841126e83a960ddc4 Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Sun, 8 Sep 2024 17:08:12 +0300 Subject: [PATCH 11/14] Added a TimescaleDB test suite to the chart Signed-off-by: Itay Grudev --- .../00-minio_cleanup-assert.yaml | 6 + .../00-minio_cleanup.yaml | 16 +++ .../01-timescale_cluster-assert.yaml | 6 + .../01-timescale_cluster.yaml | 26 ++++ .../03-timescale_test-assert.yaml | 6 + .../03-timescale_test.yaml | 22 ++++ .../04-data_write-assert.yaml | 6 + .../04-data_write.yaml | 23 ++++ .../05-backup.yaml | 8 ++ .../05-backup_completed-assert.yaml | 10 ++ .../05-backup_running-assert.yaml | 10 ++ .../05-checkpoint.yaml | 27 ++++ .../06-post_backup_data_write-assert.yaml | 6 + .../06-post_backup_data_write.yaml | 57 +++++++++ ...7-recovery_backup_pitr_cluster-assert.yaml | 6 + .../07-recovery_backup_pitr_cluster.yaml | 48 +++++++ .../08-data_test-assert.yaml | 6 + .../08-data_test.yaml | 27 ++++ .../chainsaw-test.yaml | 121 ++++++++++++++++++ 19 files changed, 437 insertions(+) create mode 100644 charts/cluster/test/timescale-minio-backup-restore/00-minio_cleanup-assert.yaml create mode 100644 charts/cluster/test/timescale-minio-backup-restore/00-minio_cleanup.yaml create mode 100644 charts/cluster/test/timescale-minio-backup-restore/01-timescale_cluster-assert.yaml create mode 100644 charts/cluster/test/timescale-minio-backup-restore/01-timescale_cluster.yaml create mode 100644 charts/cluster/test/timescale-minio-backup-restore/03-timescale_test-assert.yaml create mode 100644 charts/cluster/test/timescale-minio-backup-restore/03-timescale_test.yaml create mode 100644 charts/cluster/test/timescale-minio-backup-restore/04-data_write-assert.yaml create mode 100644 charts/cluster/test/timescale-minio-backup-restore/04-data_write.yaml create mode 100644 charts/cluster/test/timescale-minio-backup-restore/05-backup.yaml create mode 100644 charts/cluster/test/timescale-minio-backup-restore/05-backup_completed-assert.yaml create mode 100644 charts/cluster/test/timescale-minio-backup-restore/05-backup_running-assert.yaml create mode 100644 charts/cluster/test/timescale-minio-backup-restore/05-checkpoint.yaml create mode 100644 charts/cluster/test/timescale-minio-backup-restore/06-post_backup_data_write-assert.yaml create mode 100644 charts/cluster/test/timescale-minio-backup-restore/06-post_backup_data_write.yaml create mode 100644 charts/cluster/test/timescale-minio-backup-restore/07-recovery_backup_pitr_cluster-assert.yaml create mode 100644 charts/cluster/test/timescale-minio-backup-restore/07-recovery_backup_pitr_cluster.yaml create mode 100644 charts/cluster/test/timescale-minio-backup-restore/08-data_test-assert.yaml create mode 100644 charts/cluster/test/timescale-minio-backup-restore/08-data_test.yaml create mode 100644 charts/cluster/test/timescale-minio-backup-restore/chainsaw-test.yaml diff --git a/charts/cluster/test/timescale-minio-backup-restore/00-minio_cleanup-assert.yaml b/charts/cluster/test/timescale-minio-backup-restore/00-minio_cleanup-assert.yaml new file mode 100644 index 000000000..9c0f3eb48 --- /dev/null +++ b/charts/cluster/test/timescale-minio-backup-restore/00-minio_cleanup-assert.yaml @@ -0,0 +1,6 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: minio-cleanup +status: + succeeded: 1 diff --git a/charts/cluster/test/timescale-minio-backup-restore/00-minio_cleanup.yaml b/charts/cluster/test/timescale-minio-backup-restore/00-minio_cleanup.yaml new file mode 100644 index 000000000..ce71b1ef7 --- /dev/null +++ b/charts/cluster/test/timescale-minio-backup-restore/00-minio_cleanup.yaml @@ -0,0 +1,16 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: minio-cleanup +spec: + template: + spec: + restartPolicy: OnFailure + containers: + - name: minio-cleanup + image: minio/mc + command: ['sh', '-c'] + args: + - | + mc alias set myminio https://minio.minio.svc.cluster.local minio minio123 + mc rm --recursive --force myminio/mybucket/timescale diff --git a/charts/cluster/test/timescale-minio-backup-restore/01-timescale_cluster-assert.yaml b/charts/cluster/test/timescale-minio-backup-restore/01-timescale_cluster-assert.yaml new file mode 100644 index 000000000..3bbd2f8fe --- /dev/null +++ b/charts/cluster/test/timescale-minio-backup-restore/01-timescale_cluster-assert.yaml @@ -0,0 +1,6 @@ +apiVersion: postgresql.cnpg.io/v1 +kind: Cluster +metadata: + name: timescale-cluster +status: + readyInstances: 2 diff --git a/charts/cluster/test/timescale-minio-backup-restore/01-timescale_cluster.yaml b/charts/cluster/test/timescale-minio-backup-restore/01-timescale_cluster.yaml new file mode 100644 index 000000000..a248f7a3b --- /dev/null +++ b/charts/cluster/test/timescale-minio-backup-restore/01-timescale_cluster.yaml @@ -0,0 +1,26 @@ +type: timescaledb +mode: standalone +cluster: + instances: 2 + storage: + size: 256Mi + +backups: + enabled: true + provider: s3 + endpointURL: "https://minio.minio.svc.cluster.local" + endpointCA: + name: kube-root-ca.crt + key: ca.crt + wal: + encryption: "" + data: + encryption: "" + s3: + bucket: "mybucket" + path: "/timescale/v1" + accessKey: "minio" + secretKey: "minio123" + region: "local" + scheduledBackups: [] + retentionPolicy: "30d" diff --git a/charts/cluster/test/timescale-minio-backup-restore/03-timescale_test-assert.yaml b/charts/cluster/test/timescale-minio-backup-restore/03-timescale_test-assert.yaml new file mode 100644 index 000000000..aa63a21c9 --- /dev/null +++ b/charts/cluster/test/timescale-minio-backup-restore/03-timescale_test-assert.yaml @@ -0,0 +1,6 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: timescale-test +status: + succeeded: 1 diff --git a/charts/cluster/test/timescale-minio-backup-restore/03-timescale_test.yaml b/charts/cluster/test/timescale-minio-backup-restore/03-timescale_test.yaml new file mode 100644 index 000000000..2ad8bbbdd --- /dev/null +++ b/charts/cluster/test/timescale-minio-backup-restore/03-timescale_test.yaml @@ -0,0 +1,22 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: timescale-test +spec: + template: + spec: + restartPolicy: OnFailure + containers: + - name: data-test + env: + - name: DB_URI + valueFrom: + secretKeyRef: + name: timescale-cluster-app + key: uri + image: alpine:3.19 + command: ['sh', '-c'] + args: + - | + apk --no-cache add postgresql-client + test "$(psql $DB_URI -t -c 'SELECT EXISTS (SELECT FROM pg_extension WHERE extname = \'timescaledb\')' --csv -q 2>/dev/null)" = "t" \ No newline at end of file diff --git a/charts/cluster/test/timescale-minio-backup-restore/04-data_write-assert.yaml b/charts/cluster/test/timescale-minio-backup-restore/04-data_write-assert.yaml new file mode 100644 index 000000000..831f963d9 --- /dev/null +++ b/charts/cluster/test/timescale-minio-backup-restore/04-data_write-assert.yaml @@ -0,0 +1,6 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: data-write +status: + succeeded: 1 diff --git a/charts/cluster/test/timescale-minio-backup-restore/04-data_write.yaml b/charts/cluster/test/timescale-minio-backup-restore/04-data_write.yaml new file mode 100644 index 000000000..8b9338ebe --- /dev/null +++ b/charts/cluster/test/timescale-minio-backup-restore/04-data_write.yaml @@ -0,0 +1,23 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: data-write +spec: + template: + spec: + restartPolicy: OnFailure + containers: + - name: data-write + env: + - name: DB_URI + valueFrom: + secretKeyRef: + name: timescale-cluster-superuser + key: uri + image: alpine:3.19 + command: ['sh', '-c'] + args: + - | + apk --no-cache add postgresql-client kubectl + DB_URI=$(echo $DB_URI | sed "s|/\*|/|" ) + psql "$DB_URI" -c "CREATE TABLE mygoodtable (id serial PRIMARY KEY);" diff --git a/charts/cluster/test/timescale-minio-backup-restore/05-backup.yaml b/charts/cluster/test/timescale-minio-backup-restore/05-backup.yaml new file mode 100644 index 000000000..be5e4b181 --- /dev/null +++ b/charts/cluster/test/timescale-minio-backup-restore/05-backup.yaml @@ -0,0 +1,8 @@ +apiVersion: postgresql.cnpg.io/v1 +kind: Backup +metadata: + name: post-init-backup +spec: + method: barmanObjectStore + cluster: + name: timescale-cluster diff --git a/charts/cluster/test/timescale-minio-backup-restore/05-backup_completed-assert.yaml b/charts/cluster/test/timescale-minio-backup-restore/05-backup_completed-assert.yaml new file mode 100644 index 000000000..040b1a49e --- /dev/null +++ b/charts/cluster/test/timescale-minio-backup-restore/05-backup_completed-assert.yaml @@ -0,0 +1,10 @@ +apiVersion: postgresql.cnpg.io/v1 +kind: Backup +metadata: + name: post-init-backup +spec: + cluster: + name: timescale-cluster + method: barmanObjectStore +status: + phase: completed diff --git a/charts/cluster/test/timescale-minio-backup-restore/05-backup_running-assert.yaml b/charts/cluster/test/timescale-minio-backup-restore/05-backup_running-assert.yaml new file mode 100644 index 000000000..dc35727a0 --- /dev/null +++ b/charts/cluster/test/timescale-minio-backup-restore/05-backup_running-assert.yaml @@ -0,0 +1,10 @@ +apiVersion: postgresql.cnpg.io/v1 +kind: Backup +metadata: + name: post-init-backup +spec: + cluster: + name: timescale-cluster + method: barmanObjectStore +status: + phase: running diff --git a/charts/cluster/test/timescale-minio-backup-restore/05-checkpoint.yaml b/charts/cluster/test/timescale-minio-backup-restore/05-checkpoint.yaml new file mode 100644 index 000000000..3ba7fc727 --- /dev/null +++ b/charts/cluster/test/timescale-minio-backup-restore/05-checkpoint.yaml @@ -0,0 +1,27 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: backup-checkpoint +spec: + template: + spec: + restartPolicy: OnFailure + containers: + - name: create-checkpoint + env: + - name: DB_URI + valueFrom: + secretKeyRef: + name: timescale-cluster-superuser + key: uri + image: alpine:3.19 + command: ['sh', '-c'] + args: + - | + apk --no-cache add postgresql-client + DB_URI=$(echo $DB_URI | sed "s|/\*|/|" ) + END_TIME=$(( $(date +%s) + 30 )) + while [ $(date +%s) -lt $END_TIME ]; do + psql "$DB_URI" -c "SELECT pg_switch_wal();CHECKPOINT;" + sleep 5 + done diff --git a/charts/cluster/test/timescale-minio-backup-restore/06-post_backup_data_write-assert.yaml b/charts/cluster/test/timescale-minio-backup-restore/06-post_backup_data_write-assert.yaml new file mode 100644 index 000000000..ad9be77a7 --- /dev/null +++ b/charts/cluster/test/timescale-minio-backup-restore/06-post_backup_data_write-assert.yaml @@ -0,0 +1,6 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: data-write-post-backup +status: + succeeded: 1 diff --git a/charts/cluster/test/timescale-minio-backup-restore/06-post_backup_data_write.yaml b/charts/cluster/test/timescale-minio-backup-restore/06-post_backup_data_write.yaml new file mode 100644 index 000000000..1d8ddc984 --- /dev/null +++ b/charts/cluster/test/timescale-minio-backup-restore/06-post_backup_data_write.yaml @@ -0,0 +1,57 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: configmap-creator-sa +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: configmap-creator +rules: +- apiGroups: [""] + resources: ["configmaps"] + verbs: ["create"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: configmap-creator-binding +subjects: +- kind: ServiceAccount + name: configmap-creator-sa +roleRef: + kind: Role + name: configmap-creator + apiGroup: rbac.authorization.k8s.io +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: data-write-post-backup +spec: + template: + spec: + serviceAccountName: configmap-creator-sa + restartPolicy: OnFailure + containers: + - name: data-write + env: + - name: DB_URI + valueFrom: + secretKeyRef: + name: timescale-cluster-superuser + key: uri + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + image: alpine:3.19 + command: ['sh', '-c'] + args: + - | + apk --no-cache add postgresql-client kubectl coreutils + DB_URI=$(echo $DB_URI | sed "s|/\*|/|" ) + DATE_NO_BAD_TABLE=$(date --rfc-3339=ns) + sleep 30 + psql "$DB_URI" -c "CREATE TABLE mybadtable (id serial PRIMARY KEY);" + kubectl create configmap date-no-bad-table --from-literal=date="$DATE_NO_BAD_TABLE" diff --git a/charts/cluster/test/timescale-minio-backup-restore/07-recovery_backup_pitr_cluster-assert.yaml b/charts/cluster/test/timescale-minio-backup-restore/07-recovery_backup_pitr_cluster-assert.yaml new file mode 100644 index 000000000..2b6b9651f --- /dev/null +++ b/charts/cluster/test/timescale-minio-backup-restore/07-recovery_backup_pitr_cluster-assert.yaml @@ -0,0 +1,6 @@ +apiVersion: postgresql.cnpg.io/v1 +kind: Cluster +metadata: + name: recovery-backup-pitr-cluster +status: + readyInstances: 2 diff --git a/charts/cluster/test/timescale-minio-backup-restore/07-recovery_backup_pitr_cluster.yaml b/charts/cluster/test/timescale-minio-backup-restore/07-recovery_backup_pitr_cluster.yaml new file mode 100644 index 000000000..7e9c38f55 --- /dev/null +++ b/charts/cluster/test/timescale-minio-backup-restore/07-recovery_backup_pitr_cluster.yaml @@ -0,0 +1,48 @@ +type: timescaledb +mode: recovery + +cluster: + instances: 2 + storage: + size: 256Mi + +recovery: + method: backup + backupName: "post-init-backup" + provider: s3 + endpointURL: "https://minio.minio.svc.cluster.local" + endpointCA: + name: kube-root-ca.crt + key: ca.crt + wal: + encryption: "" + data: + encryption: "" + s3: + bucket: "mybucket" + path: "/timescale/v1" + accessKey: "minio" + secretKey: "minio123" + region: "local" + scheduledBackups: [] + retentionPolicy: "30d" + +backups: + enabled: true + provider: s3 + endpointURL: "https://minio.minio.svc.cluster.local" + endpointCA: + name: kube-root-ca.crt + key: ca.crt + wal: + encryption: "" + data: + encryption: "" + s3: + bucket: "mybucket" + path: "/timescale/v2" + accessKey: "minio" + secretKey: "minio123" + region: "local" + scheduledBackups: [] + retentionPolicy: "30d" diff --git a/charts/cluster/test/timescale-minio-backup-restore/08-data_test-assert.yaml b/charts/cluster/test/timescale-minio-backup-restore/08-data_test-assert.yaml new file mode 100644 index 000000000..6f14d5f23 --- /dev/null +++ b/charts/cluster/test/timescale-minio-backup-restore/08-data_test-assert.yaml @@ -0,0 +1,6 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: data-test-backup-pitr +status: + succeeded: 1 diff --git a/charts/cluster/test/timescale-minio-backup-restore/08-data_test.yaml b/charts/cluster/test/timescale-minio-backup-restore/08-data_test.yaml new file mode 100644 index 000000000..5fb4faf39 --- /dev/null +++ b/charts/cluster/test/timescale-minio-backup-restore/08-data_test.yaml @@ -0,0 +1,27 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: data-test-backup-pitr +spec: + template: + spec: + restartPolicy: OnFailure + containers: + - name: data-test + env: + - name: DB_URI + valueFrom: + secretKeyRef: + name: recovery-backup-pitr-cluster-superuser + key: uri + image: alpine:3.19 + command: ['sh', '-c'] + args: + - | + apk --no-cache add postgresql-client + DB_URI=$(echo $DB_URI | sed "s|/\*|/|" ) + set -e + test "$(psql $DB_URI -t -c 'SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_name = $$mygoodtable$$)' --csv -q 2>/dev/null)" = "t" + echo "Good table exists" + test "$(psql $DB_URI -t -c 'SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_name = $$mybadtable$$)' --csv -q 2>/dev/null)" = "f" + echo "Bad table does not exist" diff --git a/charts/cluster/test/timescale-minio-backup-restore/chainsaw-test.yaml b/charts/cluster/test/timescale-minio-backup-restore/chainsaw-test.yaml new file mode 100644 index 000000000..e0a8ee401 --- /dev/null +++ b/charts/cluster/test/timescale-minio-backup-restore/chainsaw-test.yaml @@ -0,0 +1,121 @@ +## +# This test sets up a timescale cluster with MinIO backups and ensured that timescale extensions are installed and +# PITR recovery is enabled and working. +apiVersion: chainsaw.kyverno.io/v1alpha1 +kind: Test +metadata: + name: timescale +spec: + timeouts: + apply: 1s + assert: 5m + cleanup: 1m + steps: + - name: Clear the MinIO bucket + try: + - apply: + file: ./00-minio_cleanup.yaml + - assert: + file: ./00-minio_cleanup-assert.yaml + - name: Install a standalone timescale cluster + try: + - script: + content: | + kubectl -n $NAMESPACE create secret generic kube-root-ca.crt --from-literal=ca.crt="$(kubectl -n kube-system get configmaps kube-root-ca.crt -o jsonpath='{.data.ca\.crt}')" --dry-run=client -o yaml | kubectl apply -f - + helm upgrade \ + --install \ + --namespace $NAMESPACE \ + --values ./01-timescale_cluster.yaml \ + --wait \ + timescale ../../ + - assert: + file: ./01-timescale_cluster-assert.yaml + catch: + - describe: + apiVersion: postgresql.cnpg.io/v1 + kind: Cluster + - name: Verify timescale extensions are installed + timeouts: + apply: 1s + assert: 30s + try: + - apply: + file: 03-timescale_test.yaml + - assert: + file: 03-timescale_test-assert.yaml + catch: + - describe: + apiVersion: batch/v1 + kind: Job + - podLogs: + selector: batch.kubernetes.io/job-name=data-test + - name: Write some data to the cluster + timeouts: + apply: 1s + assert: 30s + try: + - apply: + file: 04-data_write.yaml + - assert: + file: 04-data_write-assert.yaml + catch: + - describe: + apiVersion: batch/v1 + kind: Job + - podLogs: + selector: batch.kubernetes.io/job-name=data-test + - name: Create a backup + try: + - apply: + file: ./05-backup.yaml + - assert: + file: ./05-backup_running-assert.yaml + - apply: + file: ./05-checkpoint.yaml + - assert: + file: ./05-backup_completed-assert.yaml + - name: Write more data to the database after the backup + try: + - apply: + file: ./06-post_backup_data_write.yaml + - assert: + file: ./06-post_backup_data_write-assert.yaml + timeouts: + apply: 1s + assert: 10m + catch: + - describe: + apiVersion: postgresql.cnpg.io/v1 + kind: Backup + - name: Create a recovery cluster from backup with a PITR target + try: + - script: + content: | + DATE_NO_BAD_TABLE=$(kubectl -n $NAMESPACE get configmap date-no-bad-table -o 'jsonpath={.data.date}') + helm upgrade \ + --install \ + --namespace $NAMESPACE \ + --values ./07-recovery_backup_pitr_cluster.yaml \ + --set recovery.pitrTarget.time="$DATE_NO_BAD_TABLE" \ + --wait \ + recovery-backup-pitr ../../ + - assert: + file: ./07-recovery_backup_pitr_cluster-assert.yaml + - name: Verify the pre-backup data on the recovery cluster exists but not the post-backup data + try: + - apply: + file: 08-data_test.yaml + - assert: + file: 08-data_test-assert.yaml + catch: + - describe: + apiVersion: batch/v1 + kind: Job + selector: batch.kubernetes.io/job-name=data-test-backup-pitr + - podLogs: + selector: batch.kubernetes.io/job-name=data-test-backup-pitr + - name: Cleanup + try: + - script: + content: | + helm uninstall --namespace $NAMESPACE timescale From adf9d8972946feeb79463a7fcc50423a380aa9a6 Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Sun, 8 Sep 2024 17:45:20 +0300 Subject: [PATCH 12/14] Style fixes Signed-off-by: Itay Grudev --- .../timescale-minio-backup-restore/01-timescale_cluster.yaml | 2 ++ .../test/timescale-minio-backup-restore/03-timescale_test.yaml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/charts/cluster/test/timescale-minio-backup-restore/01-timescale_cluster.yaml b/charts/cluster/test/timescale-minio-backup-restore/01-timescale_cluster.yaml index a248f7a3b..f84117fe0 100644 --- a/charts/cluster/test/timescale-minio-backup-restore/01-timescale_cluster.yaml +++ b/charts/cluster/test/timescale-minio-backup-restore/01-timescale_cluster.yaml @@ -1,5 +1,6 @@ type: timescaledb mode: standalone + cluster: instances: 2 storage: @@ -7,6 +8,7 @@ cluster: backups: enabled: true + provider: s3 endpointURL: "https://minio.minio.svc.cluster.local" endpointCA: diff --git a/charts/cluster/test/timescale-minio-backup-restore/03-timescale_test.yaml b/charts/cluster/test/timescale-minio-backup-restore/03-timescale_test.yaml index 2ad8bbbdd..9b7581f96 100644 --- a/charts/cluster/test/timescale-minio-backup-restore/03-timescale_test.yaml +++ b/charts/cluster/test/timescale-minio-backup-restore/03-timescale_test.yaml @@ -19,4 +19,4 @@ spec: args: - | apk --no-cache add postgresql-client - test "$(psql $DB_URI -t -c 'SELECT EXISTS (SELECT FROM pg_extension WHERE extname = \'timescaledb\')' --csv -q 2>/dev/null)" = "t" \ No newline at end of file + test "$(psql $DB_URI -t -c 'SELECT EXISTS (SELECT FROM pg_extension WHERE extname = '\''timescaledb'\'')' --csv -q 2>/dev/null)" = "t" \ No newline at end of file From 9d161a41ab1c3106029dc224d39292425a7896ea Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Sun, 8 Sep 2024 17:46:56 +0300 Subject: [PATCH 13/14] Test FIx: incorrect timestamp due to operation order Signed-off-by: Itay Grudev --- .../04-data_write.yaml | 33 ++++++++++++++++++- .../06-post_backup_data_write.yaml | 32 +----------------- .../07-recovery_backup_pitr_cluster.yaml | 2 +- 3 files changed, 34 insertions(+), 33 deletions(-) diff --git a/charts/cluster/test/timescale-minio-backup-restore/04-data_write.yaml b/charts/cluster/test/timescale-minio-backup-restore/04-data_write.yaml index 8b9338ebe..b827de143 100644 --- a/charts/cluster/test/timescale-minio-backup-restore/04-data_write.yaml +++ b/charts/cluster/test/timescale-minio-backup-restore/04-data_write.yaml @@ -1,3 +1,29 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: configmap-creator-sa +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: configmap-creator +rules: +- apiGroups: [""] + resources: ["configmaps"] + verbs: ["create"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: configmap-creator-binding +subjects: +- kind: ServiceAccount + name: configmap-creator-sa +roleRef: + kind: Role + name: configmap-creator + apiGroup: rbac.authorization.k8s.io +--- apiVersion: batch/v1 kind: Job metadata: @@ -5,6 +31,7 @@ metadata: spec: template: spec: + serviceAccountName: configmap-creator-sa restartPolicy: OnFailure containers: - name: data-write @@ -18,6 +45,10 @@ spec: command: ['sh', '-c'] args: - | - apk --no-cache add postgresql-client kubectl + apk --no-cache add postgresql-client kubectl coreutils DB_URI=$(echo $DB_URI | sed "s|/\*|/|" ) psql "$DB_URI" -c "CREATE TABLE mygoodtable (id serial PRIMARY KEY);" + sleep 5 + DATE_NO_BAD_TABLE=$(date --rfc-3339=ns) + kubectl create configmap date-no-bad-table --from-literal=date="$DATE_NO_BAD_TABLE" + sleep 5 diff --git a/charts/cluster/test/timescale-minio-backup-restore/06-post_backup_data_write.yaml b/charts/cluster/test/timescale-minio-backup-restore/06-post_backup_data_write.yaml index 1d8ddc984..8585b247d 100644 --- a/charts/cluster/test/timescale-minio-backup-restore/06-post_backup_data_write.yaml +++ b/charts/cluster/test/timescale-minio-backup-restore/06-post_backup_data_write.yaml @@ -1,29 +1,3 @@ -apiVersion: v1 -kind: ServiceAccount -metadata: - name: configmap-creator-sa ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: configmap-creator -rules: -- apiGroups: [""] - resources: ["configmaps"] - verbs: ["create"] ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: RoleBinding -metadata: - name: configmap-creator-binding -subjects: -- kind: ServiceAccount - name: configmap-creator-sa -roleRef: - kind: Role - name: configmap-creator - apiGroup: rbac.authorization.k8s.io ---- apiVersion: batch/v1 kind: Job metadata: @@ -31,7 +5,6 @@ metadata: spec: template: spec: - serviceAccountName: configmap-creator-sa restartPolicy: OnFailure containers: - name: data-write @@ -49,9 +22,6 @@ spec: command: ['sh', '-c'] args: - | - apk --no-cache add postgresql-client kubectl coreutils + apk --no-cache add postgresql-client DB_URI=$(echo $DB_URI | sed "s|/\*|/|" ) - DATE_NO_BAD_TABLE=$(date --rfc-3339=ns) - sleep 30 psql "$DB_URI" -c "CREATE TABLE mybadtable (id serial PRIMARY KEY);" - kubectl create configmap date-no-bad-table --from-literal=date="$DATE_NO_BAD_TABLE" diff --git a/charts/cluster/test/timescale-minio-backup-restore/07-recovery_backup_pitr_cluster.yaml b/charts/cluster/test/timescale-minio-backup-restore/07-recovery_backup_pitr_cluster.yaml index 7e9c38f55..fabb3b9bb 100644 --- a/charts/cluster/test/timescale-minio-backup-restore/07-recovery_backup_pitr_cluster.yaml +++ b/charts/cluster/test/timescale-minio-backup-restore/07-recovery_backup_pitr_cluster.yaml @@ -8,7 +8,7 @@ cluster: recovery: method: backup - backupName: "post-init-backup" + clusterName: "post-init-backup" provider: s3 endpointURL: "https://minio.minio.svc.cluster.local" endpointCA: From bbf8520d31b1e83538105d057f4b7a0738fa2816 Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Mon, 9 Sep 2024 01:01:29 +0300 Subject: [PATCH 14/14] Fixed typo in test spec Signed-off-by: Itay Grudev --- .../07-recovery_backup_pitr_cluster.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/cluster/test/timescale-minio-backup-restore/07-recovery_backup_pitr_cluster.yaml b/charts/cluster/test/timescale-minio-backup-restore/07-recovery_backup_pitr_cluster.yaml index fabb3b9bb..7e9c38f55 100644 --- a/charts/cluster/test/timescale-minio-backup-restore/07-recovery_backup_pitr_cluster.yaml +++ b/charts/cluster/test/timescale-minio-backup-restore/07-recovery_backup_pitr_cluster.yaml @@ -8,7 +8,7 @@ cluster: recovery: method: backup - clusterName: "post-init-backup" + backupName: "post-init-backup" provider: s3 endpointURL: "https://minio.minio.svc.cluster.local" endpointCA: