Skip to content

Commit

Permalink
[pgadmin4] Be able to define existingSecret or existingConfigmap cont…
Browse files Browse the repository at this point in the history
…aining serverDefinitions (#249)

Signed-off-by: Alex Hofmann <[email protected]>
  • Loading branch information
alexhfmnn authored Apr 22, 2024
1 parent a659e47 commit 309425d
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 14 deletions.
2 changes: 1 addition & 1 deletion charts/pgadmin4/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v1
description: pgAdmin4 is a web based administration tool for PostgreSQL database
name: pgadmin4
version: 1.24.1
version: 1.25.0
appVersion: "8.5"
keywords:
- pgadmin
Expand Down
4 changes: 3 additions & 1 deletion charts/pgadmin4/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ The command removes nearly all the Kubernetes components associated with the cha
| `strategy` | Specifies the strategy used to replace old Pods by new ones | `{}` |
| `serverDefinitions.enabled` | Enables Server Definitions | `false` |
| `serverDefinitions.resourceType` | The type of resource to deploy server definitions (either `ConfigMap` or `Secret`) | `ConfigMap` |
| `serverDefinitions.existingConfigmap` | The name of a configMap containing Server Definitions. Only used when `serverDefinitions.resourceType` is `ConfigMap` | `""` |
| `serverDefinitions.existingSecret` | The name of a Secret containing Server Definitions. Only used when `serverDefinitions.resourceType` is `Secret` | `""` |
| `serverDefinitions.servers` | Pre-configured server parameters | `{}` |
| `networkPolicy.enabled` | Enables Network Policy | `true` |
| `ingress.enabled` | Enables Ingress | `false` |
Expand All @@ -79,7 +81,7 @@ The command removes nearly all the Kubernetes components associated with the cha
| `extraConfigmapMounts` | Additional configMap volume mounts for pgadmin4 pod | `[]` |
| `extraSecretMounts` | Additional secret volume mounts for pgadmin4 pod | `[]` |
| `extraContainers` | Sidecar containers to add to the pgadmin4 pod | `"[]"` |
| `existingSecret` | The name of an existing secret containing the pgadmin4 default password. | `""` |
| `existingSecret` | The name of an existing secret containing the pgadmin4 default password and, optionally, Server Definitions. | `""` |
| `secretKeys.pgadminPasswordKey` | Name of key in existing secret to use for default pgadmin credentials. Only used when `existingSecret` is set. | `"password"` |
| `extraInitContainers` | Sidecar init containers to add to the pgadmin4 pod | `"[]"` |
| `env.email` | pgAdmin4 default email. Needed chart reinstall for apply changes | `[email protected]` |
Expand Down
6 changes: 6 additions & 0 deletions charts/pgadmin4/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
CHART NAME: {{ .Chart.Name }}
CHART VERSION: {{ .Chart.Version }}
APP VERSION: {{ .Chart.AppVersion }}

1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
Expand All @@ -19,3 +23,5 @@
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl port-forward $POD_NAME 8080:80
{{- end }}

{{- include "pgadmin.validateValues" . }}
71 changes: 71 additions & 0 deletions charts/pgadmin4/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,74 @@ Create the name of the namespace
{{- define "pgadmin.namespaceName" -}}
{{- default .Release.Namespace .Values.namespace }}
{{- end }}

{{/*
Generate serverDefinitions configMap name
*/}}
{{- define "pgadmin.serverDefinitionsConfigmap" -}}
{{- if eq .Values.serverDefinitions.resourceType "ConfigMap" -}}
{{- if .Values.serverDefinitions.existingConfigmap }}
{{- printf "%s" (.Values.serverDefinitions.existingConfigmap) }}
{{- else }}
{{- include "pgadmin.fullname" . }}-server-definitions
{{- end }}
{{- end }}
{{- end }}

{{/*
Generate serverDefinitions secret name
*/}}
{{- define "pgadmin.serverDefinitionsSecret" -}}
{{- if eq .Values.serverDefinitions.resourceType "Secret" -}}
{{- if .Values.serverDefinitions.existingSecret }}
{{- printf "%s" (.Values.serverDefinitions.existingSecret) }}
{{- else if .Values.existingSecret }}
{{- printf "%s" (.Values.existingSecret) }}
{{- else }}
{{- include "pgadmin.fullname" . }}-server-definitions
{{- end }}
{{- end }}
{{- end }}

{{/*
Compile all warnings into a single message.
*/}}
{{- define "pgadmin.validateValues" -}}
{{- $messages := list -}}
{{- $messages := append $messages (include "pgadmin.validateValues.serverDefinitionsType" .) -}}
{{- $messages := append $messages (include "pgadmin.validateValues.serverDefinitionsContent" .) -}}
{{- $messages := without $messages "" -}}
{{- $message := join "\n" $messages -}}

{{- if $message -}}
{{- printf "\nVALUES VALIDATION:\n%s" $message | fail -}}
{{- end -}}
{{- end -}}

{{/*
Verify serverDefinitions.resourceType
*/}}
{{- define "pgadmin.validateValues.serverDefinitionsType" -}}
{{- $allowedResourceTypes := list "ConfigMap" "Secret" -}}
{{- if .Values.serverDefinitions.enabled -}}
{{- if not (has .Values.serverDefinitions.resourceType $allowedResourceTypes) -}}
pgadmin: serverDefinitions.resourceType
Invalid value for '.Values.serverDefinitions.resourceType'. Allowed values are either ConfigMap or Secret.
{{- end }}
{{- end }}
{{- end }}

{{/*
Verify serverDefinitions.content
*/}}
{{- define "pgadmin.validateValues.serverDefinitionsContent" -}}
{{- if .Values.serverDefinitions.enabled -}}
{{- if and (eq .Values.serverDefinitions.resourceType "ConfigMap") (not .Values.serverDefinitions.servers) (not .Values.serverDefinitions.existingConfigmap) -}}
pgadmin: serverDefinitions.servers
One of '.Values.serverDefinitions.servers' or '.Values.serverDefinitions.existingConfigmap' must be defined.
{{- else if and (eq .Values.serverDefinitions.resourceType "Secret") (not .Values.serverDefinitions.servers) (not .Values.serverDefinitions.existingSecret) (not .Values.existingSecret) -}}
pgadmin: serverDefinitions.servers
One of '.Values.serverDefinitions.servers', '.Values.serverDefinitions.existingSecret' or '.Values.existingSecret' must be defined.
{{- end }}
{{- end }}
{{- end }}
24 changes: 15 additions & 9 deletions charts/pgadmin4/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ spec:
checksum/secret: {{ include (print $.Template.BasePath "/auth-secret.yaml") . | sha256sum }}
{{- end }}
{{- end }}

spec:
{{- if .Values.serviceAccount.create }}
serviceAccountName: {{ default $fullName .Values.serviceAccount.name }}
Expand Down Expand Up @@ -157,10 +156,12 @@ spec:
- name: SCRIPT_NAME
value: {{ .Values.env.contextPath }}
{{- end }}
{{- if .Values.serverDefinitions.enabled }}
{{- if and (.Values.serverDefinitions.enabled) (or (eq .Values.serverDefinitions.resourceType "ConfigMap") (eq .Values.serverDefinitions.resourceType "Secret")) -}}
{{- if or (.Values.serverDefinitions.existingConfigmap) (.Values.serverDefinitions.existingSecret) (.Values.existingSecret) (.Values.serverDefinitions.servers) }}
- name: PGADMIN_SERVER_JSON_FILE
value: /pgadmin4/servers.json
{{- end }}
{{- end }}
{{- range .Values.env.variables }}
- name: {{ .name | quote }}
value: {{ .value | quote }}
Expand All @@ -180,11 +181,13 @@ spec:
- name: pgadmin-data
mountPath: /var/lib/pgadmin
subPath: {{ .Values.persistentVolume.subPath | default "" }}
{{- if .Values.serverDefinitions.enabled }}
{{- if and (.Values.serverDefinitions.enabled) (or (eq .Values.serverDefinitions.resourceType "ConfigMap") (eq .Values.serverDefinitions.resourceType "Secret")) -}}
{{- if or (.Values.serverDefinitions.existingConfigmap) (.Values.serverDefinitions.existingSecret) (.Values.existingSecret) (.Values.serverDefinitions.servers) }}
- name: definitions
mountPath: /pgadmin4/servers.json
subPath: servers.json
{{- end }}
{{- end }}
{{- range .Values.extraConfigmapMounts }}
- name: {{ .name }}
mountPath: {{ .mountPath }}
Expand Down Expand Up @@ -228,18 +231,21 @@ spec:
{{- if .Values.extraVolumes }}
{{- .Values.extraVolumes | toYaml | nindent 8 }}
{{- end }}
{{- if .Values.serverDefinitions.enabled }}
{{- if and (.Values.serverDefinitions.enabled) (eq .Values.serverDefinitions.resourceType "Secret") -}}
{{- if or (.Values.serverDefinitions.existingSecret) (.Values.existingSecret) (.Values.serverDefinitions.servers) }}
- name: definitions
{{- if eq .Values.serverDefinitions.resourceType "Secret" }}
secret:
secretName: {{ $fullName }}-server-definitions
{{- else }}
secretName: {{ include "pgadmin.serverDefinitionsSecret" . }}
{{- end }}
{{- else if and (.Values.serverDefinitions.enabled) (eq .Values.serverDefinitions.resourceType "ConfigMap") -}}
{{ if or (.Values.serverDefinitions.existingConfigmap) (.Values.serverDefinitions.servers) }}
- name: definitions
configMap:
name: {{ $fullName }}-server-definitions
{{- end }}
name: {{ include "pgadmin.serverDefinitionsConfigmap" . }}
items:
- key: servers.json
path: servers.json
{{- end }}
{{- end }}
{{- if .Values.imagePullSecrets }}
imagePullSecrets:
Expand Down
4 changes: 3 additions & 1 deletion charts/pgadmin4/templates/server-definitions-configmap.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{- if and .Values.serverDefinitions.enabled ( ne .Values.serverDefinitions.resourceType "Secret" ) }}
{{- if not .Values.serverDefinitions.existingConfigmap -}}
{{- if and (.Values.serverDefinitions.enabled) (eq .Values.serverDefinitions.resourceType "ConfigMap") (.Values.serverDefinitions.servers) }}
apiVersion: v1
kind: ConfigMap
metadata:
Expand All @@ -10,3 +11,4 @@ data:
servers.json: |-
{{ include "pgadmin.serverDefinitions" . | indent 4 }}
{{- end }}
{{- end }}
4 changes: 2 additions & 2 deletions charts/pgadmin4/templates/server-definitions-secret.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- if not .Values.existingSecret }}
{{- if and .Values.serverDefinitions.enabled ( eq .Values.serverDefinitions.resourceType "Secret" ) }}
{{- if and (not .Values.serverDefinitions.existingSecret) (not .Values.existingSecret) -}}
{{- if and (.Values.serverDefinitions.enabled) ( eq .Values.serverDefinitions.resourceType "Secret") (.Values.serverDefinitions.servers) }}
apiVersion: v1
kind: Secret
metadata:
Expand Down
6 changes: 6 additions & 0 deletions charts/pgadmin4/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ serverDefinitions:
## Can either be ConfigMap or Secret
resourceType: ConfigMap

# If resource type is set to ConfigMap, specify existingConfigmap containing definitions
existingConfigmap: ""

# If resource type is set to Secret, specify existingSecret containing definitions
existingSecret: ""

servers:
# firstServer:
# Name: "Minimally Defined Server"
Expand Down

0 comments on commit 309425d

Please sign in to comment.