diff --git a/library/common-test/tests/cnpg/cluster_validation_test.yaml b/library/common-test/tests/cnpg/cluster_validation_test.yaml index 5c5699bf..57d57e3c 100644 --- a/library/common-test/tests/cnpg/cluster_validation_test.yaml +++ b/library/common-test/tests/cnpg/cluster_validation_test.yaml @@ -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] diff --git a/library/common-test/tests/cnpg/pooler_validation_test.yaml b/library/common-test/tests/cnpg/pooler_validation_test.yaml index 57ad4fee..a3ceaa4e 100644 --- a/library/common-test/tests/cnpg/pooler_validation_test.yaml +++ b/library/common-test/tests/cnpg/pooler_validation_test.yaml @@ -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] diff --git a/library/common-test/tests/cnpg/stop_test.yaml b/library/common-test/tests/cnpg/stop_test.yaml index 21e873c6..dee3d045 100644 --- a/library/common-test/tests/cnpg/stop_test.yaml +++ b/library/common-test/tests/cnpg/stop_test.yaml @@ -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: diff --git a/library/common/Chart.yaml b/library/common/Chart.yaml index 81999d4f..15f9ab4a 100644 --- a/library/common/Chart.yaml +++ b/library/common/Chart.yaml @@ -15,4 +15,4 @@ maintainers: name: common sources: null type: library -version: 16.2.7 +version: 16.2.8 diff --git a/library/common/templates/class/cnpg/_cluster.tpl b/library/common/templates/class/cnpg/_cluster.tpl index a0bf8834..568c9912 100644 --- a/library/common/templates/class/cnpg/_cluster.tpl +++ b/library/common/templates/class/cnpg/_cluster.tpl @@ -56,7 +56,6 @@ {{/* Stop All */}} {{- if or $objectData.hibernate (include "tc.v1.common.lib.util.stopAll" $rootCtx) -}} {{- $hibernation = "on" -}} - {{- $instances = 0 -}} {{- end -}} {{/* General */}} diff --git a/library/common/templates/class/cnpg/_pooler.tpl b/library/common/templates/class/cnpg/_pooler.tpl index 271a9843..d8246b91 100644 --- a/library/common/templates/class/cnpg/_pooler.tpl +++ b/library/common/templates/class/cnpg/_pooler.tpl @@ -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 }} --- diff --git a/library/common/templates/lib/cnpg/cluster/_validation.tpl b/library/common/templates/lib/cnpg/cluster/_validation.tpl index 5ded8d8e..73124530 100644 --- a/library/common/templates/lib/cnpg/cluster/_validation.tpl +++ b/library/common/templates/lib/cnpg/cluster/_validation.tpl @@ -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) -}} diff --git a/library/common/templates/lib/cnpg/pooler/_validation.tpl b/library/common/templates/lib/cnpg/pooler/_validation.tpl index 105f2cdb..b5903189 100644 --- a/library/common/templates/lib/cnpg/pooler/_validation.tpl +++ b/library/common/templates/lib/cnpg/pooler/_validation.tpl @@ -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) -}}