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

Make kube-state-metrics optional for installation #387

Merged
merged 1 commit into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions metricbeat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ as a reference. They are also used in the automated testing of this chart.
| `imagePullSecrets` | Configuration for [imagePullSecrets][] so that you can use a private registry for your image | `[]` |
| `imageTag` | The Metricbeat Docker image tag | `8.0.0-SNAPSHOT` |
| `image` | The Metricbeat Docker image | `docker.elastic.co/beats/metricbeat` |
| `kube_state_metrics.enabled` | Install [kube-state-metrics](https://github.com/helm/charts/tree/master/stable/kube-state-metrics) as a dependency | `true` |
| `kube_state_metrics.host` | Define kube-state-metrics endpoint for an existing deployment. Works only if `kube_state_metrics.enabled: false` | `""` |
| `labels` | Configurable [labels][] applied to all Metricbeat pods | `{}` |
| `livenessProbe` | Parameters to pass to liveness [probe][] checks for values such as timeouts and thresholds | see [values.yaml][] |
| `managedServiceAccount` | Whether the `serviceAccount` should be managed by this helm chart. Set this to `false` in order to manage your own service account and related roles | `true` |
Expand Down
4 changes: 2 additions & 2 deletions metricbeat/requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ dependencies:
- name: kube-state-metrics
repository: https://kubernetes-charts.storage.googleapis.com
version: 2.4.1
digest: sha256:89fdea6b5f048652fc2d562ff59338a8cbf25f9053dc28976a1271b4387692b1
generated: "2019-11-01T10:31:40.002896+01:00"
digest: sha256:948dca129bc7c16b138ed8bcbdf666c324d812e43af59d475b8bb74a53e99778
generated: "2020-04-16T16:14:03.9537312+03:00"
1 change: 1 addition & 0 deletions metricbeat/requirements.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ dependencies:
- name: 'kube-state-metrics'
version: '2.4.1'
repository: '@stable'
condition: kube_state_metrics.enabled
4 changes: 4 additions & 0 deletions metricbeat/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ spec:
fieldRef:
fieldPath: metadata.namespace
- name: KUBE_STATE_METRICS_HOSTS
{{- if .Values.kube_state_metrics.enabled }}
value: "$({{ .Release.Name | replace "-" "_" | upper }}_KUBE_STATE_METRICS_SERVICE_HOST):$({{ .Release.Name | replace "-" "_" | upper }}_KUBE_STATE_METRICS_SERVICE_PORT_HTTP)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make more sense here to just use the kube_state_metrics_host value even if we are installing the sub-chart? In that case, what is the value that gets passed to the subchart as the service name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @pbecotte . The general idea is to preserve upstream behavior as much as possible,
so when user disables kube_state_metrics installation then he/she needs to provide
existing endpoint for kube_state_metrics

{{- else }}
value: {{ .Values.kube_state_metrics.host | default "kube-state-metrics:8080"}}
{{- end }}
{{- if .Values.extraEnvs | default .Values.deployment.extraEnvs }}
{{ toYaml ( .Values.extraEnvs | default .Values.deployment.extraEnvs ) | indent 8 }}
{{- end }}
Expand Down
47 changes: 47 additions & 0 deletions metricbeat/tests/metricbeat_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

project = "metricbeat"
name = "release-name-" + project
kube_state_metric_name = "release-name-kube-state-metrics"


def test_defaults():
Expand All @@ -17,6 +18,14 @@ def test_defaults():
assert name in r["daemonset"]
assert name + "-metrics" in r["deployment"]

assert kube_state_metric_name in r["deployment"]
assert (
r["deployment"][name + "-metrics"]["spec"]["template"]["spec"]["containers"][0][
"env"
][1]["value"]
== "$(RELEASE_NAME_KUBE_STATE_METRICS_SERVICE_HOST):$(RELEASE_NAME_KUBE_STATE_METRICS_SERVICE_PORT_HTTP)"
)

c = r["daemonset"][name]["spec"]["template"]["spec"]["containers"][0]
assert c["name"] == project
assert c["image"].startswith("docker.elastic.co/beats/" + project + ":")
Expand Down Expand Up @@ -1182,3 +1191,41 @@ def test_disable_deployment():
r = helm_template(config)

assert name + "-metrics" not in r.get("deployment", {})


def test_do_not_install_kube_stat_metrics():
config = """
kube_state_metrics:
enabled: false
"""
r = helm_template(config)

assert kube_state_metric_name not in r["deployment"]
assert (
r["deployment"][name + "-metrics"]["spec"]["template"]["spec"]["containers"][0][
"env"
][1]["name"]
== "KUBE_STATE_METRICS_HOSTS"
)
assert (
r["deployment"][name + "-metrics"]["spec"]["template"]["spec"]["containers"][0][
"env"
][1]["value"]
== "kube-state-metrics:8080"
)


def test_custom_kube_stat_metrics_host():
config = """
kube_state_metrics:
enabled: false
host: "kube-state-metrics.kube-system:9999"
"""
r = helm_template(config)

assert (
r["deployment"][name + "-metrics"]["spec"]["template"]["spec"]["containers"][0][
"env"
][1]["value"]
== "kube-state-metrics.kube-system:9999"
)
5 changes: 5 additions & 0 deletions metricbeat/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ updateStrategy: RollingUpdate
nameOverride: ""
fullnameOverride: ""

kube_state_metrics:
enabled: true
# host is used only when kube_state_metrics.enabled: false
host: ""

# DEPRECATED
affinity: {}
envFrom: []
Expand Down