Skip to content

Commit

Permalink
update / template labels / use appVersion as tag (#3692)
Browse files Browse the repository at this point in the history
Signed-off-by: André Bauer <[email protected]>
  • Loading branch information
monotek authored Aug 15, 2023
1 parent 5aad33e commit b5519f4
Show file tree
Hide file tree
Showing 16 changed files with 103 additions and 461 deletions.
4 changes: 2 additions & 2 deletions charts/prometheus-postgres-exporter/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apiVersion: v2
appVersion: "0.13.1"
appVersion: "v0.13.2"
description: A Helm chart for prometheus postgres-exporter
name: prometheus-postgres-exporter
version: 4.8.0
version: 5.0.0
home: https://github.com/prometheus-community/postgres_exporter
sources:
- https://github.com/prometheus-community/postgres_exporter
Expand Down
10 changes: 10 additions & 0 deletions charts/prometheus-postgres-exporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ _See [helm uninstall](https://helm.sh/docs/helm/helm_uninstall/) for command doc

## Upgrading

### To 5.0.0

Deprecated options `auto-discover-databases`, `constantLabels`, `exclude-databases` & `include-databases` has been removed.
Deprecated custom query config has been removed.
Deprecated PodSecurityPolicy and K8S beta API versions have been removed.
Chart.yaml appVersion field is used as default image tag.
Labels are templated now.
Add default securityContext and PodSecurityContext.
LivenessProbe timeout has been raised to 3.

### To 4.6.0

This release adds functionality to template the variables inside `config.datasource` by means of allowing the `tpl` function in the resources that make use of it. This functionality is useful when you want to do sub-charting (e.g. in a postgres chart) and you want to avoid the duplication of variables inside `config.datasource`.
Expand Down
39 changes: 19 additions & 20 deletions charts/prometheus-postgres-exporter/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@ Create chart name and version as used by the chart label.
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Common labels
*/}}
{{- define "prometheus-postgres-exporter.labels" -}}
chart: {{ include "prometheus-postgres-exporter.chart" . }}
{{ include "prometheus-postgres-exporter.selectorLabels" . }}
heritage: {{ .Release.Service }}
{{- if .Values.commonLabels}}
{{ toYaml .Values.commonLabels }}
{{- end }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "prometheus-postgres-exporter.selectorLabels" -}}
app: {{ include "prometheus-postgres-exporter.name" . }}
release: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
Expand All @@ -50,23 +69,3 @@ Set DATA_SOURCE_URI environment variable
{{- define "prometheus-postgres-exporter.data_source_uri" -}}
{{ printf "%s:%d/%s?sslmode=%s&%s" (tpl .Values.config.datasource.host .) (tpl .Values.config.datasource.port . | int) (tpl .Values.config.datasource.database .) (tpl .Values.config.datasource.sslmode .) (tpl .Values.config.datasource.extraParams .) | trimSuffix "&" | quote }}
{{- end }}

{{/*
Return the appropriate apiVersion for rbac.
*/}}
{{- define "rbac.apiVersion" -}}
{{- if .Capabilities.APIVersions.Has "rbac.authorization.k8s.io/v1" }}
{{- print "rbac.authorization.k8s.io/v1" -}}
{{- else -}}
{{- print "rbac.authorization.k8s.io/v1beta1" -}}
{{- end -}}
{{- end -}}

{{/* Get Policy API Version */}}
{{- define "prometheus-postgres-exporter.pdb.apiVersion" -}}
{{- if .Capabilities.APIVersions.Has "policy/v1" }}
{{- print "policy/v1" -}}
{{- else -}}
{{- print "policy/v1beta1" -}}
{{- end -}}
{{- end -}}
12 changes: 4 additions & 8 deletions charts/prometheus-postgres-exporter/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
{{- if not .Values.config.externalQueries.enabled }}
{{- if .Values.config.postgresExporter }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "prometheus-postgres-exporter.fullname" . }}
labels:
app: {{ template "prometheus-postgres-exporter.name" . }}
chart: {{ template "prometheus-postgres-exporter.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- include "prometheus-postgres-exporter.labels" . | nindent 4 }}
data:
allow-snippet-annotations: "false"
config.yaml: |
{{- tpl (mergeOverwrite (tpl .Values.config.queries . | fromYaml) (tpl .Values.config.userQueries . | fromYaml) | toYaml) . | nindent 4 }}
postgres_exporter.yml: |
{{ tpl .Values.config.postgresExporter . | nindent 4 }}
{{- end }}
70 changes: 25 additions & 45 deletions charts/prometheus-postgres-exporter/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ kind: Deployment
metadata:
name: {{ template "prometheus-postgres-exporter.fullname" . }}
labels:
app: {{ template "prometheus-postgres-exporter.name" . }}
chart: {{ template "prometheus-postgres-exporter.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- include "prometheus-postgres-exporter.labels" . | nindent 4 }}
{{- with .Values.deployment.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
Expand All @@ -21,21 +18,19 @@ spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: {{ template "prometheus-postgres-exporter.name" . }}
release: {{ .Release.Name }}
{{- include "prometheus-postgres-exporter.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
app: {{ template "prometheus-postgres-exporter.name" . }}
release: {{ .Release.Name }}
{{- if .Values.podLabels }}
{{ toYaml .Values.podLabels | trim | indent 8 }}
{{- end }}
{{- include "prometheus-postgres-exporter.selectorLabels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
annotations:
checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
{{- if .Values.annotations }}
{{ toYaml .Values.annotations | indent 8 }}
{{- end }}
{{- with .Values.annotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
automountServiceAccountToken: {{ .Values.automountServiceAccountToken }}
serviceAccountName: {{ template "prometheus-postgres-exporter.serviceAccountName" . }}
Expand All @@ -56,7 +51,7 @@ spec:
containers:
- name: {{ .Chart.Name }}
args:
- "--extend.query-path=/etc/config.yaml"
- "--config.file=/etc/postgres_exporter.yml"
- "--web.listen-address=:{{ .Values.service.targetPort }}"
{{- if .Values.config.disableCollectorDatabase }}
- "--no-collector.database"
Expand All @@ -70,21 +65,6 @@ spec:
{{- if .Values.config.disableSettingsMetrics }}
- "--disable-settings-metrics"
{{- end }}
{{- if .Values.config.autoDiscoverDatabases }}
- "--auto-discover-databases"
{{- if .Values.config.excludeDatabases }}
- "--exclude-databases"
- {{ .Values.config.excludeDatabases | join "," }}
{{- end }}
{{- if .Values.config.includeDatabases }}
- "--include-databases"
- {{ .Values.config.includeDatabases | join "," }}
{{- end }}
{{- end }}
{{- if .Values.config.constantLabels }}
{{ $firstLabel := true -}}
- "--constantLabels={{- range $k, $v := .Values.config.constantLabels }}{{- if not $firstLabel -}},{{ end -}}{{ $firstLabel = false -}}{{ $k }}={{ $v }}{{- end }}"
{{- end }}
{{- if .Values.config.logLevel }}
- "--log.level={{ .Values.config.logLevel }}"
{{- end}}
Expand Down Expand Up @@ -148,7 +128,7 @@ spec:
{{ toYaml . | nindent 10 }}
{{- end }}
{{- end }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.command }}
command:
Expand Down Expand Up @@ -177,12 +157,14 @@ spec:
{{- toYaml . | nindent 12 }}
{{- end }}
volumeMounts:
- name: queries
mountPath: /etc/config.yaml
subPath: config.yaml
{{- with .Values.extraVolumeMounts }}
{{ toYaml . | indent 12 }}
{{- end }}
{{- if .Values.config.postgresExporter }}
- name: postgres-exporter
mountPath: /etc/postgres_exporter.yml
subPath: postgres_exporter.yml
{{- end }}
{{- with .Values.extraVolumeMounts }}
{{ toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.extraContainers }}
{{ toYaml . | indent 8 }}
{{- end }}
Expand All @@ -203,14 +185,12 @@ spec:
{{ toYaml . | indent 8 }}
{{- end }}
volumes:
{{- if .Values.config.postgresExporter }}
- configMap:
defaultMode: 420
{{- if not .Values.config.externalQueries.enabled }}
name: {{ template "prometheus-postgres-exporter.fullname" . }}
{{- else }}
name: {{ .Values.config.externalQueries.configmap }}
{{- end }}
name: queries
{{- with .Values.extraVolumes }}
{{ toYaml . | indent 6 }}
{{- end }}
name: postgres-exporter
{{- end }}
{{- with .Values.extraVolumes }}
{{ toYaml . | nindent 6 }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ kind: NetworkPolicy
metadata:
name: {{ template "prometheus-postgres-exporter.fullname" . }}
labels:
{{- include "prometheus-postgres-exporter.labels" . | nindent 4 }}
{{- if .Values.networkPolicy.labels }}
{{ toYaml .Values.networkPolicy.labels | indent 4 }}
{{- end }}
spec:
podSelector:
matchLabels:
app: {{ template "prometheus-postgres-exporter.name" . }}
release: {{ .Release.Name }}
{{- include "prometheus-postgres-exporter.selectorLabels" . | nindent 6 }}
policyTypes:
- Ingress
ingress:
Expand Down
10 changes: 3 additions & 7 deletions charts/prometheus-postgres-exporter/templates/pdb.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
{{- if .Values.podDisruptionBudget.enabled }}
apiVersion: {{ include "prometheus-postgres-exporter.pdb.apiVersion" . }}
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: {{ template "prometheus-postgres-exporter.fullname" . }}
labels:
app: {{ template "prometheus-postgres-exporter.name" . }}
chart: {{ template "prometheus-postgres-exporter.chart" . }}
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
{{- include "prometheus-postgres-exporter.labels" . | nindent 4 }}
spec:
maxUnavailable: {{ .Values.podDisruptionBudget.maxUnavailable }}
selector:
matchLabels:
app: {{ template "prometheus-postgres-exporter.name" . }}
release: {{ .Release.Name }}
{{- include "prometheus-postgres-exporter.selectorLabels" . | nindent 6 }}
{{- end }}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ metadata:
namespace: {{ . }}
{{- end }}
labels:
app: {{ template "prometheus-postgres-exporter.name" . }}
chart: {{ template "prometheus-postgres-exporter.chart" . }}
release: {{ .Release.Name | quote }}
heritage: {{ .Release.Service | quote }}
{{- include "prometheus-postgres-exporter.labels" . | nindent 4 }}
{{- with .Values.prometheusRule.additionalLabels }}
{{ toYaml . | indent 4 }}
{{- end }}
Expand Down
14 changes: 2 additions & 12 deletions charts/prometheus-postgres-exporter/templates/role.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
{{- if .Values.rbac.create }}
apiVersion: {{ template "rbac.apiVersion" . }}
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ template "prometheus-postgres-exporter.fullname" . }}
labels:
app: {{ template "prometheus-postgres-exporter.name" . }}
chart: {{ template "prometheus-postgres-exporter.chart" . }}
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
{{- if and .Values.rbac.pspEnabled (.Capabilities.APIVersions.Has "policy/v1beta1/PodSecurityPolicy") }}
rules:
- apiGroups: ['extensions']
resources: ['podsecuritypolicies']
verbs: ['use']
resourceNames: [{{ template "prometheus-postgres-exporter.fullname" . }}]
{{- end }}
{{- include "prometheus-postgres-exporter.labels" . | nindent 4 }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
{{- if .Values.rbac.create -}}
apiVersion: {{ template "rbac.apiVersion" . }}
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ template "prometheus-postgres-exporter.fullname" . }}
labels:
app: {{ template "prometheus-postgres-exporter.name" . }}
chart: {{ template "prometheus-postgres-exporter.chart" . }}
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
{{- include "prometheus-postgres-exporter.labels" . | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
Expand Down
5 changes: 1 addition & 4 deletions charts/prometheus-postgres-exporter/templates/secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ kind: Secret
metadata:
name: {{ template "prometheus-postgres-exporter.fullname" . }}
labels:
app: {{ template "prometheus-postgres-exporter.name" . }}
chart: {{ template "prometheus-postgres-exporter.chart" . }}
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
{{- include "prometheus-postgres-exporter.labels" . | nindent 4 }}
type: Opaque
data:
data_source_password: {{ tpl (.Values.config.datasource.password | default "somepaswword") . | b64enc }}
Expand Down
8 changes: 2 additions & 6 deletions charts/prometheus-postgres-exporter/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ metadata:
{{ toYaml .Values.service.annotations | indent 4 }}
{{- end }}
labels:
app: {{ template "prometheus-postgres-exporter.name" . }}
chart: {{ template "prometheus-postgres-exporter.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- include "prometheus-postgres-exporter.labels" . | nindent 4 }}
{{- if .Values.service.labels }}
{{ toYaml .Values.service.labels | trim | indent 4 }}
{{- end }}
Expand All @@ -22,5 +19,4 @@ spec:
protocol: TCP
name: {{ .Values.service.name }}
selector:
app: {{ template "prometheus-postgres-exporter.name" . }}
release: {{ .Release.Name }}
{{- include "prometheus-postgres-exporter.selectorLabels" . | nindent 4 }}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ automountServiceAccountToken: {{ .Values.automountServiceAccountToken }}
metadata:
name: {{ template "prometheus-postgres-exporter.serviceAccountName" . }}
labels:
app: {{ template "prometheus-postgres-exporter.name" . }}
chart: {{ template "prometheus-postgres-exporter.chart" . }}
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
{{- include "prometheus-postgres-exporter.labels" . | nindent 4 }}
{{- if .Values.serviceAccount.annotations }}
annotations:
{{ toYaml .Values.serviceAccount.annotations }}
Expand Down
Loading

0 comments on commit b5519f4

Please sign in to comment.