Compare commits

...

18 Commits

Author SHA1 Message Date
bb4a5d48b4
test(deployment): topologySpreadConstraints
All checks were successful
continuous-integration/drone/push Build is passing
2024-11-26 19:55:26 +01:00
1f6550d169
test(deployment): tolerations 2024-11-26 19:55:26 +01:00
a01c7d8c45
test(deployment): terminationGracePeriodSeconds 2024-11-26 19:55:26 +01:00
2dd99e8b13
fix(deployment): restartPolicy 2024-11-26 19:55:26 +01:00
4945cd1c2e
test(deployment): imagePullSecrets 2024-11-26 19:55:26 +01:00
ed10c5362a
test(deployment): hostNetwork, hostname, subdomain 2024-11-26 19:55:26 +01:00
70abc21fb4
test(deployment): dnsPolicy 2024-11-26 19:55:26 +01:00
8618b52ef6
test(deployment): dnsConfig 2024-11-26 19:55:26 +01:00
967d36cafb
test(deployment): priorityClassName 2024-11-26 19:55:26 +01:00
8f36f688d0
test(deployment): nodeSelector 2024-11-26 19:55:26 +01:00
8d1f6622b8
doc(README): adapt key name of exporterConfig secret 2024-11-26 19:55:26 +01:00
bd04d4a349
fix(values): suppres warning of overwriting table with non-table 2024-11-26 19:55:26 +01:00
3105f2a408
test(deployment): securityContext 2024-11-26 19:55:26 +01:00
3a96e4ac5d
test(deployment): resources 2024-11-26 19:55:26 +01:00
abd73d82f2
test(deployment,secrets): volume and volumeMounts 2024-11-26 19:55:26 +01:00
19b5ac5969
test(deployment,secrets): imageRegistry, imageRepository, imagePullPolicy 2024-11-26 19:55:26 +01:00
7b98e68b03
fix(deployment,secrets): deploy always the web-config secret 2024-11-26 19:55:26 +01:00
6c30756f8d
fix(deployment): extend arguments 2024-11-26 19:55:26 +01:00
7 changed files with 368 additions and 35 deletions

View File

@ -135,8 +135,8 @@ replaced:
| `config.database.secret.databaseUsername` | Database username. Will be defined as env `DATA_SOURCE_USER` as part of a secret. | `""` |
| `config.database.secret.databasePassword` | Database password. Will be defined as env `DATA_SOURCE_PASS` as part of a secret. | `""` |
| `config.database.secret.databaseConnectionUrl` | Complex database connection URL. Will be defined as env `DATA_SOURCE_URI` as part of a secret. | `""` |
| `config.exporterConfig.existingSecret.enabled` | Mount an existing secret containing the key `exporter_config.yaml`. | `false` |
| `config.exporterConfig.existingSecret.secretName` | Name of the existing secret containing the key `exporter_config.yaml`. | `""` |
| `config.exporterConfig.existingSecret.enabled` | Mount an existing secret containing the key `exporterConfig.yaml`. | `false` |
| `config.exporterConfig.existingSecret.secretName` | Name of the existing secret containing the key `exporterConfig.yaml`. | `""` |
| `config.exporterConfig.secret.annotations` | Additional annotations of the secret containing the `exporterConfig.yaml`. | `{}` |
| `config.exporterConfig.secret.labels` | Additional labels of the secret containing the `exporterConfig.yaml`. | `{}` |
| `config.exporterConfig.secret.exporterConfig` | Content of the `exporterConfig.yaml`. Further information can be found [here](https://prometheus.io/docs/prometheus/latest/configuration/https/). | `{}` |
@ -170,10 +170,11 @@ replaced:
| `deployment.postgresExporter.image.pullPolicy` | Image pull policy. | `IfNotPresent` |
| `deployment.postgresExporter.resources` | CPU and memory resources of the pod. | `{}` |
| `deployment.postgresExporter.securityContext` | Security context of the container of the deployment. | `{}` |
| `deployment.postgresExporter.volumeMounts` | Additional volume mounts. | `{}` |
| `deployment.postgresExporter.volumeMounts` | Additional volume mounts. | `[]` |
| `deployment.nodeSelector` | NodeSelector of the postgres-exporter deployment. | `{}` |
| `deployment.priorityClassName` | PriorityClassName of the postgres-exporter deployment. | `""` |
| `deployment.replicaCount` | Number of replicas for the postgres-exporter deployment. | `1` |
| `deployment.restartPolicy` | Restart policy of the postgres-exporter deployment. | `""` |
| `deployment.securityContext` | Security context of the postgres-exporter deployment. | `{}` |
| `deployment.strategy.type` | Strategy type - `Recreate` or `Rollingupdate`. | `Recreate` |
| `deployment.strategy.rollingUpdate.maxSurge` | The maximum number of pods that can be scheduled above the desired number of pods during a rolling update. | `1` |

View File

@ -53,7 +53,7 @@
{{- define "prometheus-postgres-exporter.deployment.volumeMounts" -}}
{{- $volumeMounts := dict "volumeMounts" (.Values.deployment.postgresExporter.volumeMounts | default (list) ) }}
{{- $volumeMounts = merge $volumeMounts (dict "volumeMounts" (list (dict "name" "exporter-config" "mountPath" "/etc/prometheus-postgres-exporter/config.d" ))) }}
{{- $volumeMounts = merge $volumeMounts (dict "volumeMounts" (list (dict "name" "config.d" "mountPath" "/etc/prometheus-postgres-exporter/config.d" ))) }}
{{ toYaml $volumeMounts }}
{{- end -}}
@ -61,10 +61,19 @@
{{- define "prometheus-postgres-exporter.deployment.volumes" -}}
{{- $volumes := dict "volumes" (.Values.deployment.volumes | default (list) ) }}
{{- $secretName := .Values.config.exporterConfig.existingSecret.secretName -}}
{{- $exporterSecretName := .Values.config.exporterConfig.existingSecret.secretName -}}
{{- if not .Values.config.exporterConfig.existingSecret.enabled }}
{{- $secretName = printf "%s-exporter-config" (include "prometheus-postgres-exporter.fullname" . ) }}
{{- $exporterSecretName = printf "%s-exporter-config" (include "prometheus-postgres-exporter.fullname" . ) }}
{{- end }}
{{- $volumes = merge $volumes (dict "volumes" (list (dict "name" "exporter-config" "secret" (dict "secretName" $secretName)))) }}
{{- $webConfigSecretName := .Values.config.webConfig.existingSecret.secretName -}}
{{- if not .Values.config.webConfig.existingSecret.enabled }}
{{- $webConfigSecretName = printf "%s-web-config" (include "prometheus-postgres-exporter.fullname" . ) }}
{{- end }}
{{- $volumes = merge $volumes (dict "volumes" (list (dict "name" "config.d" "projected" (dict "defaultMode" "0444" "sources" (list (dict "secret" (dict "name" $exporterSecretName)) (dict "secret" (dict "name" $webConfigSecretName))))))) }}
{{ toYaml $volumes }}
{{- end -}}

View File

@ -24,6 +24,7 @@ spec:
- name: postgres-exporter
args:
- "--config.file=/etc/prometheus-postgres-exporter/config.d/exporterConfig.yaml"
- "--web.config.file=/etc/prometheus-postgres-exporter/config.d/web-config.yaml"
- "--web.listen-address=:9187"
{{- range .Values.deployment.postgresExporter.args }}
- {{ . | quote }}
@ -59,7 +60,7 @@ spec:
- name: http
containerPort: 9187
protocol: TCP
{{- with .Values.deployment.containerResources }}
{{- with .Values.deployment.postgresExporter.resources }}
resources:
{{- toYaml . | nindent 10 }}
{{- end }}
@ -80,7 +81,7 @@ spec:
dnsPolicy: {{ .Values.deployment.dnsPolicy }}
{{- end }}
{{- if .Values.deployment.hostname }}
hostname: {{ .Values.batch.dbUpdate.hostname }}
hostname: {{ .Values.deployment.hostname }}
{{- end }}
hostNetwork: {{ .Values.deployment.hostNetwork }}
{{- with .Values.deployment.imagePullSecrets }}
@ -94,7 +95,9 @@ spec:
{{- if .Values.deployment.priorityClassName }}
priorityClassName: {{ .Values.deployment.priorityClassName }}
{{- end }}
{{- if .Values.deployment.restartPolicy }}
restartPolicy: {{ .Values.deployment.restartPolicy }}
{{- end }}
{{- with .Values.deployment.securityContext }}
securityContext:
{{- toYaml . | nindent 8 }}

View File

@ -1,4 +1,4 @@
{{- if and (not (.Values.config.webConfig.existingSecret.enabled)) .Values.config.webConfig.secret.webConfig }}
{{- if not .Values.config.webConfig.existingSecret.enabled }}
---
apiVersion: v1
kind: Secret

View File

@ -32,8 +32,98 @@ tests:
content:
secretRef:
name: prometheus-postgres-exporter-unittest-database-env
- equal:
path: spec.template.spec.containers[0].args
value:
- --config.file=/etc/prometheus-postgres-exporter/config.d/exporterConfig.yaml
- --web.config.file=/etc/prometheus-postgres-exporter/config.d/web-config.yaml
- --web.listen-address=:9187
- equal:
path: spec.template.spec.containers[0].volumeMounts
value:
- mountPath: /etc/prometheus-postgres-exporter/config.d
name: config.d
- equal:
path: spec.template.spec.volumes
value:
- name: config.d
projected:
defaultMode: "0444"
sources:
- secret:
name: prometheus-postgres-exporter-unittest-exporter-config
- secret:
name: prometheus-postgres-exporter-unittest-web-config
- equal:
path: spec.template.spec.containers[0].image
value: quay.io/prometheuscommunity/postgres-exporter:v0.1.0
- equal:
path: spec.template.spec.containers[0].imagePullPolicy
value: IfNotPresent
- notExists:
path: spec.template.spec.containers[0].resources
- notExists:
path: spec.template.spec.containers[0].securityContext
- notExists:
path: spec.template.spec.dnsConfig
- notExists:
path: spec.template.spec.dnsPolicy
- notExists:
path: spec.template.spec.hostname
- equal:
path: spec.template.spec.hostNetwork
value: false
- notExists:
path: spec.template.spec.imagePullSecrets
- notExists:
path: spec.template.spec.nodeSelector
- notExists:
path: spec.template.spec.priorityClassName
- notExists:
path: spec.template.spec.restartPolicy
- notExists:
path: spec.template.spec.subdomain
- equal:
path: spec.template.spec.terminationGracePeriodSeconds
value: 60
- notExists:
path: spec.template.spec.tolerations
- notExists:
path: spec.template.spec.topologySpreadConstraints
- it: Test custom database secret
- it: Test additional arguments
set:
deployment.postgresExporter.args:
- "--foo=bar"
- "--bar=foo"
asserts:
- equal:
path: spec.template.spec.containers[0].args
value:
- --config.file=/etc/prometheus-postgres-exporter/config.d/exporterConfig.yaml
- --web.config.file=/etc/prometheus-postgres-exporter/config.d/web-config.yaml
- --web.listen-address=:9187
- --foo=bar
- --bar=foo
- it: Test custom imageRegistry and imageRepository
set:
deployment.postgresExporter.image.registry: registry.example.local
deployment.postgresExporter.image.repository: path/special/prometheus-postgres-exporter
asserts:
- equal:
path: spec.template.spec.containers[0].image
value: registry.example.local/path/special/prometheus-postgres-exporter:v0.1.0
- it: Test custom imagePullPolicy
set:
deployment.postgresExporter.image.pullPolicy: Always
asserts:
- equal:
path: spec.template.spec.containers[0].imagePullPolicy
value: Always
- it: Test config.database.existingSecret
set:
config.database.existingSecret.enabled: true
config.database.existingSecret.secretName: custom-database-secret
@ -43,3 +133,233 @@ tests:
content:
secretRef:
name: custom-database-secret
- it: Test config.exporterConfig.existingSecret
set:
config.exporterConfig.existingSecret.enabled: true
config.exporterConfig.existingSecret.secretName: exporter-config-secret
asserts:
- equal:
path: spec.template.spec.containers[0].volumeMounts
value:
- mountPath: /etc/prometheus-postgres-exporter/config.d
name: config.d
- equal:
path: spec.template.spec.volumes
value:
- name: config.d
projected:
defaultMode: "0444"
sources:
- secret:
name: exporter-config-secret
- secret:
name: prometheus-postgres-exporter-unittest-web-config
- it: Test config.webConfig.existingSecret
set:
config.webConfig.existingSecret.enabled: true
config.webConfig.existingSecret.secretName: web-config-secret
asserts:
- equal:
path: spec.template.spec.containers[0].volumeMounts
value:
- mountPath: /etc/prometheus-postgres-exporter/config.d
name: config.d
- equal:
path: spec.template.spec.volumes
value:
- name: config.d
projected:
defaultMode: "0444"
sources:
- secret:
name: prometheus-postgres-exporter-unittest-exporter-config
- secret:
name: web-config-secret
- it: Test custom resource limits and requests
set:
deployment.postgresExporter.resources:
limits:
cpu: 100m
memory: 250MB
requests:
cpu: 25m
memory: 100MB
asserts:
- equal:
path: spec.template.spec.containers[0].resources
value:
limits:
cpu: 100m
memory: 250MB
requests:
cpu: 25m
memory: 100MB
- it: Test custom securityContext
set:
deployment.postgresExporter.securityContext:
capabilities:
add:
- NET_RAW
drop:
- ALL
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
runAsUser: 1000
asserts:
- equal:
path: spec.template.spec.containers[0].securityContext
value:
capabilities:
add:
- NET_RAW
drop:
- ALL
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
runAsUser: 1000
- it: Test dnsConfig
set:
deployment.dnsConfig:
nameservers:
- "8.8.8.8"
- "8.8.4.4"
asserts:
- equal:
path: spec.template.spec.dnsConfig
value:
nameservers:
- "8.8.8.8"
- "8.8.4.4"
- it: Test dnsPolicy
set:
deployment.dnsPolicy: ClusterFirst
asserts:
- equal:
path: spec.template.spec.dnsPolicy
value: ClusterFirst
- it: Test hostNetwork, hostname, subdomain
set:
deployment.hostNetwork: true
deployment.hostname: pg-exporter
deployment.subdomain: exporters.internal
asserts:
- equal:
path: spec.template.spec.hostNetwork
value: true
- equal:
path: spec.template.spec.hostname
value: pg-exporter
- equal:
path: spec.template.spec.subdomain
value: exporters.internal
- it: Test imagePullSecrets
set:
deployment.imagePullSecrets:
- name: my-pull-secret
- name: my-special-secret
asserts:
- equal:
path: spec.template.spec.imagePullSecrets
value:
- name: my-pull-secret
- name: my-special-secret
- it: Test nodeSelector
set:
deployment.nodeSelector:
foo: bar
asserts:
- equal:
path: spec.template.spec.nodeSelector
value:
foo: bar
- it: Test priorityClassName
set:
deployment.priorityClassName: my-priority
asserts:
- equal:
path: spec.template.spec.priorityClassName
value: my-priority
- it: Test restartPolicy
set:
deployment.restartPolicy: Always
asserts:
- equal:
path: spec.template.spec.restartPolicy
value: Always
- it: Test terminationGracePeriodSeconds
set:
deployment.terminationGracePeriodSeconds: 120
asserts:
- equal:
path: spec.template.spec.terminationGracePeriodSeconds
value: 120
- it: Test tolerations
set:
deployment.tolerations:
- key: database/type
operator: Equal
value: postgres
effect: NoSchedule
asserts:
- equal:
path: spec.template.spec.tolerations
value:
- key: database/type
operator: Equal
value: postgres
effect: NoSchedule
- it: Test topologySpreadConstraints
set:
deployment.topologySpreadConstraints:
- topologyKey: kubernetes.io/hostname
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app.kubernetes.io/instance: prometheus-postgres-exporter
asserts:
- equal:
path: spec.template.spec.topologySpreadConstraints
value:
- topologyKey: kubernetes.io/hostname
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app.kubernetes.io/instance: prometheus-postgres-exporter
- it: Test additional volumeMounts and volumes
set:
deployment.postgresExporter.volumeMounts:
- name: data
mountPath: /usr/lib/prometheus-postgres-exporter/data
deployment.volumes:
- name: data
hostPath:
path: /usr/lib/prometheus-postgres-exporter/data
asserts:
- contains:
path: spec.template.spec.containers[0].volumeMounts
content:
name: data
mountPath: /usr/lib/prometheus-postgres-exporter/data
- contains:
path: spec.template.spec.volumes
content:
name: data
hostPath:
path: /usr/lib/prometheus-postgres-exporter/data

View File

@ -8,27 +8,7 @@ release:
templates:
- templates/prometheus-postgres-exporter/secretWebConfig.yaml
tests:
- it: Skip rendering by using existing secret.
set:
config.webConfig.existingSecret.enabled: true
asserts:
- hasDocuments:
count: 0
- it: Skip rendering when no webConfig.yaml is defined.
set:
config.webConfig.existingSecret.enabled: false
asserts:
- hasDocuments:
count: 0
- it: Rendering database secret.
set:
config.webConfig.secret.webConfig:
tls_server_config:
cert_file: /path/to/cert.pem
client_ca_file: /path/to/ca.pem
key_file: /path/to/key.pem
- it: Rendering default secret.
asserts:
- hasDocuments:
count: 1
@ -47,6 +27,19 @@ tests:
app.kubernetes.io/name: prometheus-postgres-exporter
app.kubernetes.io/version: 0.1.0
helm.sh/chart: prometheus-postgres-exporter-0.1.0
- equal:
path: stringData["webConfig.yaml"]
value: |
{}
- it: Rendering custom webconfig.
set:
config.webConfig.secret.webConfig:
tls_server_config:
cert_file: /path/to/cert.pem
client_ca_file: /path/to/ca.pem
key_file: /path/to/key.pem
asserts:
- equal:
path: stringData["webConfig.yaml"]
value: |

View File

@ -30,8 +30,8 @@ config:
databaseConnectionUrl: ""
exporterConfig:
## @param config.exporterConfig.existingSecret.enabled Mount an existing secret containing the key `exporter_config.yaml`.
## @param config.exporterConfig.existingSecret.secretName Name of the existing secret containing the key `exporter_config.yaml`.
## @param config.exporterConfig.existingSecret.enabled Mount an existing secret containing the key `exporterConfig.yaml`.
## @param config.exporterConfig.existingSecret.secretName Name of the existing secret containing the key `exporterConfig.yaml`.
existingSecret:
enabled: false
secretName: ""
@ -190,7 +190,7 @@ deployment:
# runAsUser: 1000
## @param deployment.postgresExporter.volumeMounts Additional volume mounts.
volumeMounts: {}
volumeMounts: []
# - name: my-configmap-volume
# mountPath: /configmap
# readOnly: true
@ -204,6 +204,9 @@ deployment:
## @param deployment.replicaCount Number of replicas for the postgres-exporter deployment.
replicaCount: 1
## @param deployment.restartPolicy Restart policy of the postgres-exporter deployment.
restartPolicy: ""
## @param deployment.securityContext Security context of the postgres-exporter deployment.
securityContext: {}
# fsGroup: 2000
@ -222,6 +225,10 @@ deployment:
## @param deployment.tolerations Tolerations of the postgres-exporter deployment.
tolerations: []
# - key: database/type
# operator: Equal
# value: postgres
# effect: NoSchedule
## @param deployment.topologySpreadConstraints TopologySpreadConstraints of the postgres-exporter deployment.
topologySpreadConstraints: []