Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Commit

Permalink
[elasticsearch] Automatically detect esMajorVersion for default image
Browse files Browse the repository at this point in the history
Closes: #192
  • Loading branch information
Crazybus committed Jul 5, 2019
1 parent 51d3afd commit e14981c
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 8 deletions.
8 changes: 4 additions & 4 deletions elasticsearch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ helm install --name elasticsearch elastic/elasticsearch --version 7.2.0 --set im
| `roles` | A hash map with the [specific roles](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-node.html) for the node group | `master: true`<br>`data: true`<br>`ingest: true` |
| `replicas` | Kubernetes replica count for the statefulset (i.e. how many pods) | `3` |
| `minimumMasterNodes` | The value for [discovery.zen.minimum_master_nodes](https://www.elastic.co/guide/en/elasticsearch/reference/6.7/discovery-settings.html#minimum_master_nodes). Should be set to `(master_eligible_nodes / 2) + 1`. Ignored in Elasticsearch versions >= 7. | `2` |
| `esMajorVersion` | Used to set major version specific configuration | `7` |
| `esMajorVersion` | Used to set major version specific configuration. If you are using a custom image and not running the default Elasticsearch version you will need to set this to the version you are running (e.g. `esMajorVersion: 6`) | `""` |
| `esConfig` | Allows you to add any config files in `/usr/share/elasticsearch/config/` such as `elasticsearch.yml` and `log4j2.properties`. See [values.yaml](./values.yaml) for an example of the formatting. | `{}` |
| `extraEnvs` | Extra [environment variables](https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/#using-environment-variables-inside-of-your-config) which will be appended to the `env:` definition for the container | `[]` |
| `extraVolumes` | Additional volumes to be passed to the `tpl` function | |
Expand Down Expand Up @@ -95,9 +95,9 @@ helm install --name elasticsearch elastic/elasticsearch --version 7.2.0 --set im
| `service.annotations` | Annotations that Kubernetes will use for the service. This will configure load balancer if `service.type` is `LoadBalancer` [Annotations](https://kubernetes.io/docs/concepts/services-networking/service/#ssl-support-on-aws) | `{}` |
| `updateStrategy` | The [updateStrategy](https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/#updating-statefulsets) for the statefulset. By default Kubernetes will wait for the cluster to be green after upgrading each pod. Setting this to `OnDelete` will allow you to manually delete each pod during upgrades | `RollingUpdate` |
| `maxUnavailable` | The [maxUnavailable](https://kubernetes.io/docs/tasks/run-application/configure-pdb/#specifying-a-poddisruptionbudget) value for the pod disruption budget. By default this will prevent Kubernetes from having more than 1 unhealthy pod in the node group | `1` |
| `fsGroup (DEPRECATED)` | The Group ID (GID) for [securityContext.fsGroup](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/) so that the Elasticsearch user can read from the persistent volume | `` |
| `podSecurityContext` | Allows you to set the [securityContext](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-pod) for the pod | `fsGroup: 1000` |
| `securityContext` | Allows you to set the [securityContext](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-container) for the container | `capabilities.drop:[ALL]`<br>`runAsNonRoot: true`<br>`runAsUser: 1000` |
| `fsGroup (DEPRECATED)` | The Group ID (GID) for [securityContext.fsGroup](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/) so that the Elasticsearch user can read from the persistent volume | `` |
| `podSecurityContext` | Allows you to set the [securityContext](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-pod) for the pod | `fsGroup: 1000` |
| `securityContext` | Allows you to set the [securityContext](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-container) for the container | `capabilities.drop:[ALL]`<br>`runAsNonRoot: true`<br>`runAsUser: 1000` |
| `terminationGracePeriod` | The [terminationGracePeriod](https://kubernetes.io/docs/concepts/workloads/pods/pod/#termination-of-pods) in seconds used when trying to stop the pod | `120` |
| `sysctlVmMaxMapCount` | Sets the [sysctl vm.max_map_count](https://www.elastic.co/guide/en/elasticsearch/reference/current/vm-max-map-count.html#vm-max-map-count) needed for Elasticsearch | `262144` |
| `readinessProbe` | Configuration fields for the [readinessProbe](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/) | `failureThreshold: 3`<br>`initialDelaySeconds: 10`<br>`periodSeconds: 10`<br>`successThreshold: 3`<br>`timeoutSeconds: 5` |
Expand Down
1 change: 0 additions & 1 deletion elasticsearch/examples/6.x/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@

clusterName: "six"
imageTag: "6.8.1"
esMajorVersion: 6
13 changes: 13 additions & 0 deletions elasticsearch/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,16 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this
{{ $uname }}-{{ $i }},
{{- end -}}
{{- end -}}

{{- define "esMajorVersion" -}}
{{- if .Values.esMajorVersion -}}
{{ .Values.esMajorVersion }}
{{- else -}}
{{- $version := int (index (.Values.imageTag | splitList ".") 0) -}}
{{- if and (contains "docker.elastic.co/elasticsearch/elasticsearch" .Values.image) (not (eq $version 0)) -}}
{{ $version }}
{{- else -}}
7
{{- end -}}
{{- end -}}
{{- end -}}
6 changes: 4 additions & 2 deletions elasticsearch/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ metadata:
release: {{ .Release.Name | quote }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
app: "{{ template "uname" . }}"
annotations:
esMajorVersion: "{{ include "esMajorVersion" . }}"
spec:
serviceName: {{ template "uname" . }}-headless
selector:
Expand Down Expand Up @@ -179,15 +181,15 @@ spec:
fieldRef:
fieldPath: metadata.name
{{- if eq .Values.roles.master "true" }}
{{- if ge (int .Values.esMajorVersion) 7 }}
{{- if ge (int (include "esMajorVersion" .)) 7 }}
- name: cluster.initial_master_nodes
value: "{{ template "endpoints" .Values }}"
{{- else }}
- name: discovery.zen.minimum_master_nodes
value: "{{ .Values.minimumMasterNodes }}"
{{- end }}
{{- end }}
{{- if lt (int .Values.esMajorVersion) 7 }}
{{- if lt (int (include "esMajorVersion" .)) 7 }}
- name: discovery.zen.ping.unicast.hosts
value: "{{ template "masterService" . }}-headless"
{{- else }}
Expand Down
31 changes: 31 additions & 0 deletions elasticsearch/tests/elasticsearch_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,3 +655,34 @@ def test_master_termination_fixed_enabled():

c = r['statefulset'][uname]['spec']['template']['spec']['containers'][1]
assert c['name'] == 'elasticsearch-master-graceful-termination-handler'

def test_esMajorVersion_detect_default_version():
config = ''

r = helm_template(config)
assert r['statefulset'][uname]['metadata']['annotations']['esMajorVersion'] == '7'

def test_esMajorVersion_default_to_7_if_not_elastic_image():
config = '''
image: notElastic
imageTag: 1.0.0
'''

r = helm_template(config)
assert r['statefulset'][uname]['metadata']['annotations']['esMajorVersion'] == '7'

def test_esMajorVersion_default_to_7_if_no_version_is_found():
config = '''
imageTag: not_a_number
'''

r = helm_template(config)
assert r['statefulset'][uname]['metadata']['annotations']['esMajorVersion'] == '7'

def test_esMajorVersion_set_to_6_based_on_image_tag():
config = '''
imageTag: 6.8.1
'''

r = helm_template(config)
assert r['statefulset'][uname]['metadata']['annotations']['esMajorVersion'] == '6'
2 changes: 1 addition & 1 deletion elasticsearch/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ roles:
replicas: 3
minimumMasterNodes: 2

esMajorVersion: 7
esMajorVersion: ""

# Allows you to add any config files in /usr/share/elasticsearch/config/
# such as elasticsearch.yml and log4j2.properties
Expand Down

0 comments on commit e14981c

Please sign in to comment.