Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Helm Chart for Kubernetes #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions helm/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
# Gitlab CI
.gitlab-ci.yml
examples/
17 changes: 17 additions & 0 deletions helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v2
name: sql-exporter
description: A Helm chart for SQL Metrics
type: application
version: 1.0.0
appVersion: 1.0.0
keywords:
- exporter
- servicemonitor
- sql
- metrics
home: https://github.com/free/sql_exporter
sources:
- https://github.com/free/sql_exporter
maintainers:
- name: Patrick Domnick
email: patrickfdomnick@gmail.com
59 changes: 59 additions & 0 deletions helm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# sql-exporter

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

A Helm chart for SQL Metrics

**Homepage:** <https://github.com/free/sql_exporter>

## Maintainers

| Name | Email | Url |
| ---- | ------ | --- |
| Patrick Domnick | patrickfdomnick@gmail.com | |

## Source Code

* <https://github.com/free/sql_exporter>

## Values

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| affinity | object | `{}` | |
| database.database | string | `""` | |
| database.host | string | `""` | |
| database.metrics | list | `[]` | |
| database.password | string | `""` | |
| database.port | string | `""` | |
| database.protocol | string | `"mysql"` | |
| database.user | string | `""` | |
| deployment.port | int | `9399` | |
| fullnameOverride | string | `""` | |
| image.pullPolicy | string | `"IfNotPresent"` | |
| image.repository | string | `"githubfree/sql_exporter"` | |
| image.tag | float | `0.5` | |
| imagePullSecrets | object | `{}` | |
| livenessProbe.failureThreshold | int | `6` | |
| livenessProbe.initialDelaySeconds | int | `30` | |
| livenessProbe.tcpSocket.port | string | `"http"` | |
| livenessProbe.timeoutSeconds | int | `5` | |
| nameOverride | string | `""` | |
| nodeSelector | object | `{}` | |
| podSecurityContext | object | `{}` | |
| readinessProbe.initialDelaySeconds | int | `5` | |
| readinessProbe.periodSeconds | int | `5` | |
| readinessProbe.tcpSocket.port | string | `"http"` | |
| readinessProbe.timeoutSeconds | int | `3` | |
| replicaCount | int | `1` | |
| resources.limits | object | `{}` | |
| securityContext | object | `{}` | |
| service.port | int | `9399` | |
| service.type | string | `"ClusterIP"` | |
| serviceMonitor.alerts.enabled | bool | `false` | |
| serviceMonitor.alerts.rules | list | `[]` | |
| serviceMonitor.enabled | bool | `false` | |
| serviceMonitor.namespace | string | `"monitoring"` | |
| serviceMonitor.path | string | `"/metrics"` | |
| serviceMonitor.selector | object | `{}` | |
| tolerations | list | `[]` | |
98 changes: 98 additions & 0 deletions helm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "sql-exporter.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "sql-exporter.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "sql-exporter.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Common labels
*/}}
{{- define "sql-exporter.labels" -}}
helm.sh/chart: {{ include "sql-exporter.chart" . }}
{{ include "sql-exporter.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}

{{/*
Selector labels
*/}}
{{- define "sql-exporter.selectorLabels" -}}
app.kubernetes.io/name: {{ include "sql-exporter.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}

{{/*
Create the sql_export.yml file
*/}}
{{- define "sql-exporter.expoter" -}}
{{- print "" -}}
{{- print "global:" | nindent 4 -}}
{{- print "scrape_timeout_offset: 500ms" | nindent 6 -}}
{{- print "min_interval: 0s" | nindent 6 -}}
{{- print "max_connections: 3" | nindent 6 -}}
{{- print "max_idle_connections: 3" | nindent 6 -}}
{{- print "target:" | nindent 4 -}}
{{- if eq .Values.database.protocol "mysql" -}}
{{- printf "data_source_name: %s://%s:%s@(%s:%s)/%s" .Values.database.protocol .Values.database.user .Values.database.password .Values.database.host .Values.database.port .Values.database.database | nindent 6 -}}
{{- end -}}
{{- if or (eq .Values.database.protocol "postgres") (eq .Values.database.protocol "sqlserver") -}}
{{- printf "data_source_name: %s://%s:%s@%s:%s/%s" .Values.database.protocol .Values.database.user .Values.database.password .Values.database.host .Values.database.port .Values.database.database | nindent 6 -}}
{{- end -}}
{{- if eq .Values.database.protocol "clickhouse" -}}
{{- printf "data_source_name: %s://%s:%s?username=%s&password=%s&dbname=%s" .Values.database.protocol .Values.database.host .Values.database.port .Values.database.user .Values.database.password .Values.database.database | nindent 6 -}}
{{- end -}}
{{- print "collectors: [sql_standard]" | nindent 6 -}}
{{- print "collector_files:" | nindent 4 -}}
{{- print "- /bin/config/standard.collector.yml" | nindent 6 -}}
{{- end -}}

{{/*
Create the standard.collector.yml file
*/}}
{{- define "sql-exporter.collector" -}}
{{- print "" -}}
{{- print "collector_name: sql_standard" | nindent 4 -}}
{{- print "metrics: " | nindent 4 -}}
{{ .Values.database.metrics | toYaml | nindent 6}}
{{- end -}}

{{/*
Create the name of the service account to use
*/}}
{{- define "sql-exporter.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "sql-exporter.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}
25 changes: 25 additions & 0 deletions helm/templates/alert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{{- if .Values.serviceMonitor.enabled }}
{{- if .Values.serviceMonitor.alerts.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
name: {{ template "sql-exporter.fullname" . }}
{{- if .Values.serviceMonitor.namespace }}
namespace: {{ .Values.serviceMonitor.namespace }}
{{- else }}
namespace: {{ .Release.Namespace }}
{{- end }}
labels:
app: {{ include "sql-exporter.fullname" . }}
chart: {{ template "sql-exporter.chart" . }}
release: {{ .Release.Name | quote }}
heritage: {{ .Release.Service | quote }}
{{- range $key, $value := .Values.serviceMonitor.selector }}
{{ $key }}: {{ $value | quote }}
{{- end }}
spec:
groups:
- name: {{ include "sql-exporter.fullname" . }}
rules: {{- toYaml .Values.serviceMonitor.alerts.rules | nindent 6 }}
{{- end }}
{{- end }}
13 changes: 13 additions & 0 deletions helm/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "sql-exporter.fullname" . }}
labels:
app: {{ include "sql-exporter.fullname" . }}
chart: {{ template "sql-exporter.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- include "sql-exporter.labels" . | nindent 4 }}
data:
standard.collector.yml: |-
{{- include "sql-exporter.collector" . }}
76 changes: 76 additions & 0 deletions helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "sql-exporter.fullname" . }}
labels:
app: {{ include "sql-exporter.fullname" . }}
chart: {{ template "sql-exporter.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- include "sql-exporter.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "sql-exporter.selectorLabels" . | nindent 6 }}
template:
metadata:
annotations:
rollme: {{ randAlphaNum 5 | quote }}
labels:
app: {{ include "sql-exporter.fullname" . }}
chart: {{ template "sql-exporter.chart" . }}
release: {{ .Release.Name }}
{{- include "sql-exporter.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
volumes:
- name: sql-exporter
secret:
secretName: {{ include "sql-exporter.fullname" . }}
- name: sql-collector
configMap:
name: {{ include "sql-exporter.fullname" . }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
args: ["-config.file=/bin/target/sql_exporter.yml"]
volumeMounts:
- name: sql-exporter
readOnly: true
mountPath: "/bin/target"
- name: sql-collector
readOnly: true
mountPath: "/bin/config"
{{- if .Values.livenessProbe }}
livenessProbe: {{- toYaml .Values.livenessProbe | nindent 12 }}
{{- end }}
{{- if .Values.readinessProbe }}
readinessProbe: {{- toYaml .Values.readinessProbe | nindent 12 }}
{{- end }}
ports:
- name: http
containerPort: {{ .Values.deployment.port }}
protocol: TCP
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
14 changes: 14 additions & 0 deletions helm/templates/secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ include "sql-exporter.fullname" . }}
labels:
app: {{ include "sql-exporter.fullname" . }}
chart: {{ template "sql-exporter.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- include "sql-exporter.labels" . | nindent 4 }}
type: Opaque
stringData:
sql_exporter.yml: |-
{{- include "sql-exporter.expoter" . }}
20 changes: 20 additions & 0 deletions helm/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "sql-exporter.fullname" . }}
labels:
{{- include "sql-exporter.labels" . | nindent 4 }}
app: {{ include "sql-exporter.fullname" . }}
chart: {{ template "sql-exporter.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
{{- include "sql-exporter.selectorLabels" . | nindent 4 }}
app: {{ include "sql-exporter.fullname" . }}
38 changes: 38 additions & 0 deletions helm/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{{- if .Values.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ template "sql-exporter.fullname" . }}
{{- if .Values.serviceMonitor.namespace }}
namespace: {{ .Values.serviceMonitor.namespace }}
{{- else }}
namespace: {{ .Release.Namespace }}
{{- end }}
labels:
app: {{ include "sql-exporter.fullname" . }}
chart: {{ template "sql-exporter.chart" . }}
release: {{ .Release.Name | quote }}
heritage: {{ .Release.Service | quote }}
{{- range $key, $value := .Values.serviceMonitor.selector }}
{{ $key }}: {{ $value | quote }}
{{- end }}
spec:
selector:
matchLabels:
app: {{ include "sql-exporter.fullname" . }}
release: {{ .Release.Name | quote }}
endpoints:
- port: http
{{- if .Values.serviceMonitor.path }}
path: {{ .Values.serviceMonitor.path }}
{{- end }}
{{- if .Values.serviceMonitor.interval }}
interval: {{ .Values.serviceMonitor.interval }}
{{- end }}
{{- if .Values.serviceMonitor.scrapeTimeout }}
scrapeTimeout: {{ .Values.serviceMonitor.scrapeTimeout }}
{{- end }}
namespaceSelector:
matchNames:
- {{ .Release.Namespace }}
{{- end }}
Loading