Skip to content

Commit 0e102d4

Browse files
authored
Merge pull request #813 from MetaCell/feature/CH-199-200-elasticsearch-and-env-confs
Feature/ch 199 200 elasticsearch and env confs
2 parents d6897c0 + 9d39f59 commit 0e102d4

34 files changed

Lines changed: 3427 additions & 71 deletions
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# ElasticSearch deployment
2+
3+
Based on https://github.com/elastic/helm-charts/tree/main/elasticsearch
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
tests/
2+
.pytest_cache/
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: v1
2+
description: Official Elastic helm chart for Elasticsearch
3+
home: https://github.com/elastic/helm-charts
4+
maintainers:
5+
- email: helm-charts@elastic.co
6+
name: Elastic
7+
name: elasticsearch
8+
version: 8.5.1
9+
appVersion: 8.5.1
10+
sources:
11+
- https://github.com/elastic/elasticsearch
12+
icon: https://helm.elastic.co/icons/elasticsearch.png
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include ../helpers/common.mk

applications/elasticsearch/deploy/charts/README.md

Lines changed: 490 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
1. Watch all cluster members come up.
2+
$ kubectl get pods --namespace={{ .Release.Namespace }} -l app={{ template "elasticsearch.uname" . }} -w
3+
2. Retrieve elastic user's password.
4+
$ kubectl get secrets --namespace={{ .Release.Namespace }} {{ template "elasticsearch.uname" . }}-credentials -ojsonpath='{.data.password}' | base64 -d
5+
{{- if .Values.tests.enabled }}
6+
3. Test cluster health using Helm test.
7+
$ helm --namespace={{ .Release.Namespace }} test {{ .Release.Name }}
8+
{{- end -}}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
{{/* vim: set filetype=mustache: */}}
2+
{{/*
3+
Expand the name of the chart.
4+
*/}}
5+
{{- define "elasticsearch.name" -}}
6+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
7+
{{- end -}}
8+
9+
{{/*
10+
Create a default fully qualified app name.
11+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
12+
*/}}
13+
{{- define "elasticsearch.fullname" -}}
14+
{{- $name := default .Chart.Name .Values.nameOverride -}}
15+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
16+
{{- end -}}
17+
18+
{{- define "elasticsearch.uname" -}}
19+
{{- if empty .Values.fullnameOverride -}}
20+
{{- if empty .Values.nameOverride -}}
21+
{{ .Values.clusterName }}-{{ .Values.nodeGroup }}
22+
{{- else -}}
23+
{{ .Values.nameOverride }}-{{ .Values.nodeGroup }}
24+
{{- end -}}
25+
{{- else -}}
26+
{{ .Values.fullnameOverride }}
27+
{{- end -}}
28+
{{- end -}}
29+
30+
{{/*
31+
Generate certificates when the secret doesn't exist
32+
*/}}
33+
{{- define "elasticsearch.gen-certs" -}}
34+
{{- $certs := lookup "v1" "Secret" .Release.Namespace ( printf "%s-certs" (include "elasticsearch.uname" . ) ) -}}
35+
{{- if $certs -}}
36+
tls.crt: {{ index $certs.data "tls.crt" }}
37+
tls.key: {{ index $certs.data "tls.key" }}
38+
ca.crt: {{ index $certs.data "ca.crt" }}
39+
{{- else -}}
40+
{{- $altNames := list ( include "elasticsearch.masterService" . ) ( printf "%s.%s" (include "elasticsearch.masterService" .) .Release.Namespace ) ( printf "%s.%s.svc" (include "elasticsearch.masterService" .) .Release.Namespace ) -}}
41+
{{- $ca := genCA "elasticsearch-ca" 365 -}}
42+
{{- $cert := genSignedCert ( include "elasticsearch.masterService" . ) nil $altNames 365 $ca -}}
43+
tls.crt: {{ $cert.Cert | toString | b64enc }}
44+
tls.key: {{ $cert.Key | toString | b64enc }}
45+
ca.crt: {{ $ca.Cert | toString | b64enc }}
46+
{{- end -}}
47+
{{- end -}}
48+
49+
{{- define "elasticsearch.masterService" -}}
50+
{{- if empty .Values.masterService -}}
51+
{{- if empty .Values.fullnameOverride -}}
52+
{{- if empty .Values.nameOverride -}}
53+
{{ .Values.clusterName }}-master
54+
{{- else -}}
55+
{{ .Values.nameOverride }}-master
56+
{{- end -}}
57+
{{- else -}}
58+
{{ .Values.fullnameOverride }}
59+
{{- end -}}
60+
{{- else -}}
61+
{{ .Values.masterService }}
62+
{{- end -}}
63+
{{- end -}}
64+
65+
{{- define "elasticsearch.endpoints" -}}
66+
{{- $replicas := int (toString (.Values.replicas)) }}
67+
{{- $uname := (include "elasticsearch.uname" .) }}
68+
{{- range $i, $e := untilStep 0 $replicas 1 -}}
69+
{{ $uname }}-{{ $i }},
70+
{{- end -}}
71+
{{- end -}}
72+
73+
{{- define "elasticsearch.roles" -}}
74+
{{- range $.Values.roles -}}
75+
{{ . }},
76+
{{- end -}}
77+
{{- end -}}
78+
79+
{{- define "elasticsearch.esMajorVersion" -}}
80+
{{- if .Values.esMajorVersion -}}
81+
{{ .Values.esMajorVersion }}
82+
{{- else -}}
83+
{{- $version := int (index (.Values.imageTag | splitList ".") 0) -}}
84+
{{- if and (contains "docker.elastic.co/elasticsearch/elasticsearch" .Values.image) (not (eq $version 0)) -}}
85+
{{ $version }}
86+
{{- else -}}
87+
8
88+
{{- end -}}
89+
{{- end -}}
90+
{{- end -}}
91+
92+
{{/*
93+
Use the fullname if the serviceAccount value is not set
94+
*/}}
95+
{{- define "elasticsearch.serviceAccount" -}}
96+
{{- .Values.rbac.serviceAccountName | default (include "elasticsearch.uname" .) -}}
97+
{{- end -}}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{{- if .Values.esConfig }}
2+
---
3+
apiVersion: v1
4+
kind: ConfigMap
5+
metadata:
6+
name: {{ template "elasticsearch.uname" . }}-config
7+
labels:
8+
heritage: {{ .Release.Service | quote }}
9+
release: {{ .Release.Name | quote }}
10+
chart: "{{ .Chart.Name }}"
11+
app: "{{ template "elasticsearch.uname" . }}"
12+
data:
13+
{{- range $path, $config := .Values.esConfig }}
14+
{{ $path }}: |
15+
{{ $config | indent 4 -}}
16+
{{- end -}}
17+
{{- end -}}
18+
{{- if .Values.esJvmOptions }}
19+
---
20+
apiVersion: v1
21+
kind: ConfigMap
22+
metadata:
23+
name: {{ template "elasticsearch.uname" . }}-jvm-options
24+
labels:
25+
heritage: {{ .Release.Service | quote }}
26+
release: {{ .Release.Name | quote }}
27+
chart: "{{ .Chart.Name }}"
28+
app: "{{ template "elasticsearch.uname" . }}"
29+
data:
30+
{{- range $path, $config := .Values.esJvmOptions }}
31+
{{ $path }}: |
32+
{{ $config | indent 4 -}}
33+
{{- end -}}
34+
{{- end -}}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{{- if .Values.ingress.enabled -}}
2+
{{- $fullName := include "elasticsearch.uname" . -}}
3+
{{- $httpPort := .Values.httpPort -}}
4+
{{- $pathtype := .Values.ingress.pathtype -}}
5+
{{- $ingressPath := .Values.ingress.path -}}
6+
apiVersion: networking.k8s.io/v1
7+
kind: Ingress
8+
metadata:
9+
name: {{ $fullName }}
10+
labels:
11+
app: {{ .Chart.Name }}
12+
release: {{ .Release.Name }}
13+
heritage: {{ .Release.Service }}
14+
{{- with .Values.ingress.annotations }}
15+
annotations:
16+
{{ toYaml . | indent 4 }}
17+
{{- end }}
18+
spec:
19+
{{- if .Values.ingress.className }}
20+
ingressClassName: {{ .Values.ingress.className | quote }}
21+
{{- end }}
22+
{{- if .Values.ingress.tls }}
23+
tls:
24+
{{- if .ingressPath }}
25+
{{- range .Values.ingress.tls }}
26+
- hosts:
27+
{{- range .hosts }}
28+
- {{ . }}
29+
{{- end }}
30+
secretName: {{ .secretName }}
31+
{{- end }}
32+
{{- else }}
33+
{{ toYaml .Values.ingress.tls | indent 4 }}
34+
{{- end }}
35+
{{- end}}
36+
rules:
37+
{{- range .Values.ingress.hosts }}
38+
{{- if $ingressPath }}
39+
- host: {{ . }}
40+
http:
41+
paths:
42+
- path: {{ $ingressPath }}
43+
pathType: {{ $pathtype }}
44+
backend:
45+
service:
46+
name: {{ $fullName }}
47+
port:
48+
number: {{ $httpPort }}
49+
{{- else }}
50+
- host: {{ .host }}
51+
http:
52+
paths:
53+
{{- range .paths }}
54+
- path: {{ .path }}
55+
pathType: {{ $pathtype }}
56+
backend:
57+
service:
58+
name: {{ $fullName }}
59+
port:
60+
number: {{ .servicePort | default $httpPort }}
61+
{{- end }}
62+
{{- end }}
63+
{{- end }}
64+
{{- end }}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{{- if (or .Values.networkPolicy.http.enabled .Values.networkPolicy.transport.enabled) }}
2+
kind: NetworkPolicy
3+
apiVersion: networking.k8s.io/v1
4+
metadata:
5+
name: {{ template "elasticsearch.uname" . }}
6+
labels:
7+
heritage: {{ .Release.Service | quote }}
8+
release: {{ .Release.Name | quote }}
9+
chart: "{{ .Chart.Name }}"
10+
app: "{{ template "elasticsearch.uname" . }}"
11+
spec:
12+
podSelector:
13+
matchLabels:
14+
app: "{{ template "elasticsearch.uname" . }}"
15+
ingress: # Allow inbound connections
16+
17+
{{- if .Values.networkPolicy.http.enabled }}
18+
# For HTTP access
19+
- ports:
20+
- port: {{ .Values.httpPort }}
21+
from:
22+
# From authorized Pods (having the correct label)
23+
- podSelector:
24+
matchLabels:
25+
{{ template "elasticsearch.uname" . }}-http-client: "true"
26+
{{- with .Values.networkPolicy.http.explicitNamespacesSelector }}
27+
# From authorized namespaces
28+
namespaceSelector:
29+
{{ toYaml . | indent 12 }}
30+
{{- end }}
31+
{{- with .Values.networkPolicy.http.additionalRules }}
32+
# Or from custom additional rules
33+
{{ toYaml . | indent 8 }}
34+
{{- end }}
35+
{{- end }}
36+
37+
{{- if .Values.networkPolicy.transport.enabled }}
38+
# For transport access
39+
- ports:
40+
- port: {{ .Values.transportPort }}
41+
from:
42+
# From authorized Pods (having the correct label)
43+
- podSelector:
44+
matchLabels:
45+
{{ template "elasticsearch.uname" . }}-transport-client: "true"
46+
{{- with .Values.networkPolicy.transport.explicitNamespacesSelector }}
47+
# From authorized namespaces
48+
namespaceSelector:
49+
{{ toYaml . | indent 12 }}
50+
{{- end }}
51+
{{- with .Values.networkPolicy.transport.additionalRules }}
52+
# Or from custom additional rules
53+
{{ toYaml . | indent 8 }}
54+
{{- end }}
55+
# Or from other ElasticSearch Pods
56+
- podSelector:
57+
matchLabels:
58+
app: "{{ template "elasticsearch.uname" . }}"
59+
{{- end }}
60+
61+
{{- end }}

0 commit comments

Comments
 (0)