Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
autodiscovery postgres for pgadmin
Browse files Browse the repository at this point in the history
  • Loading branch information
fcomte committed Feb 8, 2021
1 parent 0a4c41c commit 7df0345
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 28 deletions.
21 changes: 21 additions & 0 deletions charts/pgadmin/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,25 @@ ingress annotations
{{- if .Values.security.whitelist.enable }}
nginx.ingress.kubernetes.io/whitelist-source-range: {{ .Values.security.whitelist.ip }}
{{- end }}
{{- end }}

{{- define "pgadmin.configmap" -}}
{{ printf "{" }}
{{ printf "\"Servers\": {" | indent 2 }}
{{ range $index, $service := (lookup "v1" "Service" .Release.Namespace "").items }}
{{- if hasPrefix "postgres" (index $service "metadata" "labels" "helm.sh/chart") }}
{{ printf "\"%d\" :{" $index | indent 4}}
{{ printf "\"Name\": \"%s\"," $service.metadata.name | indent 6}}
{{ printf "\"Group\": \"Autodiscovery\"," | indent 6}}
{{ printf "\"Port\": %d," (index $service.spec.ports 0).port | indent 6}}
{{ printf "\"Host\": \"%s\"," $service.metadata.name | indent 6}}
{{ printf "\"Username\": \"%s\"," (trimPrefix "user-" $service.metadata.namespace) | indent 6}}
{{ printf "\"SSLMode\": \"prefer\"," | indent 6 }}
{{ printf "\"MaintenanceDB\": \"postgres\"" | indent 6}}
{{ printf "}" | indent 4}}
{{- end }}

{{- end }}
{{ printf "}" | indent 2}}
{{ printf "}" }}
{{- end }}
9 changes: 9 additions & 0 deletions charts/pgadmin/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "pgadmin.fullname" . }}
labels:
{{- include "pgadmin.labels" . | nindent 4 }}
data:
servers.json: |-
{{- include "pgadmin.configmap" . | nindent 4 }}
9 changes: 9 additions & 0 deletions charts/pgadmin/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ spec:
labels:
{{- include "pgadmin.selectorLabels" . | nindent 8 }}
spec:
volumes:
- name: config
configMap:
name: {{ include "pgadmin.fullname" . }}
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
Expand All @@ -45,11 +49,16 @@ spec:
httpGet:
path: /
port: http
volumeMounts:
- name: config
mountPath: "/data"
env:
- name: PGADMIN_DEFAULT_EMAIL
value: {{ .Values.security.mail }}
- name: PGADMIN_DEFAULT_PASSWORD
value: {{ .Values.security.password }}
- name: PGADMIN_SERVER_JSON_FILE
value: "/data/servers.json"
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
Expand Down
28 changes: 0 additions & 28 deletions charts/pgadmin/templates/hpa.yaml

This file was deleted.

12 changes: 12 additions & 0 deletions charts/pgadmin/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@
}
}
}
},
"discovery": {
"description": "configure your service to autodetect some ressources.",
"type": "object",
"properties": {
"postgres": {
"type": "boolean",
"title": "Enable postgres discovery",
"description": "discover your postgres service",
"default": true
}
}
},
"security": {
"description": "security specific configuration",
Expand Down
3 changes: 3 additions & 0 deletions charts/pgadmin/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

replicaCount: 1

discovery:
postgres: true

security:
mail: [email protected]
password: password
Expand Down

0 comments on commit 7df0345

Please sign in to comment.