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

Commit

Permalink
Make kube-state-metrics optional for installation (#387)
Browse files Browse the repository at this point in the history
In the most cases kube-state-metrics is already installed on the
cluster, so let's just re-use it, instead of installing another
one copy. By default, kube-state-metrics are installed as dependency,
so this PR doesn't change the default behaviour

Signed-off-by: Sergiy Kulanov <sergey@kulanov.org.ua>
  • Loading branch information
SergK authored and jmlrt committed Jul 13, 2020
1 parent e3c8fc6 commit 414e7d6
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 2 deletions.
2 changes: 2 additions & 0 deletions metricbeat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,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 | `7.8.1-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)"
{{- 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

0 comments on commit 414e7d6

Please sign in to comment.