Skip to content

Commit

Permalink
feat(clickhouse-monitoring): add cronjob (#177)
Browse files Browse the repository at this point in the history
* feat(clickhouse-monitoring): add cronjob

* fix(clickhouse-monitoring): fix type, add docs

* fix(clickhouse-monitoring): cronjob api version for older k8s version
  • Loading branch information
duyet authored Jun 30, 2024
1 parent 95a31dd commit 3c01215
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 3 deletions.
2 changes: 1 addition & 1 deletion clickhouse-monitoring/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.1
version: 0.1.2

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
10 changes: 8 additions & 2 deletions clickhouse-monitoring/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# clickhouse-monitoring

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

A Helm chart for ClickHouse Monitoring (https://github.com/duyet/clickhouse-monitoring)

Expand All @@ -21,6 +21,9 @@ A Helm chart for ClickHouse Monitoring (https://github.com/duyet/clickhouse-moni
| autoscaling.maxReplicas | int | `100` | |
| autoscaling.minReplicas | int | `1` | |
| autoscaling.targetCPUUtilizationPercentage | int | `80` | |
| cronjob | object | `{"enabled":true,"endpoints":[{"endpoint":"/api/clean","schedule":"*/30 * * * *"}],"failedJobsHistoryLimit":3,"image":{"pullPolicy":"IfNotPresent","repository":"alpine/curl","tag":"8.8.0"},"resources":{},"successfulJobsHistoryLimit":1}` | Enable cronjob for monitoring background tasks |
| cronjob.endpoints[0].endpoint | string | `"/api/clean"` | Endpoint for the cron job to call, must be unique as using for generate cronjob name as well. |
| cronjob.endpoints[0].schedule | string | `"*/30 * * * *"` | Cron schedule expression |
| env[0].name | string | `"CLICKHOUSE_HOST"` | |
| env[0].value | string | `"http://localhost:8123"` | |
| env[1].name | string | `"CLICKHOUSE_USER"` | |
Expand All @@ -32,7 +35,7 @@ A Helm chart for ClickHouse Monitoring (https://github.com/duyet/clickhouse-moni
| fullnameOverride | string | `""` | |
| image.pullPolicy | string | `"Always"` | |
| image.repository | string | `"ghcr.io/duyet/clickhouse-monitoring"` | |
| image.tag | string | `"main"` | |
| image.tag | string | `"latest"` | |
| imagePullSecrets | list | `[]` | |
| ingress.annotations | object | `{}` | |
| ingress.className | string | `""` | |
Expand All @@ -46,10 +49,13 @@ A Helm chart for ClickHouse Monitoring (https://github.com/duyet/clickhouse-moni
| podAnnotations | object | `{}` | |
| podLabels | object | `{}` | |
| podSecurityContext | object | `{}` | |
| port.containerPort | int | `3000` | |
| port.portName | string | `"http"` | |
| replicaCount | int | `1` | |
| resources | object | `{}` | |
| securityContext | object | `{}` | |
| service.port | int | `3000` | |
| service.portName | string | `"http"` | |
| service.type | string | `"ClusterIP"` | |
| tolerations | list | `[]` | |
| volumeMounts | list | `[]` | |
Expand Down
20 changes: 20 additions & 0 deletions clickhouse-monitoring/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,23 @@ Usage:
{{- tpl (.value | toYaml) .context }}
{{- end }}
{{- end -}}

{{/*
Cronjob name
Usage:
{{ include "clickhouse-monitoring.cronjobName" (merge $endpoint $) }}
*/}}
{{- define "clickhouse-monitoring.cronjobName" -}}
{{- printf "%s-%s" (include "clickhouse-monitoring.fullname" .) .endpoint | replace "/" "-" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Cronjob API Version
*/}}
{{- define "clickhouse-monitoring.cronJobApiVersion" -}}
{{- if semverCompare ">=1.21-0" .Capabilities.KubeVersion.GitVersion -}}
batch/v1
{{- else -}}
batch/v1beta1
{{- end -}}
{{- end -}}
89 changes: 89 additions & 0 deletions clickhouse-monitoring/templates/cronjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{{- if $.Values.cronjob.enabled }}
{{- range $endpoint := $.Values.cronjob.endpoints }}

---
apiVersion: {{ include "clickhouse-monitoring.cronJobApiVersion" $ }}
kind: CronJob
metadata:
name: {{ include "clickhouse-monitoring.cronjobName" (merge $endpoint $) }}
labels:
{{- include "clickhouse-monitoring.labels" $ | nindent 4 }}
spec:
schedule: {{ $endpoint.schedule | quote }}
successfulJobsHistoryLimit: {{ $.Values.cronjob.successfulJobsHistoryLimit }}
failedJobsHistoryLimit: {{ $.Values.cronjob.failedJobsHistoryLimit }}
jobTemplate:
metadata:
{{- with $.Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "clickhouse-monitoring.labels" $ | nindent 8 }}
{{- with $.Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
template:
spec:
{{- with $.Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 12 }}
{{- end }}
securityContext:
{{- toYaml $.Values.podSecurityContext | nindent 12 }}
containers:
- name: {{ $.Chart.Name }}
securityContext:
{{- toYaml $.Values.securityContext | nindent 16 }}
{{- with $.Values.cronjob.image }}
image: "{{ .repository }}:{{ .tag }}"
imagePullPolicy: {{ .pullPolicy | default $.Values.image.pullPolicy }}
{{- end }}
resources:
{{- toYaml $.Values.cronjob.resources | nindent 16 }}
env:
- name: ENDPOINT
value: {{ include "clickhouse-monitoring.fullname" $ }}:{{ $.Values.service.port }}
{{- with $.Values.env }}
{{- toYaml . | nindent 16 }}
{{- end }}
{{- if or $.Values.extraEnvVarsCM $.Values.extraEnvVarsSecret }}
envFrom:
{{- if $.Values.extraEnvVarsCM }}
- configMapRef:
name: {{ include "clickhouse-monitoring.tplValue" ( dict "value" $.Values.extraEnvVarsCM "context" $ ) }}
{{- end }}
{{- if $.Values.extraEnvVarsSecret }}
- secretRef:
name: {{ include "clickhouse-monitoring.tplValue" ( dict "value" $.Values.extraEnvVarsSecret "context" $ ) }}
{{- end }}
{{- end }}
command:
- curl
- -H
- 'Content-type: application/json'
- $(ENDPOINT){{ $endpoint.endpoint }}

{{- with $.Values.volumeMounts }}
volumeMounts:
{{- toYaml . | nindent 16 }}
{{- end }}
{{- with $.Values.volumes }}
volumes:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with $.Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with $.Values.affinity }}
affinity:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with $.Values.tolerations }}
tolerations:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- end }}
{{- end }}
31 changes: 31 additions & 0 deletions clickhouse-monitoring/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,37 @@ env:
- name: CLICKHOUSE_PASSWORD
value: ''

# -- Enable cronjob for monitoring background tasks
cronjob:
enabled: true

endpoints:
- # -- Cron schedule expression

Check failure on line 30 in clickhouse-monitoring/values.yaml

View workflow job for this annotation

GitHub Actions / chart-lint (v3.4.0, v1.20.15)

30:7 [comments] too few spaces before comment

Check failure on line 30 in clickhouse-monitoring/values.yaml

View workflow job for this annotation

GitHub Actions / chart-lint (v3.4.0, v1.22.5)

30:7 [comments] too few spaces before comment

Check failure on line 30 in clickhouse-monitoring/values.yaml

View workflow job for this annotation

GitHub Actions / chart-lint (v3.4.0, v1.23.17)

30:7 [comments] too few spaces before comment

Check failure on line 30 in clickhouse-monitoring/values.yaml

View workflow job for this annotation

GitHub Actions / chart-lint (v3.4.0, v1.24.15)

30:7 [comments] too few spaces before comment

Check failure on line 30 in clickhouse-monitoring/values.yaml

View workflow job for this annotation

GitHub Actions / chart-lint (v3.4.0, v1.26.6)

30:7 [comments] too few spaces before comment

Check failure on line 30 in clickhouse-monitoring/values.yaml

View workflow job for this annotation

GitHub Actions / chart-lint (v3.4.0, v1.27.3)

30:7 [comments] too few spaces before comment

Check failure on line 30 in clickhouse-monitoring/values.yaml

View workflow job for this annotation

GitHub Actions / chart-lint (v3.4.0, v1.28.0)

30:7 [comments] too few spaces before comment
schedule: "*/30 * * * *"
# -- Endpoint for the cron job to call, must be unique as using for generate cronjob name as well.
endpoint: /api/clean

successfulJobsHistoryLimit: 1
failedJobsHistoryLimit: 3

image:
repository: alpine/curl
tag: 8.8.0
pullPolicy: IfNotPresent

resources:
{}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi

# Name of a ConfigMap containing extra env vars
extraEnvVarsCM:
# Name of a Secret containing extra env vars
Expand Down

0 comments on commit 3c01215

Please sign in to comment.