From 7df0345529bfef7144a59ff9a9f6ede1dacbdbf8 Mon Sep 17 00:00:00 2001 From: tm8enk Date: Mon, 8 Feb 2021 10:24:26 +0000 Subject: [PATCH] autodiscovery postgres for pgadmin --- charts/pgadmin/templates/_helpers.tpl | 21 ++++++++++++++++++ charts/pgadmin/templates/configmap.yaml | 9 ++++++++ charts/pgadmin/templates/deployment.yaml | 9 ++++++++ charts/pgadmin/templates/hpa.yaml | 28 ------------------------ charts/pgadmin/values.schema.json | 12 ++++++++++ charts/pgadmin/values.yaml | 3 +++ 6 files changed, 54 insertions(+), 28 deletions(-) create mode 100644 charts/pgadmin/templates/configmap.yaml delete mode 100644 charts/pgadmin/templates/hpa.yaml diff --git a/charts/pgadmin/templates/_helpers.tpl b/charts/pgadmin/templates/_helpers.tpl index 6a7d43a7..09e7dffd 100644 --- a/charts/pgadmin/templates/_helpers.tpl +++ b/charts/pgadmin/templates/_helpers.tpl @@ -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 }} \ No newline at end of file diff --git a/charts/pgadmin/templates/configmap.yaml b/charts/pgadmin/templates/configmap.yaml new file mode 100644 index 00000000..33db7f72 --- /dev/null +++ b/charts/pgadmin/templates/configmap.yaml @@ -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 }} diff --git a/charts/pgadmin/templates/deployment.yaml b/charts/pgadmin/templates/deployment.yaml index 7bb6dcbe..2bf24f86 100644 --- a/charts/pgadmin/templates/deployment.yaml +++ b/charts/pgadmin/templates/deployment.yaml @@ -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 }} @@ -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 }} diff --git a/charts/pgadmin/templates/hpa.yaml b/charts/pgadmin/templates/hpa.yaml deleted file mode 100644 index 7d4e585b..00000000 --- a/charts/pgadmin/templates/hpa.yaml +++ /dev/null @@ -1,28 +0,0 @@ -{{- if .Values.autoscaling.enabled }} -apiVersion: autoscaling/v2beta1 -kind: HorizontalPodAutoscaler -metadata: - name: {{ include "pgadmin.fullname" . }} - labels: - {{- include "pgadmin.labels" . | nindent 4 }} -spec: - scaleTargetRef: - apiVersion: apps/v1 - kind: Deployment - name: {{ include "pgadmin.fullname" . }} - minReplicas: {{ .Values.autoscaling.minReplicas }} - maxReplicas: {{ .Values.autoscaling.maxReplicas }} - metrics: - {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} - - type: Resource - resource: - name: cpu - targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} - {{- end }} - {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} - - type: Resource - resource: - name: memory - targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} - {{- end }} -{{- end }} diff --git a/charts/pgadmin/values.schema.json b/charts/pgadmin/values.schema.json index 87f76c62..4932e9b4 100644 --- a/charts/pgadmin/values.schema.json +++ b/charts/pgadmin/values.schema.json @@ -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", diff --git a/charts/pgadmin/values.yaml b/charts/pgadmin/values.yaml index 8ce14749..c4fa075a 100644 --- a/charts/pgadmin/values.yaml +++ b/charts/pgadmin/values.yaml @@ -4,6 +4,9 @@ replicaCount: 1 +discovery: + postgres: true + security: mail: example@example.com password: password