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

feat: add a helm chart with the releaser action #349

Merged
merged 3 commits into from
Oct 9, 2023
Merged
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
71 changes: 71 additions & 0 deletions .github/workflows/helm-workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
name: Helm
on: push

jobs:
helm-jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Helm
uses: azure/setup-helm@v3
with:
version: v3.12.1

- uses: actions/setup-python@v4
with:
python-version: '3.9'
check-latest: true

- name: Set up chart-testing
uses: helm/[email protected]

- name: Run chart-testing (list-changed)
id: list-changed
run: |
changed=$(ct list-changed --chart-dirs . --target-branch ${{ github.event.repository.default_branch }})
if [[ -n "$changed" ]]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
fi

- name: Run chart-testing (lint)
if: steps.list-changed.outputs.changed == 'true'
run: ct lint --target-branch ${{ github.event.repository.default_branch }} --validate-maintainers=false --chart-dirs .

- name: Setup helmfile
if: steps.list-changed.outputs.changed == 'true'
uses: mamezou-tech/[email protected]

- name: Create kind cluster
if: steps.list-changed.outputs.changed == 'true'
uses: helm/[email protected]

- name: Init postgres server
if: steps.list-changed.outputs.changed == 'true'
run: |
helmfile -f helm/ci/helmfile.yaml sync

- name: Run chart-testing (install)
if: steps.list-changed.outputs.changed == 'true'
run: ct install --target-branch ${{ github.event.repository.default_branch }} --chart-dirs .

- name: Run chart-testing (upgrade)
if: steps.list-changed.outputs.changed == 'true'
run: ct install --target-branch ${{ github.event.repository.default_branch }} --chart-dirs . --upgrade

- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"

- name: Release charts
if: ${{ github.ref == github.event.repository.default_branch }}
uses: helm/[email protected]
with:
charts_dir: .
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
23 changes: 23 additions & 0 deletions helm/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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/
18 changes: 18 additions & 0 deletions helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v2
name: sql-exporter
description: Database agnostic SQL exporter for Prometheus
type: application
version: 0.1.0
appVersion: 0.12.3
keywords:
burningalchemist marked this conversation as resolved.
Show resolved Hide resolved
- exporter
- servicemonitor
- sql
- metrics
home: https://github.com/burningalchemist/sql_exporter
sources:
- https://github.com/burningalchemist/sql_exporter
maintainers:
- name: Nikolai Rodionov
email: [email protected]
url: https://badhouseplants.net
37 changes: 37 additions & 0 deletions helm/ci/helmfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
repositories:
- name: bitnami
url: https://charts.bitnami.com/bitnami
- name: prometheus-community
url: https://prometheus-community.github.io/helm-charts

releases:
- name: postgres-instance
installed: true
namespace: postgres
createNamespace: true
chart: bitnami/postgresql
values:
- global:
postgresql:
auth:
postgresPassword: 123123!!
- name: prometheus-stack
namespace: monitoring
createNamespace: true
chart: prometheus-community/kube-prometheus-stack
values:
- prometheus:
prometheusSpec:
enableAdminAPI: true
podMonitorNamespaceSelector:
any: true
podMonitorSelector: {}
podMonitorSelectorNilUsesHelmValues: false
ruleNamespaceSelector:
any: true
ruleSelector: {}
ruleSelectorNilUsesHelmValues: false
serviceMonitorNamespaceSelector:
any: true
serviceMonitorSelector: {}
serviceMonitorSelectorNilUsesHelmValues: false
56 changes: 56 additions & 0 deletions helm/ci/postgresql-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
tests:
serviceMonitor:
enabled: true
prom:
service: prometheus-operated
namespace: monitoring
metricsEndpoint:
enabled: true

config:
target:
data_source_name: 'postgresql://postgres:[email protected]:5432?sslmode=disable'
collectors: [active_connections]
collectors:
- collector_name: active_connections
metrics:
- metric_name: active_connections
type: gauge
help: 'Active connections'
key_labels:
- "datname"
- "usename"
- "state"
values:
- "count"
query_ref: active_connections
queries:
- query_name: active_connections
query: |
SELECT
datname::text,
usename::text,
state::text,
COUNT(state)::float AS count
FROM pg_stat_activity
GROUP BY datname, usename, state;
collector_files:
- "*.collector.yml"
collectorFiles:
pricing_data_freshness.collector.yml:
collector_name: pricing_data_freshness
metrics:
- metric_name: pricing_update_time
type: gauge
help: 'Time when prices for a market were last updated.'
key_labels:
# Populated from the `market` column of each row.
- Market
static_labels:
# Arbitrary key/value pair
portfolio: income
values: [LastUpdateTime]
query: |
SELECT Market, max(UpdateTime) AS LastUpdateTime
FROM MarketPrices
GROUP BY Market
33 changes: 33 additions & 0 deletions helm/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
------------------------------
Hello there!

{{- if and (not .Values.config.target ) (not .Values.config.jobs)}}
------------------------------

It seems like you haven't configured the target, please check the example here:

https://github.com/burningalchemist/sql_exporter/blob/master/documentation/sql_exporter.yml#L30

In case you need to have multiple targets, you can confiure jobs instead, have a look here

https://github.com/burningalchemist/sql_exporter#multiple-database-connections

{{- end}}

{{- if and (not .Values.config.collectors) (not .Values.config.collectorFiles)}}

------------------------------
You need to configure either collectors or collectorFiles (or both), please have a look at the example here:

https://github.com/burningalchemist/sql_exporter#multiple-database-connections

{{- end }}

------------------------------
If you want to test if the helm release is configured correctly, you can execute

$ helm test {{ .Release.Name }}

This test will check that sql_exported metrics endpoint returns status 200


62 changes: 62 additions & 0 deletions helm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
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 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 }}
13 changes: 13 additions & 0 deletions helm/templates/configmap.collectors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{- if .Values.collectorFiles }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "sql-exporter.fullname" . }}
labels:
{{- include "sql-exporter.labels" . | nindent 4 }}
data:
{{- range $k, $v := .Values.collectorFiles }}
{{ $k }}: |-
{{- toYaml $v | nindent 4}}
{{- end}}
{{- end }}
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:
{{- include "sql-exporter.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "sql-exporter.selectorLabels" . | nindent 6 }}
template:
metadata:
annotations:
checksum/config: {{ include (print $.Template.BasePath "/secret.configuration.yaml") . | sha256sum }}
checksum/collectors: {{ include (print $.Template.BasePath "/configmap.collectors.yaml") . | sha256sum }}
labels:
{{- 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" . }}
{{- if .Values.collectorFiles }}
- name: sql-collector
configMap:
name: {{ include "sql-exporter.fullname" . }}
{{- end }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ default .Chart.AppVersion .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
args: ["-config.file=/etc/sql_exporter/sql_exporter.yml"]
volumeMounts:
- name: sql-exporter
readOnly: true
mountPath: /etc/sql_exporter/
{{- if .Values.collectorFiles }}
- name: sql-collector
readOnly: true
mountPath: /etc/sql_exporter/collectors/
{{- end }}
livenessProbe:
httpGet:
path: /healthz
port: 9399
readinessProbe:
httpGet:
path: /healthz
port: 9399
ports:
- name: http
containerPort: 9399
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 }}
Loading