Skip to content

Commit d9fc2bb

Browse files
tkcontiantpcallewaert
authored andcommitted
feat: Helm-Chart Support External Secret Operator / feat: support for reload when secret changed
1 parent b438e5d commit d9fc2bb

File tree

6 files changed

+63
-15
lines changed

6 files changed

+63
-15
lines changed

charts/ext-postgres-operator/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ description: |
88
99
type: application
1010

11-
version: 2.1.0
11+
version: 2.1.1
1212
appVersion: "2.0.0"
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{{- if and (.Capabilities.APIVersions.Has "external-secrets.io/v1beta1") (.Values.ExternalSecret) }}
2+
apiVersion: external-secrets.io/v1beta1
3+
kind: ExternalSecret
4+
metadata:
5+
name: {{ include "chart.fullname" . }}-external-secret
6+
namespace: {{ if .Values.ExternalSecret.namespace }}{{ .Values.ExternalSecret.namespace }}{{ else }}{{ .Release.Namespace }}{{ end }}
7+
labels:
8+
{{- include "chart.labels" . | nindent 4 }}
9+
spec:
10+
refreshInterval: {{ .Values.ExternalSecret.refreshInterval | default "2s"}}
11+
secretStoreRef:
12+
kind: {{ .Values.ExternalSecret.secretStoreKind | default "SecretStore" }}
13+
name: {{ .Values.ExternalSecret.secretStore | quote }}
14+
target:
15+
creationPolicy: Owner
16+
deletionPolicy: Retain
17+
name: {{ include "chart.fullname" . }}
18+
template:
19+
data:
20+
POSTGRES_HOST: {{ .Values.postgres.host | quote }}
21+
POSTGRES_USER: "{{ `{{ .username }}` }}"
22+
POSTGRES_PASS: "{{ `{{ .password }}` }}"
23+
POSTGRES_URI_ARGS: {{ .Values.postgres.uri_args | quote }}
24+
POSTGRES_CLOUD_PROVIDER: {{ .Values.postgres.cloud_provider | quote }}
25+
POSTGRES_DEFAULT_DATABASE: {{ .Values.postgres.default_database | quote }}
26+
data:
27+
- secretKey: username
28+
remoteRef:
29+
key: {{ .Values.ExternalSecret.remoteKey | quote }}
30+
property: username
31+
- secretKey: password
32+
remoteRef:
33+
key: {{ .Values.ExternalSecret.remoteKey | quote }}
34+
property: password
35+
{{- end }}

charts/ext-postgres-operator/templates/operator.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ metadata:
77
namespace: {{ .Release.Namespace }}
88
{{- with .Values.deploymentAnnotations }}
99
annotations:
10+
checksum/env_config: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
11+
checksum/env_config: {{ include (print $.Template.BasePath "/external-secret.yaml") . | sha256sum }}
1012
{{- toYaml . | nindent 4 }}
1113
{{- end }}
1214
spec:

charts/ext-postgres-operator/templates/secret.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
{{- if (not .Values.existingSecret) }}
1+
{{- if and (not .Values.existingSecret) (not .Values.ExternalSecret) }}
22
---
33
apiVersion: v1
44
kind: Secret
55
metadata:
66
annotations:
77
"helm.sh/resource-policy": keep
88
name: {{ include "chart.fullname" . }}
9-
namespace: {{ .Release.namespace }}
9+
namespace: {{ .Release.Namespace }}
1010
labels:
1111
{{- include "chart.labels" . | nindent 4 }}
1212
type: Opaque

charts/ext-postgres-operator/templates/serviceaccount.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ metadata:
99
{{- toYaml . | nindent 4 }}
1010
{{- end }}
1111
namespace: {{ .Release.Namespace }}
12-
12+
automountServiceAccountToken: {{ .Values.serviceAccount.automount }}

charts/ext-postgres-operator/values.yaml

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
replicaCount: 1
66

7-
revisionHistoryLimit: 10
7+
revisionHistoryLimit: 3
88

99
image:
1010
repository: ghcr.io/movetokube/postgres-operator
@@ -27,12 +27,13 @@ serviceAccount:
2727
# The name of the service account to use.
2828
# If not set and create is true, a name is generated using the fullname template
2929
name: ""
30+
automount: true
3031

3132
deploymentAnnotations: {}
3233

3334
podAnnotations: {}
3435

35-
# Additionnal labels to add to the pod.
36+
# Additional labels to add to the pod.
3637
podLabels: {}
3738

3839
podSecurityContext:
@@ -45,8 +46,7 @@ securityContext:
4546
drop:
4647
- "ALL"
4748

48-
resources:
49-
{}
49+
resources: {}
5050
# We usually recommend not to specify default resources and to leave this as a conscious
5151
# choice for the user. This also increases chances charts run on environments with little
5252
# resources, such as Minikube. If you do want to specify resources, uncomment the following
@@ -79,11 +79,11 @@ watchNamespace: ""
7979
# Define connection to postgres database server
8080
postgres:
8181
# postgres hostname
82-
host: "localhost"
83-
# postgres admin user and password
84-
user: "admin"
85-
password: "password"
86-
# additional connection args to pg driver
82+
host: "xxxxxxxxxx"
83+
# postgres admin user and password ( ignored if existingSecret or ExternalSecret is set )
84+
user: "XXXXXXXXXX"
85+
password: "XXXXXXXXXX"
86+
# additional connection args to pg driver (Example "sslmode=disable")
8787
uri_args: ""
8888
# postgres cloud provider, could be AWS, Azure, GCP or empty (default)
8989
cloud_provider: ""
@@ -98,10 +98,21 @@ volumeMounts: []
9898

9999
# Existing secret where values to connect to Postgres are defined.
100100
# If not set a new secret will be created, filled with information under the postgres key above.
101+
# If ExternalSecret is set, existingSecret is ignored.
101102
existingSecret: ""
102103

103-
# Additionnal environment variables to add to the pod (map of key / value)
104-
env: {}
104+
# Support for ExternalSecret Operator to fetch Postgres credentials from an external secret store.
105+
ExternalSecret: {}
106+
# secretStore: "aws-secretsmanager-euc1" # (Mandatory) Name of the SecretStore or ClusterSecretStore to reference in the ExternalSecret
107+
# remoteKey: "rds!db-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" # (Mandatory) Remote key in the external secret store where Postgres credentials are stored
108+
# namespace: "" # (Optional), defaults to release namespace
109+
# secretStoreKind: "" # (Optional), defaults to SecretStore / SecretStore or ClusterSecretStore
110+
# refreshInterval: "2s" # (Optional), defaults to SecretStore / SecretStore or ClusterSecretStore
111+
112+
# Additional environment variables to add to the pod (map of key / value)
113+
env:
114+
POSTGRES_INSTANCE: "XXXXXXXXXX"
115+
# POSTGRES_CLOUD_PROVIDER: "AWS"
105116

106117
nodeSelector: {}
107118

0 commit comments

Comments
 (0)