Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for existing K8s secret for Database #107

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.

## Added
- Option to override Relay external host in config from [plejik](https://github.com/plejik)
- Option to provide existing Kubernetes secret for Database credentials

### Changed
- Updated Kubernetes labels from [nlamirault](https://github.com/nlamirault)
Expand Down
1 change: 1 addition & 0 deletions charts/ztka/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ helm show values paralus/ztka
| deploy.postgresql.database | string | `""` | Postgresql database name. Required when `deploy.postgresql.enable` is unset and dsn is not specified. |
| deploy.postgresql.dsn | string | `""` | Postgresql DSN for example, "postgres://user:password@host:5432/db". Required when `deploy.postgresql.enable` is unset and individual components are not specified. Overrides individual components (address, username, password, database) |
| deploy.postgresql.enable | bool | `false` | Postgresql db is auto deployed and managed by Helm release when true. (It is recommended to manage your own DB instance separately or use DB services like Amazon RDS in production) |
| deploy.postgresql.existingSecret | string | `""` | Postgresql existing Kubernetes secret for database authentication. Overwrites `deploy.postgresql.dsn`, `deploy.postgresql.address`, `deploy.postgresql.username`, `deploy.postgresql.password` and `deploy.postgresql.database` The Kubernetes secret must contain all values it overrides |
| deploy.postgresql.password | string | `""` | Postgresql password. Required when `deploy.postgresql.enable` is unset and dsn is not specified. |
| deploy.postgresql.username | string | `""` | Postgresql username. Required when `deploy.postgresql.enable` is unset and dsn is not specified. |
| elasticsearch.minimumMasterNodes | int | `1` | |
Expand Down
10 changes: 10 additions & 0 deletions charts/ztka/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ Get DB Address.
{{- define "ztka.dbAddr" -}}
{{- if .Values.deploy.postgresql.enable -}}
{{.Release.Name}}-postgresql.{{.Release.Namespace}}.svc.cluster.local
{{- else if .Values.deploy.postgresql.existingSecret -}}
{{- printf "%s" (tpl .Values.deploy.postgresql.existingSecret $) -}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is returning existing secret name, but instead we are expecting db address.

Need to fetch db address from k8s secret.

{{- else if empty .Values.deploy.postgresql.dsn -}}
{{ required "A valid .Values.deploy.postgresql.address entry required!" .Values.deploy.postgresql.address }}
{{- end -}}
Expand All @@ -114,6 +116,8 @@ Get DB Username.
{{- define "ztka.dbUser" -}}
{{- if .Values.deploy.postgresql.enable -}}
{{.Values.postgresql.auth.username}}
{{- else if .Values.deploy.postgresql.existingSecret -}}
{{- printf "%s" (tpl .Values.deploy.postgresql.existingSecret $) -}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

{{- else if empty .Values.deploy.postgresql.dsn -}}
{{ required "A valid .Values.deploy.postgresql.username entry required!" .Values.deploy.postgresql.username }}
{{- end -}}
Expand All @@ -125,6 +129,8 @@ Get DB Password.
{{- define "ztka.dbPassword" -}}
{{- if .Values.deploy.postgresql.enable -}}
{{.Values.postgresql.auth.password}}
{{- else if .Values.deploy.postgresql.existingSecret -}}
{{- printf "%s" (tpl .Values.deploy.postgresql.existingSecret $) -}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

{{- else if empty .Values.deploy.postgresql.dsn -}}
{{ required "A valid .Values.deploy.postgresql.password entry required!" .Values.deploy.postgresql.password }}
{{- end -}}
Expand All @@ -136,6 +142,8 @@ Get DB Name.
{{- define "ztka.dbName" -}}
{{- if .Values.deploy.postgresql.enable -}}
{{.Values.postgresql.auth.database}}
{{- else if .Values.deploy.postgresql.existingSecret -}}
{{- printf "%s" (tpl .Values.deploy.postgresql.existingSecret $) -}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

{{- else if empty .Values.deploy.postgresql.dsn -}}
{{ required "A valid .Values.deploy.postgresql.database entry required!" .Values.deploy.postgresql.database }}
{{- end -}}
Expand All @@ -149,6 +157,8 @@ Get DSN
postgres://{{ .Values.postgresql.auth.username }}:{{ .Values.postgresql.auth.password }}@{{.Release.Name}}-postgresql.{{.Release.Namespace}}.svc.cluster.local:5432/{{ .Values.postgresql.auth.database }}?sslmode=disable
{{- else if .Values.deploy.postgresql.dsn -}}
{{ .Values.deploy.postgresql.dsn }}
{{- else if .Values.deploy.postgresql.existingSecret -}}
{{- printf "%s" (tpl .Values.deploy.postgresql.existingSecret $) -}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

{{- else -}}
{{- $username := required "A valid .Values.deploy.postgresql.username entry required!" .Values.deploy.postgresql.username -}}
{{- $password := required "A valid .Values.deploy.postgresql.password entry required!" .Values.deploy.postgresql.password -}}
Expand Down
16 changes: 16 additions & 0 deletions charts/ztka/templates/deployment-paralus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ spec:
- name: DSN
valueFrom:
secretKeyRef:
{{- if .Values.deploy.postgresql.existingSecret }}
name: {{ .Values.deploy.postgresql.existingSecret }}
{{- else }}
name: paralus-db
{{- end }}
key: DSN
imagePullPolicy: {{ .Values.images.pullPolicy }}
{{- end }}
Expand All @@ -58,7 +62,11 @@ spec:
- name: DSN
valueFrom:
secretKeyRef:
{{- if .Values.deploy.postgresql.existingSecret }}
name: {{ .Values.deploy.postgresql.existingSecret }}
{{- else }}
name: paralus-db
{{- end }}
key: DSN
imagePullPolicy: {{ .Values.images.pullPolicy }}
{{- end }}
Expand All @@ -79,7 +87,11 @@ spec:
- configMapRef:
name: paralus-config
- secretRef:
{{- if .Values.deploy.postgresql.existingSecret }}
name: {{ .Values.deploy.postgresql.existingSecret }}
{{- else}}
name: paralus-db
{{- end }}
imagePullPolicy: {{ .Values.images.pullPolicy }}
containers:
- name: paralus-tail
Expand All @@ -104,7 +116,11 @@ spec:
- configMapRef:
name: paralus-config
- secretRef:
{{- if .Values.deploy.postgresql.existingSecret }}
name: {{ .Values.deploy.postgresql.existingSecret }}
{{- else }}
name: paralus-db
{{- end }}
ports:
{{- range .Values.services.paralus.ports }}
- name: {{ .name }}
Expand Down
4 changes: 4 additions & 0 deletions charts/ztka/templates/deployment-prompt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ spec:
- configMapRef:
name: prompt-config
- secretRef:
{{- if .Values.deploy.postgresql.existingSecret }}
name: {{ .Values.deploy.postgresql.existingSecret }}
{{- else }}
name: paralus-db
{{- end }}
ports:
{{- range .Values.services.prompt.ports }}
- name: {{ .name }}
Expand Down
2 changes: 2 additions & 0 deletions charts/ztka/templates/secret-database.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if not .Values.deploy.postgresql.existingSecret }}
apiVersion: v1
kind: Secret
metadata:
Expand All @@ -12,3 +13,4 @@ data:
DB_PASSWORD: {{ include "ztka.dbPassword" . | b64enc | quote }}
DB_NAME: {{ include "ztka.dbName" . | b64enc | quote }}
DSN: {{ include "ztka.dsn" . | b64enc | quote }}
{{- end }}
5 changes: 5 additions & 0 deletions charts/ztka/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ deploy:
# when true. (It is recommended to manage your own DB instance
# separately or use DB services like Amazon RDS in production)
enable: false
# -- Postgresql existing Kubernetes secret for database authentication.
# Overwrites `deploy.postgresql.dsn`, `deploy.postgresql.address`,
# `deploy.postgresql.username`, `deploy.postgresql.password` and `deploy.postgresql.database`
# The Kubernetes secret must contain all values it overrides
existingSecret: ""
# -- Postgresql DSN for example, "postgres://user:password@host:5432/db". Required
# when `deploy.postgresql.enable` is unset and individual components are not specified.
# Overrides individual components (address, username, password, database)
Expand Down
Loading