From f2a5108dd90ad0d07c005c98691560d46947257a Mon Sep 17 00:00:00 2001 From: Trevor Hartman Date: Wed, 31 May 2017 14:38:19 -0600 Subject: [PATCH 1/2] Add the option to automatically install TICK scripts from a specified directory --- kapacitor/README.md | 22 +++++- kapacitor/templates/tickscript-init-job.yaml | 74 ++++++++++++++++++++ kapacitor/values.yaml | 9 +++ 3 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 kapacitor/templates/tickscript-init-job.yaml diff --git a/kapacitor/README.md b/kapacitor/README.md index bac50c2..567b78e 100644 --- a/kapacitor/README.md +++ b/kapacitor/README.md @@ -7,7 +7,7 @@ ## QuickStart ```bash -$ helm install stable/kapacitor --name foo --namespace bar +$ helm install --wait stable/kapacitor --name foo --namespace bar ``` ## Introduction @@ -24,7 +24,7 @@ This chart bootstraps A Kapacitor deployment and service on a Kubernetes cluster To install the chart with the release name `my-release`: ```bash -$ helm install --name my-release stable/kapacitor +$ helm install --wait --name my-release stable/kapacitor ``` The command deploys Kapacitor on the Kubernetes cluster in the default configuration. The [configuration](#configuration) section lists the parameters that can be configured during installation. @@ -65,8 +65,24 @@ $ helm install --name my-release -f values.yaml stable/kapacitor > **Tip**: You can use the default [values.yaml](values.yaml) +## Automatic TICK script installation + +TICK scripts can be installed from a specified directory via a Kubernetes job +with Helm `post-install` and `post-upgrade` hooks. It's disabled by default. To +enable use: + +```bash +$ helm install --name my-release \ + --set "install_tick_scripts.enabled=true" \ + --set "install_tick_scripts.tick_dir=/tick" \ + --set "install_tick_scripts.kapacitorURL=http://kapacitor:9092" \ + -f values.yaml stable/kapacitor +``` + +Or modify the default values in `values.yaml`. + ## Persistence The [Kapacitor](https://hub.docker.com/_/kapacitor/) image stores data in the `/var/lib/kapacitor` directory in the container. -The chart optionally mounts a [Persistent Volume](kubernetes.io/docs/user-guide/persistent-volumes/) volume at this location. The volume is created using dynamic volume provisioning. \ No newline at end of file +The chart optionally mounts a [Persistent Volume](kubernetes.io/docs/user-guide/persistent-volumes/) volume at this location. The volume is created using dynamic volume provisioning. diff --git a/kapacitor/templates/tickscript-init-job.yaml b/kapacitor/templates/tickscript-init-job.yaml new file mode 100644 index 0000000..eed6e42 --- /dev/null +++ b/kapacitor/templates/tickscript-init-job.yaml @@ -0,0 +1,74 @@ +{{if .Values.install_tick_scripts.enabled }} +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ template "fullname" . }}-init + labels: + app: {{ template "fullname" . }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + release: "{{ .Release.Name }}" + heritage: "{{ .Release.Service }}" +data: + init.sh: |- + #!/usr/bin/env bash + export KAPACITOR_URL={{ .Values.install_tick_scripts.kapacitorURL }} + ls -al $TICK_DIR + kapacitor list tasks + + echo "Loading TICK files from $TICK_DIR" + for f in ${TICK_DIR}/*.tick + do + name="$(basename $f)" + name="${name/.tick/}" + kapacitor define $name \ + -type batch \ + -dbrp telegraf.autogen \ + -tick $f + kapacitor enable $name + done + echo DONE + kapacitor list tasks +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: {{ template "fullname" . }}-init-job + labels: + chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + release: {{ .Release.Name | quote }} + heritage: {{ .Release.Service | quote }} + app: {{ template "fullname" . }} + annotations: + "helm.sh/hook": post-install,post-upgrade +spec: + template: + metadata: + name: "{{.Release.Name}}" + labels: + heritage: {{.Release.Service | quote }} + release: {{.Release.Name | quote }} + chart: "{{.Chart.Name}}-{{.Chart.Version}}" + spec: + restartPolicy: OnFailure + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + command: ["bash", "/init/init.sh"] + env: + - name: TICK_DIR + value: "{{ .Values.install_tick_scripts.tick_dir }}" + volumeMounts: + - name: alerts + mountPath: /tick + - name: init + mountPath: /init + volumes: + - name: alerts + configMap: + name: {{ template "fullname" . }}-alerts + - name: init + configMap: + name: {{ template "fullname" . }}-init +{{- end }} diff --git a/kapacitor/values.yaml b/kapacitor/values.yaml index 0086b9a..e0011ae 100644 --- a/kapacitor/values.yaml +++ b/kapacitor/values.yaml @@ -39,3 +39,12 @@ resources: ## ref: https://docs.influxdata.com/kapacitor/v1.1/introduction/getting_started/ ## influxURL: http://data-influxdb.tick:8086 + + +## A Kubernetes Job can be used to install TICK scripts from a specified +## tick_dir directory, if enabled. +## +install_tick_scripts: + kapacitorURL: http://kapacitor:9092 + enabled: false + tick_dir: /tick From e48a0515318f0793a170527304fc499940ba2bd5 Mon Sep 17 00:00:00 2001 From: Trevor Hartman Date: Wed, 31 May 2017 19:33:11 -0600 Subject: [PATCH 2/2] Set KAPACITOR_URL directly --- kapacitor/README.md | 3 +-- kapacitor/templates/tickscript-init-job.yaml | 2 +- kapacitor/values.yaml | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/kapacitor/README.md b/kapacitor/README.md index 567b78e..aa98e5c 100644 --- a/kapacitor/README.md +++ b/kapacitor/README.md @@ -72,10 +72,9 @@ with Helm `post-install` and `post-upgrade` hooks. It's disabled by default. To enable use: ```bash -$ helm install --name my-release \ +helm install --name my-release \ --set "install_tick_scripts.enabled=true" \ --set "install_tick_scripts.tick_dir=/tick" \ - --set "install_tick_scripts.kapacitorURL=http://kapacitor:9092" \ -f values.yaml stable/kapacitor ``` diff --git a/kapacitor/templates/tickscript-init-job.yaml b/kapacitor/templates/tickscript-init-job.yaml index eed6e42..30e675b 100644 --- a/kapacitor/templates/tickscript-init-job.yaml +++ b/kapacitor/templates/tickscript-init-job.yaml @@ -12,7 +12,7 @@ metadata: data: init.sh: |- #!/usr/bin/env bash - export KAPACITOR_URL={{ .Values.install_tick_scripts.kapacitorURL }} + export KAPACITOR_URL="{{ template "fullname" . }}.{{ .Release.Namespace }}:9092" ls -al $TICK_DIR kapacitor list tasks diff --git a/kapacitor/values.yaml b/kapacitor/values.yaml index e0011ae..d785d62 100644 --- a/kapacitor/values.yaml +++ b/kapacitor/values.yaml @@ -45,6 +45,5 @@ influxURL: http://data-influxdb.tick:8086 ## tick_dir directory, if enabled. ## install_tick_scripts: - kapacitorURL: http://kapacitor:9092 enabled: false tick_dir: /tick