From 886cac277eaaada4ac2c1495c81a11f025c588b9 Mon Sep 17 00:00:00 2001 From: John Bai Date: Tue, 28 Apr 2020 13:42:04 +0800 Subject: [PATCH] [incubator/solr] Allow adding a custom script to be run before starting Solr (using the entry point of the official Solr Docker Image) (#21598) * Allow adding a custom script to be run before starting Solr Signed-off-by: John Bai * Allow adding a custom script to be run before starting Solr Signed-off-by: John Bai * Update incubator/solr/Chart.yaml Bump version for new features Co-Authored-By: Carlos Tadeu Panato Junior Signed-off-by: John Bai Co-authored-by: Carlos Tadeu Panato Junior --- incubator/solr/Chart.yaml | 2 +- incubator/solr/README.md | 2 ++ incubator/solr/templates/_helpers.tpl | 7 +++++++ incubator/solr/templates/solr-custom-script.yaml | 13 +++++++++++++ incubator/solr/templates/statefulset.yaml | 12 ++++++++++++ incubator/solr/values.yaml | 4 ++++ 6 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 incubator/solr/templates/solr-custom-script.yaml diff --git a/incubator/solr/Chart.yaml b/incubator/solr/Chart.yaml index a2f8156f9b..9c276467f3 100644 --- a/incubator/solr/Chart.yaml +++ b/incubator/solr/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: "v1" name: "solr" -version: "1.4.0" +version: "1.5.0" appVersion: "8.4.0" description: "A helm chart to install Apache Solr: http://lucene.apache.org/solr/" keywords: diff --git a/incubator/solr/README.md b/incubator/solr/README.md index de97af3cbb..e8bb94dc20 100644 --- a/incubator/solr/README.md +++ b/incubator/solr/README.md @@ -31,6 +31,8 @@ The following table shows the configuration options for the Solr helm chart: | `javaMem` | JVM memory settings to pass to Solr | `-Xms2g -Xmx3g` | | `resources` | Resource limits and requests to set on the solr pods | `{}` | | `extraEnvVars` | Additional environment variables to set on the solr pods (in yaml syntax) | `[]` | +| `initScript` | The file name of the custom script to be run before starting Solr | `""` | + | `terminationGracePeriodSeconds` | The termination grace period of the Solr pods | `180`| | `image.repository` | The repository to pull the docker image from| `solr` | | `image.tag` | The tag on the repository to pull | `7.7.2` | diff --git a/incubator/solr/templates/_helpers.tpl b/incubator/solr/templates/_helpers.tpl index 4269fdb700..d6f80d6b40 100644 --- a/incubator/solr/templates/_helpers.tpl +++ b/incubator/solr/templates/_helpers.tpl @@ -80,6 +80,13 @@ Create chart name and version as used by the chart label. {{- printf "%s-%s" (include "solr.fullname" .) "config-map" | trunc 63 | trimSuffix "-" -}} {{- end -}} +{{/* + Define the name of the custom script configmap +*/}} +{{- define "solr.custom-script.configmap-name" -}} +{{- printf "%s-%s" (include "solr.fullname" .) "custom-script-config-map" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + {{/* Define the labels that should be applied to all resources in the chart */}} diff --git a/incubator/solr/templates/solr-custom-script.yaml b/incubator/solr/templates/solr-custom-script.yaml new file mode 100644 index 0000000000..41c0e13ed2 --- /dev/null +++ b/incubator/solr/templates/solr-custom-script.yaml @@ -0,0 +1,13 @@ +{{ if not ( eq .Values.initScript "" ) }} +--- + +apiVersion: "v1" +kind: "ConfigMap" +metadata: + name: "{{ include "solr.custom-script.configmap-name" . }}" + labels: +{{ include "solr.common.labels" . | indent 4}} +data: + solr-init.sh: | +{{ .Files.Get .Values.initScript | indent 4}} +{{ end }} diff --git a/incubator/solr/templates/statefulset.yaml b/incubator/solr/templates/statefulset.yaml index fb8df5b2e1..3b048c5955 100644 --- a/incubator/solr/templates/statefulset.yaml +++ b/incubator/solr/templates/statefulset.yaml @@ -55,6 +55,14 @@ spec: items: - key: solr.xml path: solr.xml +{{- if not ( eq .Values.initScript "" ) }} + - name: solr-init-script + configMap: + name: {{ include "solr.custom-script.configmap-name" . }} + items: + - key: solr-init.sh + path: solr-init.sh +{{- end }} initContainers: - name: check-zk image: busybox:latest @@ -199,6 +207,10 @@ spec: volumeMounts: - name: {{ include "solr.pvc-name" . }} mountPath: /opt/solr/server/home +{{- if not ( eq .Values.initScript "" ) }} + - name: solr-init-script + mountPath: /docker-entrypoint-initdb.d +{{- end }} {{ if .Values.tls.enabled }} - name: "keystore-volume" mountPath: "/etc/ssl/keystores" diff --git a/incubator/solr/values.yaml b/incubator/solr/values.yaml index cafb88cb21..913e084bc8 100644 --- a/incubator/solr/values.yaml +++ b/incubator/solr/values.yaml @@ -22,6 +22,10 @@ resources: {} # Extra environment variables - allows yaml definitions extraEnvVars: [] +# Specify the initial script file name here to be executed before starting Solr +# The file is located relative to the solr chart root folder +initScript: "" + # Sets the termination Grace period for the solr pods # This can take a while for shards to elect new leaders terminationGracePeriodSeconds: 180