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

Commit

Permalink
[metricbeat] split configmap for daemonset and deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
jmlrt committed Apr 10, 2020
1 parent b3bb665 commit 03a0cb7
Show file tree
Hide file tree
Showing 6 changed files with 284 additions and 101 deletions.
70 changes: 38 additions & 32 deletions metricbeat/README.md

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions metricbeat/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,39 @@ data:
{{ $config | indent 4 -}}
{{- end -}}
{{- end -}}

{{- if .Values.daemonset.metricbeatConfig }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "metricbeat.fullname" . }}-daemonset-config
labels:
app: "{{ template "metricbeat.fullname" . }}"
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
data:
{{- range $path, $config := .Values.daemonset.metricbeatConfig }}
{{ $path }}: |
{{ $config | indent 4 -}}
{{- end -}}
{{- end -}}

{{- if .Values.deployment.metricbeatConfig }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "metricbeat.fullname" . }}-deployment-config
labels:
app: "{{ template "metricbeat.fullname" . }}"
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
data:
{{- range $path, $config := .Values.deployment.metricbeatConfig }}
{{ $path }}: |
{{ $config | indent 4 -}}
{{- end -}}
{{- end -}}
12 changes: 12 additions & 0 deletions metricbeat/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ spec:
configMap:
defaultMode: 0600
name: {{ template "metricbeat.fullname" . }}-config
{{- else if .Values.daemonset.metricbeatConfig }}
- name: metricbeat-config
configMap:
defaultMode: 0600
name: {{ template "metricbeat.fullname" . }}-daemonset-config
{{- end }}
- name: data
hostPath:
Expand Down Expand Up @@ -136,6 +141,13 @@ spec:
mountPath: /usr/share/metricbeat/{{ $path }}
readOnly: true
subPath: {{ $path }}
{{ else }}
{{- range $path, $config := .Values.daemonset.metricbeatConfig }}
- name: metricbeat-config
mountPath: /usr/share/metricbeat/{{ $path }}
readOnly: true
subPath: {{ $path }}
{{- end }}
{{- end }}
- name: data
mountPath: /usr/share/metricbeat/data
Expand Down
14 changes: 12 additions & 2 deletions metricbeat/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ spec:
configMap:
defaultMode: 0600
name: {{ template "metricbeat.fullname" . }}-config
{{- else if .Values.deployment.metricbeatConfig }}
- name: metricbeat-config
configMap:
defaultMode: 0600
name: {{ template "metricbeat.fullname" . }}-deployment-config
{{- end }}
{{- if .Values.extraVolumes }}
{{ toYaml .Values.extraVolumes | indent 6 }}
Expand All @@ -69,8 +74,6 @@ spec:
image: "{{ .Values.image }}:{{ .Values.imageTag }}"
imagePullPolicy: "{{ .Values.imagePullPolicy }}"
args:
- "-c"
- "/usr/share/metricbeat/kube-state-metrics-metricbeat.yml"
- "-e"
- "-E"
- "http.enabled=true"
Expand Down Expand Up @@ -111,6 +114,13 @@ spec:
mountPath: /usr/share/metricbeat/{{ $path }}
readOnly: true
subPath: {{ $path }}
{{ else }}
{{- range $path, $config := .Values.deployment.metricbeatConfig }}
- name: metricbeat-config
mountPath: /usr/share/metricbeat/{{ $path }}
readOnly: true
subPath: {{ $path }}
{{- end }}
{{- end }}
{{- if .Values.extraVolumeMounts }}
{{ toYaml .Values.extraVolumeMounts | indent 8 }}
Expand Down
113 changes: 111 additions & 2 deletions metricbeat/tests/metricbeat_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,66 @@ def test_defaults():
r["daemonset"][name]["spec"]["template"]["spec"]["serviceAccountName"] == name
)

volumes = r["daemonset"][name]["spec"]["template"]["spec"]["volumes"]
cfg = r["configmap"]

assert name + "-config" not in cfg
assert name + "-daemonset-config" in cfg
assert name + "-deployment-config" in cfg

assert "metricbeat.yml" in cfg[name + "-daemonset-config"]["data"]
assert "metricbeat.yml" in cfg[name + "-deployment-config"]["data"]

assert "module: system" in cfg[name + "-daemonset-config"]["data"]["metricbeat.yml"]
assert (
"module: system"
not in cfg[name + "-deployment-config"]["data"]["metricbeat.yml"]
)
assert "state_pod" not in cfg[name + "-daemonset-config"]["data"]["metricbeat.yml"]
assert "state_pod" in cfg[name + "-deployment-config"]["data"]["metricbeat.yml"]

daemonset = r["daemonset"][name]["spec"]["template"]["spec"]

assert {
"configMap": {"name": name + "-config", "defaultMode": 0o600},
"name": project + "-config",
} not in daemonset["volumes"]
assert {
"configMap": {"name": name + "-daemonset-config", "defaultMode": 0o600},
"name": project + "-config",
} in daemonset["volumes"]

assert {
"name": "data",
"hostPath": {
"path": "/var/lib/" + name + "-default-data",
"type": "DirectoryOrCreate",
},
} in volumes
} in daemonset["volumes"]

assert {
"mountPath": "/usr/share/metricbeat/metricbeat.yml",
"name": project + "-config",
"subPath": "metricbeat.yml",
"readOnly": True,
} in daemonset["containers"][0]["volumeMounts"]

deployment = r["deployment"][name + "-metrics"]["spec"]["template"]["spec"]

assert {
"configMap": {"name": name + "-config", "defaultMode": 0o600},
"name": project + "-config",
} not in deployment["volumes"]
assert {
"configMap": {"name": name + "-deployment-config", "defaultMode": 0o600},
"name": project + "-config",
} in deployment["volumes"]

assert {
"mountPath": "/usr/share/metricbeat/metricbeat.yml",
"name": project + "-config",
"subPath": "metricbeat.yml",
"readOnly": True,
} in deployment["containers"][0]["volumeMounts"]


def test_adding_a_extra_container():
Expand Down Expand Up @@ -184,6 +236,63 @@ def test_setting_pod_security_context():

def test_adding_in_metricbeat_config():
config = """
daemonset:
metricbeatConfig:
metricbeat.yml: |
key: daemonset
daemonset-config.yml: |
hello = daemonset
deployment:
metricbeatConfig:
metricbeat.yml: |
key: deployment
deployment-config.yml: |
hello = deployment
"""
r = helm_template(config)
cfg = r["configmap"]

assert "metricbeat.yml" in cfg[name + "-daemonset-config"]["data"]
assert "daemonset-config.yml" in cfg[name + "-daemonset-config"]["data"]
assert "deployment-config.yml" not in cfg[name + "-daemonset-config"]["data"]
assert "metricbeat.yml" in cfg[name + "-deployment-config"]["data"]
assert "deployment-config.yml" in cfg[name + "-deployment-config"]["data"]
assert "daemonset-config.yml" not in cfg[name + "-deployment-config"]["data"]

assert "key: daemonset" in cfg[name + "-daemonset-config"]["data"]["metricbeat.yml"]
assert (
"key: deployment" in cfg[name + "-deployment-config"]["data"]["metricbeat.yml"]
)

assert (
"hello = daemonset"
in cfg[name + "-daemonset-config"]["data"]["daemonset-config.yml"]
)
assert (
"hello = deployment"
in cfg[name + "-deployment-config"]["data"]["deployment-config.yml"]
)

daemonset = r["daemonset"][name]["spec"]["template"]["spec"]
assert {
"mountPath": "/usr/share/metricbeat/daemonset-config.yml",
"name": project + "-config",
"subPath": "daemonset-config.yml",
"readOnly": True,
} in daemonset["containers"][0]["volumeMounts"]

deployment = r["deployment"][name + "-metrics"]["spec"]["template"]["spec"]
assert {
"mountPath": "/usr/share/metricbeat/deployment-config.yml",
"name": project + "-config",
"subPath": "deployment-config.yml",
"readOnly": True,
} in deployment["containers"][0]["volumeMounts"]


def test_adding_in_deprecated_metricbeat_config():
config = """
metricbeatConfig:
metricbeat.yml: |
key:
Expand Down
140 changes: 75 additions & 65 deletions metricbeat/values.yaml
Original file line number Diff line number Diff line change
@@ -1,72 +1,82 @@
---

daemonset:
# Allows you to add any config files in /usr/share/metricbeat
# such as metricbeat.yml for daemonset
metricbeatConfig:
metricbeat.yml: |
metricbeat.modules:
- module: kubernetes
metricsets:
- container
- node
- pod
- system
- volume
period: 10s
host: "${NODE_NAME}"
hosts: ["https://${NODE_NAME}:10250"]
bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
ssl.verification_mode: "none"
# If using Red Hat OpenShift remove ssl.verification_mode entry and
# uncomment these settings:
#ssl.certificate_authorities:
#- /var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt
processors:
- add_kubernetes_metadata: ~
- module: kubernetes
enabled: true
metricsets:
- event
- module: system
period: 10s
metricsets:
- cpu
- load
- memory
- network
- process
- process_summary
processes: ['.*']
process.include_top_n:
by_cpu: 5
by_memory: 5
- module: system
period: 1m
metricsets:
- filesystem
- fsstat
processors:
- drop_event.when.regexp:
system.filesystem.mount_point: '^/(sys|cgroup|proc|dev|etc|host|lib)($|/)'
output.elasticsearch:
hosts: '${ELASTICSEARCH_HOSTS:elasticsearch-master:9200}'
deployment:
# Allows you to add any config files in /usr/share/metricbeat
# such as metricbeat.yml for deployment
metricbeatConfig:
metricbeat.yml: |
metricbeat.modules:
- module: kubernetes
enabled: true
metricsets:
- state_node
- state_deployment
- state_replicaset
- state_pod
- state_container
period: 10s
hosts: ["${KUBE_STATE_METRICS_HOSTS}"]
output.elasticsearch:
hosts: '${ELASTICSEARCH_HOSTS:elasticsearch-master:9200}'
# DEPRECATED
# Allows you to add any config files in /usr/share/metricbeat
# such as metricbeat.yml
metricbeatConfig:
metricbeat.yml: |
metricbeat.modules:
- module: kubernetes
metricsets:
- container
- node
- pod
- system
- volume
period: 10s
host: "${NODE_NAME}"
hosts: ["https://${NODE_NAME}:10250"]
bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
ssl.verification_mode: "none"
# If using Red Hat OpenShift remove ssl.verification_mode entry and
# uncomment these settings:
#ssl.certificate_authorities:
#- /var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt
processors:
- add_kubernetes_metadata: ~
- module: kubernetes
enabled: true
metricsets:
- event
- module: system
period: 10s
metricsets:
- cpu
- load
- memory
- network
- process
- process_summary
processes: ['.*']
process.include_top_n:
by_cpu: 5
by_memory: 5
- module: system
period: 1m
metricsets:
- filesystem
- fsstat
processors:
- drop_event.when.regexp:
system.filesystem.mount_point: '^/(sys|cgroup|proc|dev|etc|host|lib)($|/)'
output.elasticsearch:
hosts: '${ELASTICSEARCH_HOSTS:elasticsearch-master:9200}'
kube-state-metrics-metricbeat.yml: |
metricbeat.modules:
- module: kubernetes
enabled: true
metricsets:
- state_node
- state_deployment
- state_replicaset
- state_pod
- state_container
period: 10s
hosts: ["${KUBE_STATE_METRICS_HOSTS}"]
output.elasticsearch:
hosts: '${ELASTICSEARCH_HOSTS:elasticsearch-master:9200}'
# such as metricbeat.yml for both daemonset and deployment
metricbeatConfig: {}

# Replicas being used for the kube-state-metrics metricbeat deployment

replicas: 1

extraContainers: ""
Expand Down

0 comments on commit 03a0cb7

Please sign in to comment.