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

Commit

Permalink
[metricbeat] split resources for daemonset and deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
jmlrt committed Apr 14, 2020
1 parent 2a5e45d commit c8af71b
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 18 deletions.
14 changes: 8 additions & 6 deletions metricbeat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ helm install --name metricbeat elastic/metricbeat --set imageTag=7.6.2

## Configuration
| Parameter | Description | Default |
| ----------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| --- | --- | --- |
| `daemonset.affinity` | Configurable [affinity][] for Metricbeat `DaemonSet`. | `{}` |
| `daemonset.metricbeatConfig` | Allows you to add any config files in `/usr/share/metricbeat` such as `metricbeat.yml` for Metricbeat `DaemonSet`. | see [values.yaml][] |
| `daemonset.resources` | Allows you to set the [resources][] for Metricbeat `DaemonSet` | `requests.cpu: 100m`<br>`requests.memory: 100Mi`<br>`limits.cpu: 1000m`<br>`limits.memory: 200Mi` |
| `deployment.affinity` | Configurable [affinity][] for Metricbeat `Deployment`. | `{}` |
| `deployment.metricbeatConfig` | Allows you to add any config files in `/usr/share/metricbeat` such as `metricbeat.yml` for Metricbeat `Deployment`. | see [values.yaml][] |
| `deployment.resources` | Allows you to set the [resources][] for Metricbeat `Deployment` | `requests.cpu: 100m`<br>`requests.memory: 100Mi`<br>`limits.cpu: 1000m`<br>`limits.memory: 200Mi` |
| `extraContainers` | Templatable string of additional containers to be passed to the `tpl` function | `""` |
| `extraInitContainers` | Templatable string of additional containers to be passed to the `tpl` function | `""` |
| `extraEnvs` | Extra [environment variables][] which will be appended to the `env:` definition for the container | `[]` |
Expand All @@ -89,7 +91,6 @@ helm install --name metricbeat elastic/metricbeat --set imageTag=7.6.2
| `podSecurityContext` | Configurable [podSecurityContext][] for Metricbeat pod execution environment | `runAsUser: 0`<br>`privileged: false` |
| `livenessProbe` | Parameters to pass to [liveness probe][] checks for values such as timeouts and thresholds. | `failureThreshold: 3`<br>`initialDelaySeconds: 10`<br>`periodSeconds: 10`<br>`successThreshold: 3`<br>`timeoutSeconds: 5` |
| `readinessProbe` | Parameters to pass to [readiness probe][] checks for values such as timeouts and thresholds. | `failureThreshold: 3`<br>`initialDelaySeconds: 10`<br>`periodSeconds: 10`<br>`successThreshold: 3`<br>`timeoutSeconds: 5` |
| `resources` | Allows you to set the [resources][] for the `DaemonSet` | `requests.cpu: 100m`<br>`requests.memory: 100Mi`<br>`limits.cpu: 1000m`<br>`limits.memory: 200Mi` |
| `serviceAccount` | Custom [serviceAccount][] that Metricbeat will use during execution. By default will use the service account created by this chart. | `""` |
| `secretMounts` | Allows you easily mount a secret as a file inside the `DaemonSet`. Useful for mounting certificates and other secrets. See [values.yaml][] for an example | `[]` |
| `terminationGracePeriod` | Termination period (in seconds) to wait before killing Metricbeat pod process on pod shutdown | `30` |
Expand All @@ -101,10 +102,11 @@ helm install --name metricbeat elastic/metricbeat --set imageTag=7.6.2
| `fullnameOverride` | Overrides the full name of the resources. If not set the name will default to "`.Release.Name`-`.Values.nameOverride or .Chart.Name`" | `""` |

### Deprecated
| Parameter | Description | Default |
| ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------- | ------------------- |
| `affinity` | Configurable [affinity][] | `{}` |
| `metricbeatConfig` | Allows you to add any config files in `/usr/share/metricbeat` such as `metricbeat.yml` for both Metricbeat `DaemonSet` and `Deployment`. | see [values.yaml][] |
| Parameter | Description | Default |
| --- | --- | --- |
| `affinity` | Configurable [affinity][] | `{}` |
| `metricbeatConfig` | Allows you to add any config files in `/usr/share/metricbeat` such as `metricbeat.yml` for both Metricbeat `DaemonSet` and `Deployment`. | see [values.yaml][] |
| `resources` | Allows you to set the [resources][] for both Metricbeat `DaemonSet` and `Deployment`. | `requests.cpu: 100m`<br>`requests.memory: 100Mi`<br>`limits.cpu: 1000m`<br>`limits.memory: 200Mi` |

## Examples

Expand Down
3 changes: 1 addition & 2 deletions metricbeat/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ spec:
{{ toYaml .Values.livenessProbe | indent 10 }}
readinessProbe:
{{ toYaml .Values.readinessProbe | indent 10 }}
resources:
{{ toYaml .Values.resources | indent 10 }}
resources: {{ toYaml ( .Values.resources | default .Values.daemonset.resources ) | nindent 10 }}
env:
- name: POD_NAMESPACE
valueFrom:
Expand Down
3 changes: 1 addition & 2 deletions metricbeat/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ spec:
{{ toYaml .Values.livenessProbe | indent 10 }}
readinessProbe:
{{ toYaml .Values.readinessProbe | indent 10 }}
resources:
{{ toYaml .Values.resources | indent 10 }}
resources: {{ toYaml ( .Values.resources | default .Values.deployment.resources ) | nindent 10 }}
env:
- name: POD_NAMESPACE
valueFrom:
Expand Down
84 changes: 84 additions & 0 deletions metricbeat/tests/metricbeat_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ def test_defaults():
"readOnly": True,
} in deployment["containers"][0]["volumeMounts"]

assert daemonset["containers"][0]["resources"] == {
"requests": {"cpu": "100m", "memory": "100Mi"},
"limits": {"cpu": "1000m", "memory": "200Mi"},
}
assert deployment["containers"][0]["resources"] == {
"requests": {"cpu": "100m", "memory": "100Mi"},
"limits": {"cpu": "1000m", "memory": "200Mi"},
}


def test_adding_a_extra_container():
config = """
Expand Down Expand Up @@ -541,6 +550,81 @@ def test_adding_env_from():
assert configMapRef == {"name": "configmap-name"}


def test_overriding_resources():
config = """
daemonset:
resources:
limits:
cpu: "25m"
memory: "128Mi"
requests:
cpu: "25m"
memory: "128Mi"
"""
r = helm_template(config)
assert r["daemonset"][name]["spec"]["template"]["spec"]["containers"][0][
"resources"
] == {
"requests": {"cpu": "25m", "memory": "128Mi"},
"limits": {"cpu": "25m", "memory": "128Mi"},
}
assert r["deployment"][name + "-metrics"]["spec"]["template"]["spec"]["containers"][
0
]["resources"] == {
"requests": {"cpu": "100m", "memory": "100Mi"},
"limits": {"cpu": "1000m", "memory": "200Mi"},
}

config = """
deployment:
resources:
limits:
cpu: "25m"
memory: "128Mi"
requests:
cpu: "25m"
memory: "128Mi"
"""
r = helm_template(config)
assert r["daemonset"][name]["spec"]["template"]["spec"]["containers"][0][
"resources"
] == {
"requests": {"cpu": "100m", "memory": "100Mi"},
"limits": {"cpu": "1000m", "memory": "200Mi"},
}
assert r["deployment"][name + "-metrics"]["spec"]["template"]["spec"]["containers"][
0
]["resources"] == {
"requests": {"cpu": "25m", "memory": "128Mi"},
"limits": {"cpu": "25m", "memory": "128Mi"},
}


def test_adding_deprecated_resources():
config = """
resources:
limits:
cpu: "25m"
memory: "128Mi"
requests:
cpu: "25m"
memory: "128Mi"
"""
r = helm_template(config)
assert r["daemonset"][name]["spec"]["template"]["spec"]["containers"][0][
"resources"
] == {
"requests": {"cpu": "25m", "memory": "128Mi"},
"limits": {"cpu": "25m", "memory": "128Mi"},
}
assert r["deployment"][name + "-metrics"]["spec"]["template"]["spec"]["containers"][
0
]["resources"] == {
"requests": {"cpu": "25m", "memory": "128Mi"},
"limits": {"cpu": "25m", "memory": "128Mi"},
}


def test_setting_fullnameOverride():
config = """
fullnameOverride: 'metricbeat-custom'
Expand Down
23 changes: 15 additions & 8 deletions metricbeat/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ daemonset:
system.filesystem.mount_point: '^/(sys|cgroup|proc|dev|etc|host|lib)($|/)'
output.elasticsearch:
hosts: '${ELASTICSEARCH_HOSTS:elasticsearch-master:9200}'
resources:
requests:
cpu: "100m"
memory: "100Mi"
limits:
cpu: "1000m"
memory: "200Mi"

deployment:
affinity: {}
Expand All @@ -72,6 +79,13 @@ deployment:
hosts: ["${KUBE_STATE_METRICS_HOSTS}"]
output.elasticsearch:
hosts: '${ELASTICSEARCH_HOSTS:elasticsearch-master:9200}'
resources:
requests:
cpu: "100m"
memory: "100Mi"
limits:
cpu: "1000m"
memory: "200Mi"

# DEPRECATED
# Allows you to add any config files in /usr/share/metricbeat
Expand Down Expand Up @@ -186,14 +200,6 @@ podSecurityContext:
runAsUser: 0
privileged: false

resources:
requests:
cpu: "100m"
memory: "100Mi"
limits:
cpu: "1000m"
memory: "200Mi"

# Custom service account override that the pod will use
serviceAccount: ""

Expand Down Expand Up @@ -224,3 +230,4 @@ fullnameOverride: ""

# DEPRECATED
affinity: {}
resources: {}

0 comments on commit c8af71b

Please sign in to comment.