diff --git a/charts/pgadmin4/Chart.yaml b/charts/pgadmin4/Chart.yaml index 760fccb5..e831ae4e 100644 --- a/charts/pgadmin4/Chart.yaml +++ b/charts/pgadmin4/Chart.yaml @@ -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 diff --git a/charts/pgadmin4/README.md b/charts/pgadmin4/README.md index 53e5e359..287db1fc 100644 --- a/charts/pgadmin4/README.md +++ b/charts/pgadmin4/README.md @@ -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` | @@ -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 | `chart@domain.com` | diff --git a/charts/pgadmin4/templates/NOTES.txt b/charts/pgadmin4/templates/NOTES.txt index 67b0bdcb..88fede24 100644 --- a/charts/pgadmin4/templates/NOTES.txt +++ b/charts/pgadmin4/templates/NOTES.txt @@ -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 }} @@ -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" . }} diff --git a/charts/pgadmin4/templates/_helpers.tpl b/charts/pgadmin4/templates/_helpers.tpl index d58687b8..42488dbd 100644 --- a/charts/pgadmin4/templates/_helpers.tpl +++ b/charts/pgadmin4/templates/_helpers.tpl @@ -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 }} diff --git a/charts/pgadmin4/templates/deployment.yaml b/charts/pgadmin4/templates/deployment.yaml index b1c17773..e3f397e9 100644 --- a/charts/pgadmin4/templates/deployment.yaml +++ b/charts/pgadmin4/templates/deployment.yaml @@ -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 }} @@ -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 }} @@ -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 }} @@ -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: diff --git a/charts/pgadmin4/templates/server-definitions-configmap.yaml b/charts/pgadmin4/templates/server-definitions-configmap.yaml index 3245d1ee..1a52c875 100644 --- a/charts/pgadmin4/templates/server-definitions-configmap.yaml +++ b/charts/pgadmin4/templates/server-definitions-configmap.yaml @@ -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: @@ -10,3 +11,4 @@ data: servers.json: |- {{ include "pgadmin.serverDefinitions" . | indent 4 }} {{- end }} +{{- end }} diff --git a/charts/pgadmin4/templates/server-definitions-secret.yaml b/charts/pgadmin4/templates/server-definitions-secret.yaml index 13768e0f..ebacf64c 100644 --- a/charts/pgadmin4/templates/server-definitions-secret.yaml +++ b/charts/pgadmin4/templates/server-definitions-secret.yaml @@ -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: diff --git a/charts/pgadmin4/values.yaml b/charts/pgadmin4/values.yaml index 71e9a28f..3615b5b5 100644 --- a/charts/pgadmin4/values.yaml +++ b/charts/pgadmin4/values.yaml @@ -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"