From 33defe0a8055a686a273c729dce56a298fb57700 Mon Sep 17 00:00:00 2001 From: Steve Chung Date: Tue, 2 Apr 2019 19:18:35 +0900 Subject: [PATCH] [stable/kibana] add tests (#12595) * test stable/kibana Signed-off-by: Steven Chung * stable/kibana test revisions due to PR #12200 Signed-off-by: Steven Chung --- stable/kibana/Chart.yaml | 2 +- stable/kibana/README.md | 3 ++ .../templates/tests/test-configmap.yaml | 35 ++++++++++++++++ stable/kibana/templates/tests/test.yaml | 42 +++++++++++++++++++ stable/kibana/values.yaml | 12 ++++-- 5 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 stable/kibana/templates/tests/test-configmap.yaml create mode 100644 stable/kibana/templates/tests/test.yaml diff --git a/stable/kibana/Chart.yaml b/stable/kibana/Chart.yaml index d39fdb0104..96bb894512 100644 --- a/stable/kibana/Chart.yaml +++ b/stable/kibana/Chart.yaml @@ -1,5 +1,5 @@ name: kibana -version: 2.1.0 +version: 2.2.0 appVersion: 6.7.0 description: Kibana is an open source data visualization plugin for Elasticsearch icon: https://raw.githubusercontent.com/elastic/kibana/master/src/ui/public/icons/kibana-color.svg diff --git a/stable/kibana/README.md b/stable/kibana/README.md index 97b25a33b7..c900c88fe0 100644 --- a/stable/kibana/README.md +++ b/stable/kibana/README.md @@ -112,6 +112,9 @@ The following table lists the configurable parameters of the kibana chart and th | `extraConfigMapMounts` | Additional configmaps to be mounted | `[]` | | `deployment.annotations` | Annotations for deployment | `{}` | | `initContainers` | Init containers to add to the kibana deployment | `{}` | +| `testFramework.image` | `test-framework` image repository. | `dduportal/bats` | +| `testFramework.tag` | `test-framework` image tag. | `0.4.0` | + Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example, diff --git a/stable/kibana/templates/tests/test-configmap.yaml b/stable/kibana/templates/tests/test-configmap.yaml new file mode 100644 index 0000000000..912755e297 --- /dev/null +++ b/stable/kibana/templates/tests/test-configmap.yaml @@ -0,0 +1,35 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ template "kibana.fullname" . }}-test + labels: + app: {{ template "kibana.fullname" . }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + heritage: "{{ .Release.Service }}" + release: "{{ .Release.Name }}" +data: + run.sh: |- + @test "Test Status" { + {{- if .Values.service.selector }} + skip "Can't guarentee pod names with selector" + {{- else }} + {{- $port := .Values.service.externalPort }} + url="http://{{ template "kibana.fullname" . }}{{ if $port }}:{{ $port }}{{ end }}/api{{ .Values.livenessProbe.path }}" + + # retry for 1 minute + run curl -s -o /dev/null -I -w "%{http_code}" --retry 30 --retry-delay 2 $url + + code=$(curl -s -o /dev/null -I -w "%{http_code}" $url) + body=$(curl $url) + if [ "$code" == "503" ] + then + skip "Kibana Unavailable (503), can't get status - see pod logs: $body" + fi + + result=$(echo $body | jq -cr '.status.statuses[]') + [ "$result" != "" ] + + result=$(echo $body | jq -cr '.status.statuses[] | select(.state != "green")') + [ "$result" == "" ] + {{- end }} + } diff --git a/stable/kibana/templates/tests/test.yaml b/stable/kibana/templates/tests/test.yaml new file mode 100644 index 0000000000..8a518fde8d --- /dev/null +++ b/stable/kibana/templates/tests/test.yaml @@ -0,0 +1,42 @@ +apiVersion: v1 +kind: Pod +metadata: + name: {{ template "kibana.fullname" . }}-test + labels: + app: {{ template "kibana.fullname" . }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + heritage: "{{ .Release.Service }}" + release: "{{ .Release.Name }}" + annotations: + "helm.sh/hook": test-success +spec: + initContainers: + - name: test-framework + image: "{{ .Values.testFramework.image}}:{{ .Values.testFramework.tag }}" + command: + - "bash" + - "-c" + - | + set -ex + # copy bats to tools dir + cp -R /usr/local/libexec/ /tools/bats/ + volumeMounts: + - mountPath: /tools + name: tools + containers: + - name: {{ .Release.Name }}-test + image: "dwdraju/alpine-curl-jq" + command: ["/tools/bats/bats", "-t", "/tests/run.sh"] + volumeMounts: + - mountPath: /tests + name: tests + readOnly: true + - mountPath: /tools + name: tools + volumes: + - name: tests + configMap: + name: {{ template "kibana.fullname" . }}-test + - name: tools + emptyDir: {} + restartPolicy: Never diff --git a/stable/kibana/values.yaml b/stable/kibana/values.yaml index a97bc9ed8a..a3310f9f84 100644 --- a/stable/kibana/values.yaml +++ b/stable/kibana/values.yaml @@ -3,6 +3,10 @@ image: tag: "6.7.0" pullPolicy: "IfNotPresent" +testFramework: + image: "dduportal/bats" + tag: "0.4.0" + commandline: args: [] @@ -17,11 +21,11 @@ env: {} # SERVER_DEFAULTROUTE: "/app/kibana" files: - kibana.yml: {} + kibana.yml: ## Default Kibana configuration from kibana-docker. - # server.name: kibana - # server.host: "0" - # elasticsearch.url: http://elasticsearch:9200 + server.name: kibana + server.host: "0" + elasticsearch.url: http://elasticsearch:9200 ## Custom config properties below ## Ref: https://www.elastic.co/guide/en/kibana/current/settings.html