From ce8c1b2c0b80a5cb182b588d6eedc606b4a88ae6 Mon Sep 17 00:00:00 2001 From: nathan patel Date: Wed, 26 Jun 2019 17:21:28 +0100 Subject: [PATCH 1/3] Add resources to sidecar container. Some K8s clusters have requirements that all containers contain resource definitions. This provides the option to add resource limits to sidecar containers. --- elasticsearch/templates/statefulset.yaml | 2 ++ elasticsearch/tests/elasticsearch_test.py | 24 +++++++++++++++++++++++ elasticsearch/values.yaml | 8 ++++++++ 3 files changed, 34 insertions(+) diff --git a/elasticsearch/templates/statefulset.yaml b/elasticsearch/templates/statefulset.yaml index be2d44f8e..683ddb83a 100644 --- a/elasticsearch/templates/statefulset.yaml +++ b/elasticsearch/templates/statefulset.yaml @@ -263,6 +263,8 @@ spec: sleep infinity & wait $! + resources: +{{ toYaml .Values.sidecarResources | indent 10 }} env: - name: NODE_NAME valueFrom: diff --git a/elasticsearch/tests/elasticsearch_test.py b/elasticsearch/tests/elasticsearch_test.py index 9422858a2..c65f6174f 100755 --- a/elasticsearch/tests/elasticsearch_test.py +++ b/elasticsearch/tests/elasticsearch_test.py @@ -459,6 +459,30 @@ def test_adding_resources_to_initcontainer(): } } +def test_adding_resources_to_sidecar_container(): + config = ''' +initResources: + limits: + cpu: "100m" + memory: "128Mi" + requests: + cpu: "100m" + memory: "128Mi" +''' + r = helm_template(config) + i = r['statefulset'][uname]['spec']['template']['spec']['initContainers'][0] + + assert i['resources'] == { + 'requests': { + 'cpu': '100m', + 'memory': '128Mi' + }, + 'limits': { + 'cpu': '100m', + 'memory': '128Mi' + } + } + def test_adding_a_node_affinity(): config = ''' nodeAffinity: diff --git a/elasticsearch/values.yaml b/elasticsearch/values.yaml index 14d28f71a..8db4418da 100755 --- a/elasticsearch/values.yaml +++ b/elasticsearch/values.yaml @@ -67,6 +67,14 @@ initResources: {} # cpu: "25m" # memory: "128Mi" +sidecarResources: {} + # limits: + # cpu: "25m" + # # memory: "128Mi" + # requests: + # cpu: "25m" + # memory: "128Mi" + networkHost: "0.0.0.0" volumeClaimTemplate: From 63690215a32d2d6aa45c3a586d8fdc361d255f30 Mon Sep 17 00:00:00 2001 From: nathan patel Date: Wed, 26 Jun 2019 18:11:02 +0100 Subject: [PATCH 2/3] Update README. --- elasticsearch/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/elasticsearch/README.md b/elasticsearch/README.md index a17ea420d..d8b21feda 100644 --- a/elasticsearch/README.md +++ b/elasticsearch/README.md @@ -77,6 +77,7 @@ helm install --name elasticsearch elastic/elasticsearch --version 7.1.1 --set im | `esJavaOpts` | [Java options](https://www.elastic.co/guide/en/elasticsearch/reference/current/jvm-options.html) for Elasticsearch. This is where you should configure the [jvm heap size](https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html) | `-Xmx1g -Xms1g` | | `resources` | Allows you to set the [resources](https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/) for the statefulset | `requests.cpu: 100m`
`requests.memory: 2Gi`
`limits.cpu: 1000m`
`limits.memory: 2Gi` | | `initResources` | Allows you to set the [resources](https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/) for the initContainer in the statefulset | {} | +| `sidecarResources` | Allows you to set the [resources](https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/) for the sidecar containers in the statefulset | {} | | `networkHost` | Value for the [network.host Elasticsearch setting](https://www.elastic.co/guide/en/elasticsearch/reference/current/network.host.html) | `0.0.0.0` | | `volumeClaimTemplate` | Configuration for the [volumeClaimTemplate for statefulsets](https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#stable-storage). You will want to adjust the storage (default `30Gi`) and the `storageClassName` if you are using a different storage class | `accessModes: [ "ReadWriteOnce" ]`
`resources.requests.storage: 30Gi` | | `persistence.annotations` | Additional persistence annotations for the `volumeClaimTemplate` | `{}` | From f17997b53cda461eb876d2912032a6cce4e208b4 Mon Sep 17 00:00:00 2001 From: nathan patel Date: Wed, 26 Jun 2019 23:06:41 +0100 Subject: [PATCH 3/3] Fix test. --- elasticsearch/tests/elasticsearch_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/elasticsearch/tests/elasticsearch_test.py b/elasticsearch/tests/elasticsearch_test.py index c65f6174f..55fcb8acc 100755 --- a/elasticsearch/tests/elasticsearch_test.py +++ b/elasticsearch/tests/elasticsearch_test.py @@ -461,7 +461,7 @@ def test_adding_resources_to_initcontainer(): def test_adding_resources_to_sidecar_container(): config = ''' -initResources: +sidecarResources: limits: cpu: "100m" memory: "128Mi" @@ -470,7 +470,7 @@ def test_adding_resources_to_sidecar_container(): memory: "128Mi" ''' r = helm_template(config) - i = r['statefulset'][uname]['spec']['template']['spec']['initContainers'][0] + i = r['statefulset'][uname]['spec']['template']['spec']['containers'][1] assert i['resources'] == { 'requests': {