From 838956b0586e57d784749da54cb6d3122e86fc7f Mon Sep 17 00:00:00 2001 From: alespour <42931850+alespour@users.noreply.github.com> Date: Thu, 2 Jun 2022 14:15:53 +0200 Subject: [PATCH] [influxdb2] add init scripts support (#456) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add init scripts support * add test values files * prettify templates output * bump version Co-authored-by: Pavel Závora * update script execution info in comment Co-authored-by: Pavel Závora * fix trailing spaces * fix default init script to run non-interactively --- charts/influxdb2/Chart.yaml | 2 +- charts/influxdb2/ci/default-values.yaml | 1 + charts/influxdb2/ci/init-scripts-values.yaml | 5 +++ charts/influxdb2/templates/_helpers.tpl | 2 +- charts/influxdb2/templates/init-config.yaml | 10 ++++++ charts/influxdb2/templates/service.yaml | 9 +++--- charts/influxdb2/templates/statefulset.yaml | 32 +++++++++++++++----- charts/influxdb2/values.yaml | 30 ++++++++++++++++++ 8 files changed, 78 insertions(+), 13 deletions(-) create mode 100644 charts/influxdb2/ci/default-values.yaml create mode 100644 charts/influxdb2/ci/init-scripts-values.yaml create mode 100644 charts/influxdb2/templates/init-config.yaml diff --git a/charts/influxdb2/Chart.yaml b/charts/influxdb2/Chart.yaml index b8110cea..13b841b3 100644 --- a/charts/influxdb2/Chart.yaml +++ b/charts/influxdb2/Chart.yaml @@ -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: rawkode@influxdata.com diff --git a/charts/influxdb2/ci/default-values.yaml b/charts/influxdb2/ci/default-values.yaml new file mode 100644 index 00000000..986b68f1 --- /dev/null +++ b/charts/influxdb2/ci/default-values.yaml @@ -0,0 +1 @@ +# Default values only, no overrides diff --git a/charts/influxdb2/ci/init-scripts-values.yaml b/charts/influxdb2/ci/init-scripts-values.yaml new file mode 100644 index 00000000..41169940 --- /dev/null +++ b/charts/influxdb2/ci/init-scripts-values.yaml @@ -0,0 +1,5 @@ +initScripts: + enabled: true + +persistence: + enabled: false diff --git a/charts/influxdb2/templates/_helpers.tpl b/charts/influxdb2/templates/_helpers.tpl index f65c65b8..aa82dac2 100644 --- a/charts/influxdb2/templates/_helpers.tpl +++ b/charts/influxdb2/templates/_helpers.tpl @@ -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 -}} {{/* diff --git a/charts/influxdb2/templates/init-config.yaml b/charts/influxdb2/templates/init-config.yaml new file mode 100644 index 00000000..5f608985 --- /dev/null +++ b/charts/influxdb2/templates/init-config.yaml @@ -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 -}} diff --git a/charts/influxdb2/templates/service.yaml b/charts/influxdb2/templates/service.yaml index aff81880..daada35a 100644 --- a/charts/influxdb2/templates/service.yaml +++ b/charts/influxdb2/templates/service.yaml @@ -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 }} diff --git a/charts/influxdb2/templates/statefulset.yaml b/charts/influxdb2/templates/statefulset.yaml index 8e12cc10..5b1f3d4c 100644 --- a/charts/influxdb2/templates/statefulset.yaml +++ b/charts/influxdb2/templates/statefulset.yaml @@ -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: @@ -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 @@ -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 }} @@ -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: @@ -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 }} diff --git a/charts/influxdb2/values.yaml b/charts/influxdb2/values.yaml index 9863c3d1..68db48f4 100644 --- a/charts/influxdb2/values.yaml +++ b/charts/influxdb2/values.yaml @@ -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: "" @@ -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/ ##