fix(cnpg): hibernation wasn't working because instances cannot be 0

This commit is contained in:
Stavros kois
2023-12-21 09:55:01 +02:00
parent 1a6bb5d9b9
commit a7bb6499a1
8 changed files with 47 additions and 6 deletions

View File

@@ -556,3 +556,18 @@ tests:
asserts:
- failedTemplate:
errorMessage: CNPG Backup - You need to specify [backups.azure.containerName] or [backups.destinationPath]
- it: should fail with instances less than 1
set:
operator:
verify:
enabled: false
cnpg:
my-pg:
enabled: true
instances: 0
user: test-user
database: test-db
asserts:
- failedTemplate:
errorMessage: CNPG - Expected [instances] to be greater than 0, but got [0]

View File

@@ -20,3 +20,19 @@ tests:
asserts:
- failedTemplate:
errorMessage: CNPG Pooler - Expected [poolMode] to be one of [session, transaction], but got [invalid]
- it: should fail with pooler instances less than 1
set:
operator:
verify:
enabled: false
cnpg:
my-pg:
enabled: true
user: test-user
database: test-db
pooler:
instances: 0
asserts:
- failedTemplate:
errorMessage: CNPG Pooler - Expected [instances] to be greater than 0, but got [0]

View File

@@ -39,7 +39,7 @@ tests:
isSubset:
path: spec
content:
instances: 0
instances: 2
- it: should set hibernate and 0 instances on stopAll
set:
@@ -77,7 +77,7 @@ tests:
isSubset:
path: spec
content:
instances: 0
instances: 2
- it: should set hibernate and 0 instances on ixChartContext - isStopped
set:
@@ -118,7 +118,7 @@ tests:
isSubset:
path: spec
content:
instances: 0
instances: 2
- it: should not set hibernate and 0 instances on ixChartContext - isStopped
set:

View File

@@ -15,4 +15,4 @@ maintainers:
name: common
sources: null
type: library
version: 16.2.7
version: 16.2.8

View File

@@ -56,7 +56,6 @@
{{/* Stop All */}}
{{- if or $objectData.hibernate (include "tc.v1.common.lib.util.stopAll" $rootCtx) -}}
{{- $hibernation = "on" -}}
{{- $instances = 0 -}}
{{- end -}}
{{/* General */}}

View File

@@ -20,7 +20,6 @@
{{- $instances := $objectData.pooler.instances | default 2 -}}
{{- $hibernation := "off" -}}
{{- if or $objectData.hibernate (include "tc.v1.common.lib.util.stopAll" $rootCtx) -}}
{{- $instances = 0 -}}
{{- $hibernation = "on" -}}
{{- end }}
---

View File

@@ -21,6 +21,12 @@
{{- end -}}
{{- end -}}
{{- if (hasKey $objectData "instances") -}}
{{- if lt ($objectData.instances | int) 1 -}}
{{- fail (printf "CNPG - Expected [instances] to be greater than 0, but got [%d]" ($objectData.instances | int)) -}}
{{- end -}}
{{- end -}}
{{- if (hasKey $objectData "mode") -}}
{{- $validModes := (list "standalone" "replica" "recovery") -}}
{{- if not (mustHas $objectData.mode $validModes) -}}

View File

@@ -6,6 +6,12 @@
{{- fail (printf "CNPG Pooler - Expected [type] to be one one of [%s], but got [%s]" (join ", " $validTypes) $objectData.pooler.type) -}}
{{- end -}}
{{- if (hasKey $objectData.pooler "instances") -}}
{{- if lt ($objectData.pooler.instances | int) 1 -}}
{{- fail (printf "CNPG Pooler - Expected [instances] to be greater than 0, but got [%d]" ($objectData.instances | int)) -}}
{{- end -}}
{{- end -}}
{{- $validPgModes := (list "session" "transaction") -}}
{{- if $objectData.pooler.poolMode -}}
{{- if not (mustHas $objectData.pooler.poolMode $validPgModes) -}}