Skip to content

Commit d7bed55

Browse files
Context Flow (#36)
* Add context-flow-db Helm chart with PostgreSQL configuration and templates * Update kube/context-flow-db/templates/manual-backup.yaml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Phelipe Rocha <phelipeafonso@gmail.com> * Update kube/context-flow-db/templates/manual-backup.yaml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Phelipe Rocha <phelipeafonso@gmail.com> * Update kube/context-flow-db/Chart.yaml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Phelipe Rocha <phelipeafonso@gmail.com> * Add context-flow Helm chart with deployment, service, and ingress configurations * Update kube/context-flow-db/templates/networkpolicy.yaml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Phelipe Rocha <phelipeafonso@gmail.com> * Update container images in deployment and job templates to use values from values.yaml * Update kube/context-flow/Chart.yaml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Phelipe Rocha <phelipeafonso@gmail.com> * Update kube/context-flow/templates/ingress.yaml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Phelipe Rocha <phelipeafonso@gmail.com> --------- Signed-off-by: Phelipe Rocha <phelipeafonso@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 5c84c67 commit d7bed55

20 files changed

+616
-0
lines changed

helmfile.yaml.gotmpl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,19 @@ releases:
101101
- ./kube/values.yaml
102102
secrets:
103103
- ./kube/secrets.yaml
104+
105+
- name: context-flow
106+
namespace: context-flow
107+
chart: ./kube/context-flow
108+
version: 1.0.0
109+
values:
110+
- ./kube/values.yaml
111+
112+
- name: context-flow-db
113+
namespace: context-flow
114+
chart: ./kube/context-flow-db
115+
version: 1.0.0
116+
values:
117+
- ./kube/values.yaml
118+
secrets:
119+
- ./kube/secrets.yaml

kube/context-flow-db/Chart.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: v2
2+
name: context-flow-db
3+
description: Context Flow Database (CloudNative-PG)
4+
type: application
5+
version: 1.0.0
6+
appVersion: "18.1"
7+
kubeVersion: "^1.20.0"
8+
sources:
9+
- https://github.com/pheliperocha/home-server
10+
maintainers:
11+
- name: Phelipe Rocha
12+
url: https://pheliperocha.com
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "context-flow-db.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
*/}}
11+
{{- define "context-flow-db.fullname" -}}
12+
{{- if .Values.fullnameOverride }}
13+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
14+
{{- else }}
15+
{{- $name := default .Chart.Name .Values.nameOverride }}
16+
{{- if contains $name .Release.Name }}
17+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
18+
{{- else }}
19+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
20+
{{- end }}
21+
{{- end }}
22+
{{- end }}
23+
24+
{{/*
25+
Create chart name and version as used by the chart label.
26+
*/}}
27+
{{- define "context-flow-db.chart" -}}
28+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
29+
{{- end }}
30+
31+
{{/*
32+
Common labels
33+
*/}}
34+
{{- define "context-flow-db.labels" -}}
35+
helm.sh/chart: {{ include "context-flow-db.chart" . }}
36+
{{ include "context-flow-db.selectorLabels" . }}
37+
{{- if .Chart.AppVersion }}
38+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
39+
{{- end }}
40+
app.kubernetes.io/managed-by: {{ .Release.Service }}
41+
{{- end }}
42+
43+
{{/*
44+
Selector labels
45+
*/}}
46+
{{- define "context-flow-db.selectorLabels" -}}
47+
app.kubernetes.io/name: {{ include "context-flow-db.name" . }}
48+
app.kubernetes.io/instance: {{ .Release.Name }}
49+
{{- end }}
50+
51+
{{/*
52+
Cluster name
53+
*/}}
54+
{{- define "context-flow-db.clusterName" -}}
55+
{{- printf "context-flow-db" }}
56+
{{- end }}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{{- if .Values.context_flow_db.enabled }}
2+
apiVersion: postgresql.cnpg.io/v1
3+
kind: Cluster
4+
metadata:
5+
name: {{ include "context-flow-db.clusterName" . }}
6+
namespace: context-flow
7+
labels:
8+
{{- include "context-flow-db.labels" . | nindent 4 }}
9+
spec:
10+
instances: {{ .Values.context_flow_db.cluster.instances }}
11+
12+
imageName: ghcr.io/cloudnative-pg/postgresql:18.1
13+
14+
bootstrap:
15+
initdb:
16+
database: {{ .Values.context_flow_db.database.name }}
17+
owner: app
18+
encoding: UTF8
19+
localeCType: en_US.UTF-8
20+
localeCollate: en_US.UTF-8
21+
22+
storage:
23+
size: {{ .Values.context_flow_db.cluster.storage.size }}
24+
{{- if .Values.context_flow_db.cluster.storage.storageClass }}
25+
storageClass: {{ .Values.context_flow_db.cluster.storage.storageClass }}
26+
{{- end }}
27+
28+
resources:
29+
requests:
30+
memory: {{ .Values.context_flow_db.cluster.resources.requests.memory | quote }}
31+
cpu: {{ .Values.context_flow_db.cluster.resources.requests.cpu | quote }}
32+
limits:
33+
memory: {{ .Values.context_flow_db.cluster.resources.limits.memory | quote }}
34+
cpu: {{ .Values.context_flow_db.cluster.resources.limits.cpu | quote }}
35+
36+
postgresql:
37+
parameters:
38+
{{- range $key, $value := .Values.context_flow_db.cluster.postgresql.parameters }}
39+
{{ $key }}: {{ $value | quote }}
40+
{{- end }}
41+
42+
monitoring:
43+
enablePodMonitor: true
44+
45+
{{- if .Values.context_flow_db.backup.enabled }}
46+
backup:
47+
barmanObjectStore:
48+
destinationPath: "s3://{{ .Values.context_flow_db.backup.s3.bucket }}{{ .Values.context_flow_db.backup.s3.path }}"
49+
endpointURL: {{ .Values.context_flow_db.backup.s3.endpointURL }}
50+
s3Credentials:
51+
accessKeyId:
52+
name: {{ .Values.context_flow_db.backup.s3.credentialsSecretName }}
53+
key: AWS_ACCESS_KEY_ID
54+
secretAccessKey:
55+
name: {{ .Values.context_flow_db.backup.s3.credentialsSecretName }}
56+
key: AWS_SECRET_ACCESS_KEY
57+
wal:
58+
compression: gzip
59+
encryption: AES256
60+
data:
61+
compression: gzip
62+
encryption: AES256
63+
retentionPolicy: {{ .Values.context_flow_db.backup.retentionPolicy | quote }}
64+
{{- end }}
65+
{{- end }}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{{- if and .Values.context_flow_db.enabled .Values.context_flow_db.backup.enabled .Values.context_flow_db.backup.manualBackup.enabled }}
2+
apiVersion: postgresql.cnpg.io/v1
3+
kind: Backup
4+
metadata:
5+
name: cnpg-manual-backup{{- if .Values.context_flow_db.backup.manualBackup.suffix }}-{{ .Values.context_flow_db.backup.manualBackup.suffix }}{{- end }}
6+
namespace: context-flow
7+
spec:
8+
cluster:
9+
name: {{ include "context-flow-db.clusterName" . }}
10+
{{- end }}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{{- if and .Values.context_flow_db.enabled .Values.context_flow_db.networkPolicy.enabled }}
2+
apiVersion: networking.k8s.io/v1
3+
kind: NetworkPolicy
4+
metadata:
5+
name: {{ include "context-flow-db.clusterName" . }}-netpol
6+
namespace: context-flow
7+
labels:
8+
{{- include "context-flow-db.labels" . | nindent 4 }}
9+
spec:
10+
podSelector:
11+
matchLabels:
12+
cnpg.io/cluster: {{ include "context-flow-db.clusterName" . }}
13+
policyTypes:
14+
- Ingress
15+
ingress:
16+
{{- if .Values.context_flow_db.networkPolicy.allowSameNamespace }}
17+
# Allow connections from pods in the same namespace
18+
- from:
19+
- podSelector: {}
20+
ports:
21+
- protocol: TCP
22+
port: 5432
23+
{{- end }}
24+
# Allow connections from CloudNative-PG operator
25+
- from:
26+
- namespaceSelector:
27+
matchLabels:
28+
kubernetes.io/metadata.name: cloudnative-pg-system
29+
ports:
30+
- protocol: TCP
31+
port: 5432
32+
- protocol: TCP
33+
port: 8000
34+
{{- end }}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{{- if and .Values.context_flow_db.enabled .Values.context_flow_db.backup.enabled }}
2+
apiVersion: postgresql.cnpg.io/v1
3+
kind: ScheduledBackup
4+
metadata:
5+
name: {{ include "context-flow-db.clusterName" . }}-backup
6+
namespace: context-flow
7+
labels:
8+
{{- include "context-flow-db.labels" . | nindent 4 }}
9+
spec:
10+
schedule: {{ .Values.context_flow_db.backup.schedule | quote }}
11+
backupOwnerReference: self
12+
cluster:
13+
name: {{ include "context-flow-db.clusterName" . }}
14+
method: barmanObjectStore
15+
immediate: false
16+
{{- end }}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{{- if .Values.context_flow_db.enabled }}
2+
apiVersion: v1
3+
kind: Service
4+
metadata:
5+
name: {{ .Values.context_flow_db.service.name }}
6+
namespace: context-flow
7+
labels:
8+
{{- include "context-flow-db.labels" . | nindent 4 }}
9+
spec:
10+
type: {{ .Values.context_flow_db.service.type }}
11+
ports:
12+
- name: postgres
13+
port: {{ .Values.context_flow_db.service.port }}
14+
targetPort: 5432
15+
protocol: TCP
16+
selector:
17+
cnpg.io/cluster: {{ include "context-flow-db.clusterName" . }}
18+
role: primary
19+
{{- end }}

kube/context-flow-db/values.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
context_flow_db:
2+
enabled: true
3+
4+
database:
5+
name: context_flow
6+
7+
cluster:
8+
instances: 1
9+
10+
resources:
11+
requests:
12+
memory: "1Gi"
13+
cpu: "500m"
14+
limits:
15+
memory: "2Gi"
16+
cpu: "1000m"
17+
18+
storage:
19+
size: 10Gi
20+
storageClass: "" # Use cluster default
21+
22+
postgresql:
23+
parameters:
24+
max_connections: "100"
25+
shared_buffers: "256MB"
26+
effective_cache_size: "1GB"
27+
maintenance_work_mem: "64MB"
28+
checkpoint_completion_target: "0.9"
29+
wal_buffers: "16MB"
30+
default_statistics_target: "100"
31+
random_page_cost: "1.1"
32+
effective_io_concurrency: "200"
33+
work_mem: "2621kB"
34+
min_wal_size: "1GB"
35+
max_wal_size: "4GB"
36+
37+
backup:
38+
enabled: false
39+
schedule: "0 2 * * *" # Daily at 2 AM
40+
retentionPolicy: "30d"
41+
s3:
42+
endpointURL: "https://s3.sa-east-1.amazonaws.com"
43+
bucket: "context-flow-backups"
44+
path: "/cnpg-production"
45+
credentialsSecretName: "aws-secrets"
46+
manualBackup:
47+
enabled: false
48+
suffix: ""
49+
50+
service:
51+
name: "pg-context-flow-db"
52+
type: ClusterIP
53+
port: 5432
54+
55+
networkPolicy:
56+
enabled: true
57+
# Only allow connections from pods in the same namespace
58+
allowSameNamespace: true

kube/context-flow/Chart.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v2
2+
name: context-flow
3+
description: Helm chart for context-flow
4+
type: application
5+
version: 1.0.0
6+
appVersion: "1.0.0"
7+
kubeVersion: "^1.20.0"
8+
maintainers:
9+
- name: Phelipe Rocha
10+
url: https://pheliperocha.com

0 commit comments

Comments
 (0)