diff --git a/library/common-test/tests/cnpg/pooler_metadata_test.yaml b/library/common-test/tests/cnpg/pooler_metadata_test.yaml index b69ce713..5f9c57b1 100644 --- a/library/common-test/tests/cnpg/pooler_metadata_test.yaml +++ b/library/common-test/tests/cnpg/pooler_metadata_test.yaml @@ -60,7 +60,6 @@ tests: annotation3: annotation3 g_annotation1: global_annotation1 g_annotation2: global_annotation2 - cnpg.io/hibernation: "off" some-annotation: some-value - documentIndex: *poolerDoc matchRegex: diff --git a/library/common-test/tests/cnpg/stop_test.yaml b/library/common-test/tests/cnpg/stop_test.yaml index dee3d045..d92700ed 100644 --- a/library/common-test/tests/cnpg/stop_test.yaml +++ b/library/common-test/tests/cnpg/stop_test.yaml @@ -18,7 +18,10 @@ tests: instances: 2 hibernate: true asserts: - - documentIndex: &clusterDoc 1 + # Cluster and 2 Secrets + - hasDocuments: + count: &docCount 3 + - documentIndex: &clusterDoc 0 isKind: of: Cluster - documentIndex: *clusterDoc @@ -29,17 +32,6 @@ tests: path: metadata.annotations content: cnpg.io/hibernation: "on" - - documentIndex: &poolerDoc 0 - isKind: - of: Pooler - - documentIndex: *poolerDoc - isAPIVersion: - of: postgresql.cnpg.io/v1 - - documentIndex: *poolerDoc - isSubset: - path: spec - content: - instances: 2 - it: should set hibernate and 0 instances on stopAll set: @@ -56,6 +48,8 @@ tests: hibernate: false instances: 2 asserts: + - hasDocuments: + count: *docCount - documentIndex: *clusterDoc isKind: of: Cluster @@ -67,17 +61,6 @@ tests: path: metadata.annotations content: cnpg.io/hibernation: "on" - - documentIndex: *poolerDoc - isKind: - of: Pooler - - documentIndex: *poolerDoc - isAPIVersion: - of: postgresql.cnpg.io/v1 - - documentIndex: *poolerDoc - isSubset: - path: spec - content: - instances: 2 - it: should set hibernate and 0 instances on ixChartContext - isStopped set: @@ -97,6 +80,8 @@ tests: hibernate: false instances: 2 asserts: + - hasDocuments: + count: *docCount - documentIndex: *clusterDoc isKind: of: Cluster @@ -108,17 +93,6 @@ tests: path: metadata.annotations content: cnpg.io/hibernation: "on" - - documentIndex: *poolerDoc - isKind: - of: Pooler - - documentIndex: *poolerDoc - isAPIVersion: - of: postgresql.cnpg.io/v1 - - documentIndex: *poolerDoc - isSubset: - path: spec - content: - instances: 2 - it: should not set hibernate and 0 instances on ixChartContext - isStopped set: @@ -138,7 +112,10 @@ tests: hibernate: false instances: 2 asserts: - - documentIndex: *clusterDoc + # Cluster, Pooler and 2 Secrets + - hasDocuments: + count: 4 + - documentIndex: &clusterDoc 1 isKind: of: Cluster - documentIndex: *clusterDoc @@ -149,7 +126,7 @@ tests: path: metadata.annotations content: cnpg.io/hibernation: "off" - - documentIndex: *poolerDoc + - documentIndex: &poolerDoc 0 isKind: of: Pooler - documentIndex: *poolerDoc diff --git a/library/common/Chart.yaml b/library/common/Chart.yaml index 0bc095b4..cbf517f4 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.12 +version: 16.2.13 diff --git a/library/common/templates/class/cnpg/_pooler.tpl b/library/common/templates/class/cnpg/_pooler.tpl index d8246b91..ef0cdefe 100644 --- a/library/common/templates/class/cnpg/_pooler.tpl +++ b/library/common/templates/class/cnpg/_pooler.tpl @@ -16,12 +16,7 @@ {{- $poolerAnnotations := $objectData.pooler.annotations | default dict -}} {{- $poolerAnnotations = mustMerge $poolerAnnotations $objAnnotations -}} - {{/* Stop All */}} - {{- $instances := $objectData.pooler.instances | default 2 -}} - {{- $hibernation := "off" -}} - {{- if or $objectData.hibernate (include "tc.v1.common.lib.util.stopAll" $rootCtx) -}} - {{- $hibernation = "on" -}} - {{- end }} + {{- $instances := $objectData.pooler.instances | default 2 }} --- apiVersion: postgresql.cnpg.io/v1 kind: Pooler @@ -36,7 +31,6 @@ metadata: {{- end }} annotations: rollme: {{ randAlphaNum 5 | quote }} - cnpg.io/hibernation: {{ $hibernation | quote }} {{- $annotations := (mustMerge $poolerAnnotations (include "tc.v1.common.lib.metadata.allAnnotations" $rootCtx | fromYaml)) -}} {{- with (include "tc.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "annotations" $annotations) | trim) }} {{- . | nindent 4 }} diff --git a/library/common/templates/lib/cnpg/pooler/_spawner.tpl b/library/common/templates/lib/cnpg/pooler/_spawner.tpl index e08ceed4..7dc7d89b 100644 --- a/library/common/templates/lib/cnpg/pooler/_spawner.tpl +++ b/library/common/templates/lib/cnpg/pooler/_spawner.tpl @@ -16,26 +16,29 @@ {{- $_ := set $objectData.pooler "type" "rw" -}} {{/* Validate Pooler */}} {{- include "tc.v1.common.lib.cnpg.pooler.validation" (dict "objectData" $objectData) -}} - {{/* Create the RW Pooler object */}} - {{- include "tc.v1.common.class.cnpg.pooler" (dict "rootCtx" $rootCtx "objectData" $objectData) -}} - {{- if $monitoring -}} {{/* TODO: Unit tests for Pooler Metrics */}} - {{- $poolerMetrics := include "tc.v1.common.lib.cnpg.metrics.pooler" (dict "poolerName" (printf "%s-rw" $objectData.name)) | fromYaml -}} - {{- $_ := set $.Values.metrics (printf "cnpg-%s-rw" $objectData.shortName) $poolerMetrics -}} - {{- end -}} - - {{- if $objectData.pooler.createRO -}} - {{- $_ := set $objectData.pooler "type" "ro" -}} - - {{/* Validate Pooler */}} - {{- include "tc.v1.common.lib.cnpg.pooler.validation" (dict "objectData" $objectData) -}} - {{/* Create the RO Pooler object */}} + {{/* Stop All */}} + {{- if not (or $objectData.hibernate (include "tc.v1.common.lib.util.stopAll" $rootCtx)) -}} + {{/* Create the RW Pooler object */}} {{- include "tc.v1.common.class.cnpg.pooler" (dict "rootCtx" $rootCtx "objectData" $objectData) -}} {{- if $monitoring -}} {{/* TODO: Unit tests for Pooler Metrics */}} {{- $poolerMetrics := include "tc.v1.common.lib.cnpg.metrics.pooler" (dict "poolerName" (printf "%s-rw" $objectData.name)) | fromYaml -}} - {{- $_ := set $.Values.metrics (printf "cnpg-%s-ro" $objectData.shortName) $poolerMetrics -}} + {{- $_ := set $.Values.metrics (printf "cnpg-%s-rw" $objectData.shortName) $poolerMetrics -}} + {{- end -}} + + {{- if $objectData.pooler.createRO -}} + {{- $_ := set $objectData.pooler "type" "ro" -}} + + {{/* Validate Pooler */}} + {{- include "tc.v1.common.lib.cnpg.pooler.validation" (dict "objectData" $objectData) -}} + {{/* Create the RO Pooler object */}} + {{- include "tc.v1.common.class.cnpg.pooler" (dict "rootCtx" $rootCtx "objectData" $objectData) -}} + + {{- if $monitoring -}} {{/* TODO: Unit tests for Pooler Metrics */}} + {{- $poolerMetrics := include "tc.v1.common.lib.cnpg.metrics.pooler" (dict "poolerName" (printf "%s-rw" $objectData.name)) | fromYaml -}} + {{- $_ := set $.Values.metrics (printf "cnpg-%s-ro" $objectData.shortName) $poolerMetrics -}} + {{- end -}} {{- end -}} {{- end -}} - {{- end -}}