Skip to content

Commit

Permalink
[influxdb2] add init scripts support (#456)
Browse files Browse the repository at this point in the history
* add init scripts support

* add test values files

* prettify templates output

* bump version

Co-authored-by: Pavel Závora <[email protected]>

* update script execution info in comment

Co-authored-by: Pavel Závora <[email protected]>

* fix trailing spaces

* fix default init script to run non-interactively
  • Loading branch information
alespour authored Jun 2, 2022
1 parent bae0041 commit 838956b
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 13 deletions.
2 changes: 1 addition & 1 deletion charts/influxdb2/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: influxdb2
description: A Helm chart for InfluxDB v2
home: https://www.influxdata.com/products/influxdb/
type: application
version: 2.0.12
version: 2.1.0
maintainers:
- name: rawkode
email: [email protected]
Expand Down
1 change: 1 addition & 0 deletions charts/influxdb2/ci/default-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Default values only, no overrides
5 changes: 5 additions & 0 deletions charts/influxdb2/ci/init-scripts-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
initScripts:
enabled: true

persistence:
enabled: false
2 changes: 1 addition & 1 deletion charts/influxdb2/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ Common labels
*/}}
{{- define "influxdb.labels" -}}
app.kubernetes.io/name: {{ include "influxdb.name" . }}
helm.sh/chart: {{ include "influxdb.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
helm.sh/chart: {{ include "influxdb.chart" . }}
{{- end -}}

{{/*
Expand Down
10 changes: 10 additions & 0 deletions charts/influxdb2/templates/init-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{- if .Values.initScripts.enabled -}}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "influxdb.fullname" . }}-init
labels:
{{- include "influxdb.labels" . | nindent 4 }}
data:
{{ toYaml .Values.initScripts.scripts | indent 2 }}
{{- end -}}
9 changes: 5 additions & 4 deletions charts/influxdb2/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ spec:
port: {{ .Values.service.port }}
protocol: TCP
targetPort: {{ .Values.service.targetPort }}
{{ if (and (eq .Values.service.type "NodePort") (not (empty .Values.service.nodePort))) }}
nodePort: {{.Values.service.nodePort}}
{{ end }}
{{- if (and (eq .Values.service.type "NodePort") (not (empty .Values.service.nodePort))) }}
nodePort: {{ .Values.service.nodePort }}
{{- end }}
{{- if .Values.extraExposePorts }}
{{- tpl (toYaml .Values.extraExposePorts) . | indent 4 }}
{{- end }}
selector: {{- include "influxdb.selectorLabels" . | nindent 4 }}
selector:
{{- include "influxdb.selectorLabels" . | nindent 4 }}
32 changes: 25 additions & 7 deletions charts/influxdb2/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: StatefulSet
metadata:
name: {{ template "influxdb.fullname" . }}
labels:
{{ include "influxdb.labels" . | nindent 4 }}
{{- include "influxdb.labels" . | nindent 4 }}
spec:
replicas: 1
selector:
Expand All @@ -14,8 +14,13 @@ spec:
metadata:
labels:
{{- include "influxdb.selectorLabels" . | nindent 8 }}
{{- if .Values.podLabels }}
{{ toYaml .Values.podLabels | indent 8 }}
{{- end }}
{{- if .Values.podAnnotations }}
annotations:
{{- toYaml .Values.podAnnotations | nindent 8 }}
{{ toYaml .Values.podAnnotations | indent 8 }}
{{- end }}
spec:
volumes:
- name: data
Expand All @@ -30,6 +35,15 @@ spec:
{{- else }}
emptyDir: {}
{{- end }}
{{- if .Values.initScripts.enabled }}
- name: init
configMap:
name: {{ include "influxdb.fullname" . }}-init
defaultMode: 0744
{{- end }}
{{- if .Values.volumes }}
{{- toYaml .Values.volumes | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "influxdb.serviceAccountName" . }}
containers:
- name: {{ .Chart.Name }}
Expand Down Expand Up @@ -76,22 +90,19 @@ spec:
name: {{ template "influxdb.fullname" . }}-auth
{{- end }}
key: admin-token

# Path to the BoltDB database.
- name: INFLUXD_BOLT_PATH
value: {{ .Values.persistence.mountPath }}/influxd.bolt
# Path to persistent storage engine files where InfluxDB stores all Time-Structure Merge Tree (TSM) data on disk.
- name: INFLUXD_ENGINE_PATH
value: {{ .Values.persistence.mountPath }}

# Extra environment variables from .Values.env
{{- with .Values.env }}
# Extra environment variables from .Values.env
{{- toYaml . | nindent 12 }}
{{- end }}

{{- if .Values.securityContext }}
securityContext:
{{ toYaml .Values.securityContext | nindent 12 }}
{{- toYaml .Values.securityContext | nindent 12 }}
{{- end }}
livenessProbe:
httpGet:
Expand Down Expand Up @@ -127,6 +138,13 @@ spec:
- name: data
mountPath: {{ .Values.persistence.mountPath }}
subPath: {{ .Values.persistence.subPath }}
{{- if .Values.initScripts.enabled }}
- name: init
mountPath: /docker-entrypoint-initdb.d
{{- end }}
{{- if .Values.mountPoints }}
{{- toYaml .Values.mountPoints | nindent 10 }}
{{- end }}
resources:
{{ .Values.resources | toYaml | nindent 12 | trim }}

Expand Down
30 changes: 30 additions & 0 deletions charts/influxdb2/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ image:
tag: 2.2.0-alpine
pullPolicy: IfNotPresent

## Annotations to be added to InfluxDB pods
##
podAnnotations: {}

## Labels to be added to InfluxDB pods
##
podLabels: {}

nameOverride: ""
fullnameOverride: ""

Expand Down Expand Up @@ -120,6 +126,30 @@ persistence:
mountPath: /var/lib/influxdb2
subPath: ""

## Add custom volume and volumeMounts
##
# volumes:
# - name: influxdb2-templates
# hostPath:
# path: /data/influxdb2-templates
# type: Directory
# mountPoints:
# - name: influxdb2-templates
# mountPath: /influxdb2-templates
# readOnly: true

## Allow executing custom init scripts
## If the container finds any files with the .sh extension inside of the
## /docker-entrypoint-initdb.d folder, it will execute them.
## When multiple scripts are present, they will be executed in lexical sort order by name.
## For more details see Custom Initialization Scripts in https://hub.docker.com/_/influxdb
initScripts:
enabled: false
scripts:
init.sh: |+
#!/bin/bash
influx apply --force yes -u https://raw.githubusercontent.com/influxdata/community-templates/master/influxdb2_operational_monitoring/influxdb2_operational_monitoring.yml
## Specify a service type
## ref: http://kubernetes.io/docs/user-guide/services/
##
Expand Down

0 comments on commit 838956b

Please sign in to comment.