From 08bf0e8130a17894bd35aca4cfb5bfbafb90399e Mon Sep 17 00:00:00 2001 From: Kjeld Schouten Date: Fri, 12 May 2023 14:24:51 +0200 Subject: [PATCH] feat(common): add support for cnpg cluster hibernation without using annotations (#420) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Description** cluster hibernation is a good way to get CNPG to scale down to 0 cleanly. This might(!) be a potential solution for fixing the broken stop button on SCALE as well, but that's not fully clear as of yet. This also scales down the poolers to 0 as well. To ensure nothing remains active. **โš™๏ธ Type of change** - [x] โš™๏ธ Feature/App addition - [ ] ๐Ÿช› Bugfix - [ ] โš ๏ธ Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] ๐Ÿ”ƒ Refactor of current code **๐Ÿงช How Has This Been Tested?** **๐Ÿ“ƒ Notes:** **โœ”๏ธ Checklist:** - [x] โš–๏ธ My code follows the style guidelines of this project - [x] ๐Ÿ‘€ I have performed a self-review of my own code - [x] #๏ธโƒฃ I have commented my code, particularly in hard-to-understand areas - [x] ๐Ÿ“„ I have made corresponding changes to the documentation - [x] โš ๏ธ My changes generate no new warnings - [x] ๐Ÿงช I have added tests to this description that prove my fix is effective or that my feature works - [x] โฌ†๏ธ I increased versions for any altered app according to semantic versioning **โž• App addition** If this PR is an app addition please make sure you have done the following. - [ ] ๐Ÿชž I have opened a PR on [truecharts/containers](https://github.com/truecharts/containers) adding the container to TrueCharts mirror repo. - [ ] ๐Ÿ–ผ๏ธ I have added an icon in the Chart's root directory called `icon.png` --- _Please don't blindly check all the boxes. Read them and only check those that apply. Those checkboxes are there for the reviewer to see what is this all about and the status of this PR with a quick glance._ --- library/common-test/Chart.yaml | 2 +- library/common/Chart.yaml | 2 +- library/common/templates/class/_cnpgCluster.tpl | 12 +++++++----- library/common/templates/class/_cnpgPooler.tpl | 2 +- library/common/values.yaml | 3 +++ 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/library/common-test/Chart.yaml b/library/common-test/Chart.yaml index 0c7cb71b..fd5cfbb8 100644 --- a/library/common-test/Chart.yaml +++ b/library/common-test/Chart.yaml @@ -3,7 +3,7 @@ appVersion: "" dependencies: - name: common repository: file://../common - version: ~12.6.0 + version: ~12.7.0 deprecated: false description: Helper chart to test different use cases of the common library home: https://github.com/truecharts/apps/tree/master/charts/library/common-test diff --git a/library/common/Chart.yaml b/library/common/Chart.yaml index 4138e4be..79c9c54e 100644 --- a/library/common/Chart.yaml +++ b/library/common/Chart.yaml @@ -15,4 +15,4 @@ maintainers: name: common sources: null type: library -version: 12.6.9 +version: 12.7.0 diff --git a/library/common/templates/class/_cnpgCluster.tpl b/library/common/templates/class/_cnpgCluster.tpl index 6ffa7b95..e309e657 100644 --- a/library/common/templates/class/_cnpgCluster.tpl +++ b/library/common/templates/class/_cnpgCluster.tpl @@ -15,14 +15,16 @@ apiVersion: {{ include "tc.v1.common.capabilities.cnpg.cluster.apiVersion" $ }} kind: Cluster metadata: name: {{ $cnpgClusterName }} - {{- $labels := (mustMerge ($cnpgClusterLabels | default dict) (include "tc.v1.common.lib.metadata.allLabels" $ | fromYaml)) -}} - {{- with (include "tc.v1.common.lib.metadata.render" (dict "rootCtx" $ "labels" $labels) | trim) }} + {{- $labels := (mustMerge ($cnpgClusterLabels | default dict) (include "tc.v1.common.lib.metadata.allLabels" $ | fromYaml)) }} labels: + cnpg.io/reload: "on" + {{- with (include "tc.v1.common.lib.metadata.render" (dict "rootCtx" $ "labels" $labels) | trim) }} {{- . | nindent 4 }} {{- end }} - {{- $annotations := (mustMerge ($cnpgClusterAnnotations | default dict) (include "tc.v1.common.lib.metadata.allAnnotations" $ | fromYaml)) -}} - {{- with (include "tc.v1.common.lib.metadata.render" (dict "rootCtx" $ "annotations" $annotations) | trim) }} + {{- $annotations := (mustMerge ($cnpgClusterAnnotations | default dict) (include "tc.v1.common.lib.metadata.allAnnotations" $ | fromYaml)) }} annotations: + cnpg.io/hibernation: {{ if $values.hibernate }}"on"{{ else }}"off"{{ end }} + {{- with (include "tc.v1.common.lib.metadata.render" (dict "rootCtx" $ "annotations" $annotations) | trim) }} {{- . | nindent 4 }} {{- end }} spec: @@ -64,7 +66,7 @@ spec: nodeMaintenanceWindow: inProgress: false - reusePVC: on + reusePVC: true postgresql: {{- tpl ( $values.postgresql | toYaml ) $ | nindent 4 }} diff --git a/library/common/templates/class/_cnpgPooler.tpl b/library/common/templates/class/_cnpgPooler.tpl index ce241e39..67b63a5a 100644 --- a/library/common/templates/class/_cnpgPooler.tpl +++ b/library/common/templates/class/_cnpgPooler.tpl @@ -21,7 +21,7 @@ spec: cluster: name: {{ $cnpgClusterName }} - instances: {{ $values.pooler.instances | default 2 }} + instances: {{ if $values.hibernate}}0{{ else }}{{ $values.pooler.instances | default 2 }}{{ end }} type: {{ $values.pooler.type }} pgbouncer: poolMode: session diff --git a/library/common/values.yaml b/library/common/values.yaml index 4f1322d5..0f0657b4 100644 --- a/library/common/values.yaml +++ b/library/common/values.yaml @@ -705,6 +705,8 @@ cnpg: main: enabled: false primary: true + # -- Puts the cnpg cluster in hibernation mode + hibernate: false # -- number of instances for both postgres and pgbouncer instances: 2 database: "app" @@ -724,6 +726,7 @@ cnpg: storage: size: "256Gi" walsize: "256Gi" + # -- Gets scaled to 0 if hibernation is true pooler: instances: 2 # -- set to enable prometheus metrics