Skip to content

Commit

Permalink
[cloud-native-pg] Refactor templating for cluster kind. (#423)
Browse files Browse the repository at this point in the history
Co-authored-by: Jozef Volak <[email protected]>
  • Loading branch information
Jozefiel and Jozef Volak authored Sep 17, 2024
1 parent 03c1f7b commit bed19a5
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 60 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/lint-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ jobs:
kubectl -n ct create secret docker-registry regcred --docker-server=https://index.docker.io/v1/ --docker-username=${{ secrets.DOCKERHUB_NAME }} --docker-password=${{ secrets.DOCKERHUB_PASSWORD }} [email protected]
- name: Install operators
if: steps.list-changed.outputs.changed == 'true'
run: |
helm install frinx-machine-operators frinx/frinx-machine-operators
- name: Run chart-testing (install)
if: steps.list-changed.outputs.changed == 'true'
run: ct install --config .github/lint_test_config.yaml --namespace ct
10 changes: 5 additions & 5 deletions charts/cloud-native-pg/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ name: cloud-native-pg
description: A Helm chart for creating postgres cluster via CloudNativePG operator
icon: https://avatars.githubusercontent.com/u/23452093?s=200&v=4
type: application
version: 0.1.0
appVersion: 6.0.0
version: 1.0.0
appVersion: 7.0.0
maintainers:
- name: FRINX
email: [email protected]
url: https://frinx.io
annotations:
artifacthub.io/changes: |
- kind: added
description: Enable cluster podmonitor for monitoring
- kind: changed
description: Refactor templating for cluster kind. Fix argo-cd sync issues
links:
- name: GitHub PR
url: https://github.com/FRINXio/helm-charts/pull/397
url: https://github.com/FRINXio/helm-charts/pull/423
17 changes: 7 additions & 10 deletions charts/cloud-native-pg/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# cloud-native-pg

![Version: 0.1.0](https://img.shields.io/badge/Version-0.1.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 6.0.0](https://img.shields.io/badge/AppVersion-6.0.0-informational?style=flat-square)

A Helm chart for creating postgres cluster via CloudNativePG operator

![Version: 1.0.0](https://img.shields.io/badge/Version-1.0.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 7.0.0](https://img.shields.io/badge/AppVersion-7.0.0-informational?style=flat-square)

## Get Repo Info

```console
Expand All @@ -29,28 +29,24 @@ helm upgrade [RELEASE_NAME] frinx/cloud-native-pg
helm uninstall [RELEASE_NAME]
```

## Maintainers

| Name | Email | Url |
| ---- | ------ | --- |
| FRINX | <[email protected]> | <https://frinx.io> |

## Values

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| affinity | object | `{}` | [Affinity] Defines info about creating affinity rules for pods https://cloudnative-pg.io/documentation/1.18/api_reference/#AffinityConfiguration |
| backup | object | `{}` | [Backup] Cluster backup configuration https://cloudnative-pg.io/documentation/1.18/api_reference/#backupconfiguration |
| bootstrap | object | `{"initdb":{"database":"frinx","owner":"frinx","postInitApplicationSQL":{},"postInitApplicationSQLRefs":{"extraConfigMapRefs":{},"extraSecretRefs":{}},"postInitSQL":{},"postInitTemplateSQL":{}}}` | Bootstrap configuration of cluster |
| bootstrap | object | `{"initdb":{"database":"frinx","owner":"frinx","postInitApplicationSQL":[],"postInitApplicationSQLRefs":null,"postInitSQL":[],"postInitTemplateSQL":[]}}` | Bootstrap configuration of cluster |
| env | object | `{}` | Environmental variables configuration |
| envFrom | object | `{}` | Environmental variables passed from referenced objects |
| imageName | string | `"ghcr.io/cloudnative-pg/postgresql:12.18"` | Image repository with tag |
| imagePullPolicy | string | `"IfNotPresent"` | Image pull policy |
| imagePullSecrets | list | `[]` | [Image Pull Secrets](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/) |
| instances | int | `2` | Number of instances |
| logLevel | string | `"info"` | Logging level configuration |
| monitoring | object | `{"podMonitorEnabled":false}` | Podmonitor configuration |
| monitoring | object | `{"enablePodMonitor":false}` | Podmonitor configuration |
| name | string | `nil` | |
| podAnnotations | object | `{}` | Pod annotations |
| podLabels | object | `{}` | Pod labels |
| postgresql | object | `{"parameters":{"max_connections":"300"}}` | [PostgresConfiguration] Defines the PostgreSQL configuration https://cloudnative-pg.io/documentation/1.18/api_reference/#postgresconfiguration |
| primaryUpdateMethod | string | `"switchover"` | Primary update method configuration |
| primaryUpdateStrategy | string | `"unsupervised"` | Primary update strategy configuration |
Expand All @@ -60,3 +56,4 @@ helm uninstall [RELEASE_NAME]
| startDelay | int | `30` | Start delay configuration |
| stopDelay | int | `30` | Stop delay configuration |
| storage | object | `{"resizeInUseVolumes":true,"size":"1Gi"}` | [StorageConfiguration] Defines PostgreSQL instances storage configuration https://cloudnative-pg.io/documentation/1.18/api_reference/#storageconfiguration |

35 changes: 35 additions & 0 deletions charts/cloud-native-pg/README.md.gotmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{{ template "chart.header" . }}
{{ template "chart.description" . }}

{{ template "chart.versionBadge" . }}{{ template "chart.typeBadge" . }}{{ template "chart.appVersionBadge" . }}

## Get Repo Info

```console
helm repo add frinx https://FRINXio.github.io/helm-charts
helm repo update
```

## Install Chart

```console
helm install [RELEASE_NAME] frinx/{{ template "chart.name" . }}
```

## Upgrading Chart

```console
helm upgrade [RELEASE_NAME] frinx/{{ template "chart.name" . }}
```

## Uninstall Chart

```console
helm uninstall [RELEASE_NAME]
```

{{ template "chart.requirementsSection" . }}

{{ template "chart.valuesSection" . }}

{{ template "helm-docs.versionFooter" . }}
97 changes: 59 additions & 38 deletions charts/cloud-native-pg/templates/postgres-cluster.yaml
Original file line number Diff line number Diff line change
@@ -1,47 +1,60 @@
---
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: {{ include "cloud-native-pg.fullname" . }}
{{- with .Values.podAnnotations }}
annotations:
{{- . | toYaml | nindent 4 }}
{{- end }}

{{- with .Values.podLabels }}
labels:
{{- . | toYaml | nindent 4 }}
{{- end }}
spec:
instances: {{ .Values.instances }}
imageName: {{ .Values.imageName }}
imagePullPolicy: {{ .Values.imagePullPolicy }}
imagePullSecrets: {{ .Values.imagePullSecrets }}
{{- with .Values.imagePullSecrets}}
imagePullSecrets:
{{- . | toYaml | nindent 4 }}
{{- end }}
primaryUpdateStrategy: {{ .Values.primaryUpdateStrategy }}
primaryUpdateMethod: {{ .Values.primaryUpdateMethod }}
logLevel: {{ .Values.logLevel }}

{{- if .Values.startDelay }}
startDelay: {{ .Values.startDelay }}
{{- with .Values.startDelay }}
startDelay: {{ . }}
{{- end }}

{{- if .Values.stopDelay }}
stopDelay: {{ .Values.stopDelay }}
{{- with .Values.stopDelay }}
stopDelay: {{ . }}
{{- end }}

{{- if .Values.replicationSlots }}
{{- with .Values.replicationSlots }}
replicationSlots:
{{- toYaml .Values.replicationSlots | nindent 4 }}
{{- . | toYaml | nindent 4 }}
{{- end }}

{{- if .Values.storage }}
{{- with .Values.storage }}
storage:
{{- toYaml .Values.storage | nindent 4 }}
{{- . | toYaml | nindent 4 }}
{{- end }}

{{- if .Values.resources }}
{{- with .Values.resources }}
resources:
{{- toYaml .Values.resources | nindent 4 }}
{{- . | toYaml | nindent 4 }}
{{- end }}

{{- if .Values.postgresql }}
{{- with .Values.postgresql }}
postgresql:
{{- toYaml .Values.postgresql | nindent 4 }}
{{- . | toYaml | nindent 4 }}
{{- end }}

{{- if .Values.monitoring }}
{{- with .Values.monitoring }}
monitoring:
enablePodMonitor: {{ .Values.monitoring.podMonitorEnabled }}
{{- . | toYaml | nindent 4 }}
{{- end }}

bootstrap:
Expand All @@ -50,52 +63,60 @@ spec:
owner: {{ .Values.bootstrap.initdb.owner }}
secret:
name: {{ include "cloud-native-pg.userSecretName" . }}
{{- if .Values.bootstrap.initdb.postInitSQL }}

{{- with .Values.bootstrap.initdb.postInitSQL }}
postInitSQL:
{{- toYaml .Values.bootstrap.initdb.postInitSQL | nindent 8 }}
{{- . | toYaml | nindent 8 }}
{{- end }}
{{- if .Values.bootstrap.initdb.postInitTemplateSQL }}

{{- with .Values.bootstrap.initdb.postInitTemplateSQL }}
postInitTemplateSQL:
{{- toYaml .Values.bootstrap.initdb.postInitTemplateSQL | nindent 8 }}
{{- . | toYaml | nindent 8 }}
{{- end }}
{{- if .Values.bootstrap.initdb.postInitApplicationSQL }}

{{- with .Values.bootstrap.initdb.postInitApplicationSQL }}
postInitApplicationSQL:
{{- toYaml .Values.bootstrap.initdb.postInitApplicationSQL | nindent 8 }}
{{- end }}
{{- if .Values.bootstrap.initdb.postInitApplicationSQLRefs }}
{{- . | toYaml| nindent 8 }}
{{- end }}

{{- with .Values.bootstrap.initdb.postInitApplicationSQLRefs }}
postInitApplicationSQLRefs:
{{- with .extraConfigMapRefs }}
configMapRefs:
{{- range .Values.bootstrap.initdb.postInitApplicationSQLRefs.extraConfigMapRefs }}
{{- range . }}
- name: {{ .name }}
key: {{ .key }}
{{- end }}
{{- end }}

{{- if or .extraSecretRefs $.Values.secrets.postInitSqlSecret }}
secretRefs:
{{- if .Values.secrets.postInitSqlSecret }}
- name: {{ include "cloud-native-pg.postInitSqlSecretName" . }}
key: secret.sql
{{- with .extraSecretRefs }}
{{- . | toYaml| nindent 10 }}
{{- end }}
{{- range .Values.bootstrap.initdb.postInitApplicationSQLRefs.extraSecretRefs }}
- name: {{- .name }}
key: {{ .key }}
{{- if $.Values.secrets.postInitSqlSecret }}
- name: {{ include "cloud-native-pg.postInitSqlSecretName" $ }}
key: secret.sql
{{- end }}
{{- end }}
{{- end }}
{{- end }}

{{- if .Values.backup }}
{{- with .Values.backup }}
backup:
{{- toYaml .Values.backup | nindent 4 }}
{{- . | toYaml | nindent 4 }}
{{- end }}

{{- if .Values.secrets.superuserSecret }}
superuserSecret:
name: {{ include "cloud-native-pg.superUserSecretName" . }}
{{- end }}

{{- if .Values.env }}
{{- with .Values.env }}
env:
{{- toYaml .Values.env | nindent 4 }}
{{- . | toYaml | nindent 4 }}
{{- end }}

{{- if .Values.envFrom }}
{{- with .Values.envFrom }}
envFrom:
{{- toYaml .Values.envFrom | nindent 4 }}
{{- . | toYaml | nindent 4 }}
{{- end }}
20 changes: 13 additions & 7 deletions charts/cloud-native-pg/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ stopDelay: 30
# -- [ReplicationSlots] Defines encapsulation of the configuration of replication slots
replicationSlots: {}

# -- Pod annotations
podAnnotations: {}

# -- Pod labels
podLabels: {}

# -- [StorageConfiguration] Defines PostgreSQL instances storage configuration https://cloudnative-pg.io/documentation/1.18/api_reference/#storageconfiguration
storage:
size: "1Gi"
Expand Down Expand Up @@ -53,16 +59,16 @@ bootstrap:
owner: frinx
# secret:
# name: frinx-user
postInitSQL: {}
postInitTemplateSQL: {}
postInitApplicationSQL: {}
postInitSQL: []
postInitTemplateSQL: []
postInitApplicationSQL: []
postInitApplicationSQLRefs:
# extraConfigMapRefs holds a list of references to configmaps
# key-value format
extraConfigMapRefs: {}
# extraConfigMapRefs: {}
# extraSecretRefs holds a list of references to secrets
# key-value format
extraSecretRefs: {}
# # key-value format
# extraSecretRefs: {}
# secretRefs:
# - name: cloud-native-pq-post-init-sql-secret
# key: secret.sql
Expand All @@ -72,7 +78,7 @@ backup: {}

# -- Podmonitor configuration
monitoring:
podMonitorEnabled: false
enablePodMonitor: false

# -- Environmental variables configuration
env: {}
Expand Down

0 comments on commit bed19a5

Please sign in to comment.