Skip to content

Commit 0d9ad0c

Browse files
authored
Add elasticsearch (#620)
* Add elasticsearch support * Use openwhisk style * Add ElasticSearch backend store for activation * Add waitForElasticsearch * Change variable * Support external elasticsearch * Change affinity * Add document * Add license header Co-authored-by: ning.yougang <[email protected]>
1 parent db613f3 commit 0d9ad0c

14 files changed

+1016
-0
lines changed

docs/configurationChoices.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,48 @@ redis:
9797
port: <redis port>
9898
```
9999

100+
### Using an external kafka/zookeeper
101+
102+
To use an externally deployed kafka/zookeeper instead of using default single pod deployment, add a stanza like the one
103+
below to your `mycluster.yaml`, substituting in the appropriate values
104+
for `<...>`
105+
106+
```yaml
107+
zookeeper:
108+
external: true
109+
connect_string: <zookeeper connect string>
110+
host: <the first instance of zookeeper>
111+
112+
kafka:
113+
external: true
114+
connect_string: <kafka connect string>
115+
```
116+
117+
### Using activation store backend: ElasticSearch
118+
119+
Currently, deploy-kube uses `CouchDB` for activation store backend by default,
120+
If you want to change it to `ElasticSearch`, just change
121+
122+
```yaml
123+
activationStoreBackend: "ElasticSearch"
124+
```
125+
126+
If you want to use an externally deployed ElasticSearch for activation store backend, add a stanza like the one
127+
below to your `mycluster.yaml`, substituting in the appropriate values
128+
for `<...>`
129+
130+
```yaml
131+
activationStoreBackend: "ElasticSearch"
132+
elasticsearch:
133+
external: true
134+
connect_string: <elasticsearch connect string>
135+
protocol: <"http" or "https">
136+
host: <the first instance of elasticsearch>
137+
indexPattern: <the indexPattern for activation index>
138+
username: <elasticsearch username>
139+
password: <elasticsearch username>
140+
```
141+
100142
### Persistence
101143

102144
Several of the OpenWhisk components that are deployed by the Helm

helm/openwhisk/templates/_helpers.tpl

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ app: {{ template "openwhisk.fullname" . }}
5555
{{ .Values.db.auth.username }}:{{ .Values.db.auth.password }}
5656
{{- end -}}
5757

58+
{{- define "openwhisk.elasticsearch_authentication" -}}
59+
{{ .Values.elasticsearch.username }}:{{ .Values.elasticsearch.password }}
60+
{{- end -}}
61+
5862
{{/* hostname for redis */}}
5963
{{- define "openwhisk.redis_host" -}}
6064
{{- if .Values.redis.external -}}
@@ -341,3 +345,100 @@ imagePullSecrets:
341345
{{ .Files.Get .Values.nginx.certificate.key_file }}
342346
{{- end -}}
343347
{{- end -}}
348+
349+
{{/* vim: set filetype=mustache: */}}
350+
{{/*
351+
Expand the name of the chart.
352+
*/}}
353+
{{- define "elasticsearch.name" -}}
354+
{{- default .Chart.Name .Values.elasticsearch.nameOverride | trunc 63 | trimSuffix "-" -}}
355+
{{- end -}}
356+
357+
{{/*
358+
Create a default fully qualified app name.
359+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
360+
*/}}
361+
{{- define "elasticsearch.fullname" -}}
362+
{{- $name := default .Chart.Name .Values.elasticsearch.nameOverride -}}
363+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
364+
{{- end -}}
365+
366+
{{- define "elasticsearch.uname" -}}
367+
{{- if empty .Values.elasticsearch.fullnameOverride -}}
368+
{{- if empty .Values.elasticsearch.nameOverride -}}
369+
{{ .Values.elasticsearch.clusterName }}-{{ .Values.elasticsearch.nodeGroup }}
370+
{{- else -}}
371+
{{ .Values.elasticsearch.nameOverride }}-{{ .Values.elasticsearch.nodeGroup }}
372+
{{- end -}}
373+
{{- else -}}
374+
{{ .Values.elasticsearch.fullnameOverride }}
375+
{{- end -}}
376+
{{- end -}}
377+
378+
{{- define "elasticsearch.masterService" -}}
379+
{{- if empty .Values.elasticsearch.masterServiceValue -}}
380+
{{- if empty .Values.elasticsearch.fullnameOverride -}}
381+
{{- if empty .Values.elasticsearch.nameOverride -}}
382+
{{ .Values.elasticsearch.clusterName }}-master
383+
{{- else -}}
384+
{{ .Values.elasticsearch.nameOverride }}-master
385+
{{- end -}}
386+
{{- else -}}
387+
{{ .Values.elasticsearch.fullnameOverride }}
388+
{{- end -}}
389+
{{- else -}}
390+
{{ .Values.elasticsearch.masterServiceValue }}
391+
{{- end -}}
392+
{{- end -}}
393+
394+
{{- define "elasticsearch.endpoints" -}}
395+
{{- $replicas := int (toString (.Values.elasticsearch.replicaCount)) }}
396+
{{- $uname := printf "%s-elasticsearch" .Release.Name }}
397+
{{- range $i, $e := untilStep 0 $replicas 1 -}}
398+
{{ $uname }}-{{ $i }},
399+
{{- end -}}
400+
{{- end -}}
401+
402+
{{- define "elasticsearch.esMajorVersion" -}}
403+
{{- if .Values.elasticsearch.esMajorVersionValue -}}
404+
{{ .Values.elasticsearch.esMajorVersionValue }}
405+
{{- else -}}
406+
{{- $version := int (index (.Values.elasticsearch.imageTag | splitList ".") 0) -}}
407+
{{- if and (contains "docker.elastic.co/elasticsearch/elasticsearch" .Values.elasticsearch.image) (not (eq $version 0)) -}}
408+
{{ $version }}
409+
{{- else -}}
410+
7
411+
{{- end -}}
412+
{{- end -}}
413+
{{- end -}}
414+
415+
{{/*
416+
Return the appropriate apiVersion for statefulset.
417+
*/}}
418+
{{- define "elasticsearch.statefulset.apiVersion" -}}
419+
{{- if semverCompare "<1.9-0" .Capabilities.KubeVersion.GitVersion -}}
420+
{{- print "apps/v1beta2" -}}
421+
{{- else -}}
422+
{{- print "apps/v1" -}}
423+
{{- end -}}
424+
{{- end -}}
425+
426+
{{- define "openwhisk.elasticsearch_connect" -}}
427+
{{- if .Values.elasticsearch.external -}}
428+
{{ .Values.elasticsearch.connect_string }}
429+
{{- else -}}
430+
{{- $kname := printf "%s-elasticsearch" .Release.Name }}
431+
{{- $kport := .Values.elasticsearch.httpPort }}
432+
{{- $kubeDomain := .Values.k8s.domain }}
433+
{{- range $i, $e := until (int .Values.elasticsearch.replicaCount) -}}{{ if ne $i 0 }},{{ end }}{{ $kname }}-{{ . }}.{{ $kname }}.{{ $.Release.Namespace }}.svc.{{ $kubeDomain }}:{{ $kport }}{{ end }}
434+
{{- end -}}
435+
{{- end -}}
436+
437+
{{/* host name for server.0 in elasticsearch cluster */}}
438+
{{- define "openwhisk.elasticsearch_zero_host" -}}
439+
{{- if .Values.elasticsearch.external -}}
440+
{{ .Values.elasticsearch.host }}
441+
{{- else -}}
442+
{{ .Release.Name }}-elasticsearch-0.{{ .Release.Name }}-elasticsearch.{{ .Release.Namespace }}.svc.{{ .Values.k8s.domain }}
443+
{{- end -}}
444+
{{- end -}}

helm/openwhisk/templates/_readiness.tpl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,14 @@
6868
value: "http://{{ include "openwhisk.controller_host" . }}:{{ .Values.controller.port }}/invokers/healthy/count"
6969
command: ["sh", "-c", "echo 0 > /tmp/count.txt; while true; do echo 'waiting for healthy invoker'; wget -T 5 -qO /tmp/count.txt --no-check-certificate \"$READINESS_URL\"; NUM_HEALTHY_INVOKERS=$(cat /tmp/count.txt); if [ $NUM_HEALTHY_INVOKERS -gt 0 ]; then echo \"Success: there are $NUM_HEALTHY_INVOKERS healthy invokers\"; break; fi; echo '...not ready yet; sleeping 3 seconds before retry'; sleep 3; done;"]
7070
{{- end -}}
71+
72+
{{/* Init container that waits for ElasticSearch to be ready */}}
73+
{{- define "openwhisk.readiness.waitForElasticSearch" -}}
74+
- name: "wait-for-elasticsearch"
75+
image: "{{- .Values.docker.registry.name -}}busybox"
76+
imagePullPolicy: "IfNotPresent"
77+
env:
78+
- name: "READINESS_URL"
79+
value: {{ .Values.elasticsearch.protocol }}://{{ include "openwhisk.elasticsearch_zero_host" . }}:{{ .Values.elasticsearch.httpPort }}/_cluster/health
80+
command: ["sh", "-c", "while true; do echo 'checking ElasticSearch readiness'; wget -T 5 --spider $READINESS_URL --header=\"Authorization: Basic {{ include "openwhisk.elasticsearch_authentication" . | b64enc }}\"; result=$?; if [ $result -eq 0 ]; then echo 'Success: ElasticSearch is ready!'; break; fi; echo '...not ready yet; sleeping 3 seconds before retry'; sleep 3; done;"]
81+
{{- end -}}

helm/openwhisk/templates/controller-pod.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ spec:
6262
{{ include "openwhisk.readiness.waitForKafka" . | indent 6 }}
6363
{{- end }}
6464
{{ include "openwhisk.readiness.waitForCouchDB" . | indent 6 }}
65+
{{- if eq .Values.activationStoreBackend "ElasticSearch" }}
66+
# The controller must wait for elasticsearch to be ready before it starts
67+
{{ include "openwhisk.readiness.waitForElasticSearch" . | indent 6 }}
68+
{{- end }}
6569
# The lean controller requires invoker volumes mounts
6670
{{- if .Values.controller.lean }}
6771
{{ include "openwhisk.invoker.volumes" . }}
@@ -182,6 +186,20 @@ spec:
182186
- name: "CONFIG_whisk_userEvents_enabled"
183187
value: "true"
184188
{{ end }}
189+
{{- if eq .Values.activationStoreBackend "ElasticSearch" }}
190+
- name: "CONFIG_whisk_activationStore_elasticsearch_protocol"
191+
value: "{{ .Values.elasticsearch.protocol }}"
192+
- name: "CONFIG_whisk_activationStore_elasticsearch_hosts"
193+
value: {{ template "openwhisk.elasticsearch_connect" . }}
194+
- name: "CONFIG_whisk_activationStore_elasticsearch_indexPattern"
195+
value: {{ .Values.elasticsearch.indexPattern }}
196+
- name: "CONFIG_whisk_activationStore_elasticsearch_username"
197+
value: "{{ .Values.elasticsearch.username }}"
198+
- name: "CONFIG_whisk_activationStore_elasticsearch_password"
199+
value: "{{ .Values.elasticsearch.password }}"
200+
- name: "CONFIG_whisk_spi_ActivationStoreProvider"
201+
value: "org.apache.openwhisk.core.database.elasticsearch.ElasticSearchActivationStoreProvider"
202+
{{- end }}
185203
# properties for lean messaging provider
186204
{{ include "openwhisk.lean.provider" . | indent 8 }}
187205

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
{{- if and (not .Values.elasticsearch.external) (eq .Values.activationStoreBackend "ElasticSearch") .Values.elasticsearch.esConfig }}
19+
apiVersion: v1
20+
kind: ConfigMap
21+
metadata:
22+
name: {{ .Release.Name }}-elasticsearch-cm
23+
labels:
24+
{{ include "openwhisk.label_boilerplate" .| indent 4 }}
25+
data:
26+
{{- range $path, $config := .Values.elasticsearch.esConfig }}
27+
{{ $path }}: |
28+
{{ $config | indent 4 -}}
29+
{{- end -}}
30+
{{- end -}}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
---
19+
{{- if and .Values.pdb.enable (not .Values.elasticsearch.external) (eq .Values.activationStoreBackend "ElasticSearch") }}
20+
apiVersion: policy/v1beta1
21+
kind: PodDisruptionBudget
22+
metadata:
23+
name: {{ .Release.Name }}-elasticsearch-pdb
24+
labels:
25+
{{ include "openwhisk.label_boilerplate" .| indent 4 }}
26+
spec:
27+
maxUnavailable: {{ .Values.pdb.elasticsearch.maxUnavailable | default 1 }}
28+
selector:
29+
matchLabels:
30+
name: {{ .Release.Name }}-elasticsearch
31+
{{- end }}

0 commit comments

Comments
 (0)