Skip to content

Commit

Permalink
feat(helm): Add an ability to set addition env via helm (#399)
Browse files Browse the repository at this point in the history
* feat: Add local bin dir to helmignore

In case somebody wants to test the chart locally, after generating docs,
tests will fail, because helm will consider bin as a part of the chart,
and the size of the binary is too big to be installed to k8s

* feat: Add an ability to set addition env via helm

Now it should be possible to set addition environment variables that are
going to be used by sql_exporter deployment.

User can either set a value of the variable, so it's taken directly from
Values, or use a value from an already existing Secret or ConfigMap.
  • Loading branch information
Nikolai Rodionov authored Nov 21, 2023
1 parent 885c365 commit bf66c18
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
2 changes: 2 additions & 0 deletions helm/.helmignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@
.idea/
*.tmproj
.vscode/
# Dir with local binaries
bin
2 changes: 1 addition & 1 deletion helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: sql-exporter
description: Database agnostic SQL exporter for Prometheus
type: application
version: 0.2.3
version: 0.2.4
appVersion: 0.13.0
keywords:
- exporter
Expand Down
4 changes: 2 additions & 2 deletions helm/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# sql-exporter

![Version: 0.2.2](https://img.shields.io/badge/Version-0.2.2-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.13.0](https://img.shields.io/badge/AppVersion-0.13.0-informational?style=flat-square)
![Version: 0.2.4](https://img.shields.io/badge/Version-0.2.4-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 0.13.0](https://img.shields.io/badge/AppVersion-0.13.0-informational?style=flat-square)

Database agnostic SQL exporter for Prometheus

Expand Down Expand Up @@ -72,4 +72,4 @@ It's also possible to define collectors (i.e. metrics and queries) in separate f

## Dev Notes

After updating default `Values`, please execute `make gen_docs` to update the `README.md` file
After changing default `Values`, please execute `make gen_docs` to update the `README.md` file. Readme file is generated by the `helm-docs` tool, so make sure not to edit it manually.
20 changes: 20 additions & 0 deletions helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,26 @@ spec:
readOnly: true
mountPath: /etc/sql_exporter/collectors/
{{- end }}
{{- if .Values.env }}
env:
{{- range $key, $value := .Values.env }}
- name: {{ $key }}
{{- if $value.value }}
value: {{ $value.value }}
{{- else }}
valueFrom:
{{- if eq $value.from.kind "Secret" }}
secretKeyRef:
{{- else if eq $value.from.kind "ConfigMap" }}
configMapKeyRef:
{{- else }}
{{- fail "Values.env[].from.kind should be either Secret or ConfigMap" }}
{{- end }}
name: {{ $value.from.name }}
key: {{ $value.from.key }}
{{- end }}
{{- end }}
{{- end }}
livenessProbe:
httpGet:
path: /healthz
Expand Down
20 changes: 16 additions & 4 deletions helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ service:
# -- Service labels
labels: {}
# -- Service annotations
annotations: {}
annotations:
{}
# example of prometheus usage
# prometheus.io/scrape: "true"
# prometheus.io/path: "/metrics"

# -- Resource limits and requests for the application controller pods
resources: {}
resources:
{}
# limits:
# cpu: 100m
# memory: 128Mi
Expand All @@ -43,7 +45,8 @@ podLabels: {}
podAnnotations: {}

# -- Pod security context
podSecurityContext: {}
podSecurityContext:
{}
# capabilities:
# drop:
# - ALL
Expand All @@ -64,6 +67,16 @@ serviceMonitor:
# -- ServiceMonitor scrape timeout
# scrapeTimeout: 10s

# Additional env variables
# - kind should be either Secret or ConfigMap
# - name is the name of the Secret or ConfigMap that should be used
# - key is the key of the object inside of a Secret or ConfigMap
# env:
# SQLEXPORTER_TARGET_DSN:
# from:
# kind: Secret
# name: sql_exporter_secret
# key: CONNECTION_STRING
config:
global:
# -- Scrape timeout
Expand All @@ -76,7 +89,6 @@ config:
max_connections: 3
# -- Number of idle connections.
max_idle_connections: 3

# Target and collectors are not set so the chart is more flexible. Please configure it yourself.
# target:
# data_source_name: 'sqlserver://prom_user:[email protected]:1433'
Expand Down

0 comments on commit bf66c18

Please sign in to comment.