From 9ffc74897904ffe53c634795955e700dd5f17d65 Mon Sep 17 00:00:00 2001 From: Steve Wilkerson Date: Mon, 15 Jan 2018 08:30:28 -0600 Subject: [PATCH] helm-toolkit prometheus service annotation clean up This adds checks for the fields in the service annotations for prometheus, similar to the checks made for the pod annotations. It also moves prometheus annotations under a prometheus: key under a top-level monitoring tree to allow for other monitoring mechanisms independent of the endpoints tree Change-Id: I4be6d6ad8e74e8ca52bd224ceddad785577bf6c7 --- calico/templates/daemonset-calico-node.yaml | 6 ++++- calico/values.yaml | 11 ++++++---- .../snippets/_prometheus_pod_annotations.tpl | 14 ++++++------ .../_prometheus_service_annotations.tpl | 21 +++++++++++------- .../templates/service-controller-manager.yaml | 6 +++-- ...s.yaml => service-kube-state-metrics.yaml} | 10 +++++---- .../templates/service-scheduler.yaml | 6 +++-- prometheus-kube-state-metrics/values.yaml | 22 +++++++++++-------- .../templates/service.yaml | 6 +++-- prometheus-node-exporter/values.yaml | 10 +++++++-- .../templates/service.yaml | 6 +++-- prometheus-openstack-exporter/values.yaml | 11 +++++++++- prometheus/templates/service.yaml | 6 +++-- prometheus/values.yaml | 8 +++++-- 14 files changed, 95 insertions(+), 48 deletions(-) rename prometheus-kube-state-metrics/templates/{service-kube-metrics.yaml => service-kube-state-metrics.yaml} (70%) diff --git a/calico/templates/daemonset-calico-node.yaml b/calico/templates/daemonset-calico-node.yaml index 5bdbe876c..cd53cd111 100644 --- a/calico/templates/daemonset-calico-node.yaml +++ b/calico/templates/daemonset-calico-node.yaml @@ -39,6 +39,8 @@ limitations under the License. {{- $_ := set .Values "pod_dependency" .Values.dependencies.calico_node -}} {{- end -}} +{{- $prometheus_annotations := $envAll.Values.monitoring.prometheus.calico_node }} + {{- $serviceAccountName := "calico-cni-plugin"}} {{ tuple $envAll $envAll.Values.pod_dependency $serviceAccountName | include "helm-toolkit.snippets.kubernetes_pod_rbac_serviceaccount" }} --- @@ -93,7 +95,9 @@ spec: # reserves resources for critical add-on pods so that they can be rescheduled after # a failure. This annotation works in tandem with the toleration below. scheduler.alpha.kubernetes.io/critical-pod: '' -{{ tuple $envAll.Values.pod.annotations.calico_node | include "helm-toolkit.snippets.prometheus_pod_annotations" | indent 8 }} +{{- if .Values.monitoring.prometheus.enabled }} +{{ tuple $prometheus_annotations | include "helm-toolkit.snippets.prometheus_pod_annotations" | indent 8 }} +{{- end }} spec: hostNetwork: true tolerations: diff --git a/calico/values.yaml b/calico/values.yaml index a693c4635..c5701a8c9 100644 --- a/calico/values.yaml +++ b/calico/values.yaml @@ -44,10 +44,6 @@ images: - calico_kube_policy_controller pod: - annotations: - calico_node: - prometheus_port: 9091 - prometheus_scrape: true resources: enabled: false jobs: @@ -104,6 +100,13 @@ endpoints: peer: default: 6667 +monitoring: + prometheus: + enabled: true + calico_node: + scrape: true + port: 9091 + networking: podSubnet: 192.168.0.0/16 #NOTE(portdirect): this should be the physical MTU, the appropriate MTU diff --git a/helm-toolkit/templates/snippets/_prometheus_pod_annotations.tpl b/helm-toolkit/templates/snippets/_prometheus_pod_annotations.tpl index 5effa7702..9e09326f6 100644 --- a/helm-toolkit/templates/snippets/_prometheus_pod_annotations.tpl +++ b/helm-toolkit/templates/snippets/_prometheus_pod_annotations.tpl @@ -22,14 +22,14 @@ limitations under the License. # pod's declared ports (default is a port-free target if none are declared). {{- define "helm-toolkit.snippets.prometheus_pod_annotations" -}} -{{- $pod := index . 0 -}} -{{- if $pod.prometheus_scrape }} -prometheus.io/scrape: {{ $pod.prometheus_scrape | quote }} +{{- $config := index . 0 -}} +{{- if $config.scrape }} +prometheus.io/scrape: {{ $config.scrape | quote }} {{- end }} -{{- if $pod.prometheus_path }} -prometheus.io/path: {{ $pod.prometheus_path | quote }} +{{- if $config.path }} +prometheus.io/path: {{ $config.path | quote }} {{- end }} -{{- if $pod.prometheus_port }} -prometheus.io/port: {{ $pod.prometheus_port | quote }} +{{- if $config.port }} +prometheus.io/port: {{ $config.port | quote }} {{- end }} {{- end -}} diff --git a/helm-toolkit/templates/snippets/_prometheus_service_annotations.tpl b/helm-toolkit/templates/snippets/_prometheus_service_annotations.tpl index e2305ae16..1255dccb9 100644 --- a/helm-toolkit/templates/snippets/_prometheus_service_annotations.tpl +++ b/helm-toolkit/templates/snippets/_prometheus_service_annotations.tpl @@ -1,12 +1,9 @@ {{/* Copyright 2017 The Openstack-Helm Authors. - Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -24,9 +21,17 @@ limitations under the License. # service then set this appropriately. {{- define "helm-toolkit.snippets.prometheus_service_annotations" -}} -{{- $endpoint := index . 0 -}} -prometheus.io/scrape: {{ $endpoint.scrape | quote }} -prometheus.io/scheme: {{ $endpoint.scheme.default | quote }} -prometheus.io/path: {{ $endpoint.path.default | quote }} -prometheus.io/port: {{ $endpoint.scrape_port | quote }} +{{- $config := index . 0 -}} +{{- if $config.scrape }} +prometheus.io/scrape: {{ $config.scrape | quote }} +{{- end }} +{{- if $config.scheme }} +prometheus.io/scheme: {{ $config.scheme | quote }} +{{- end }} +{{- if $config.path }} +prometheus.io/path: {{ $config.path | quote }} +{{- end }} +{{- if $config.port }} +prometheus.io/port: {{ $config.port | quote }} +{{- end }} {{- end -}} diff --git a/prometheus-kube-state-metrics/templates/service-controller-manager.yaml b/prometheus-kube-state-metrics/templates/service-controller-manager.yaml index 6e19486d3..b9a08b9b2 100644 --- a/prometheus-kube-state-metrics/templates/service-controller-manager.yaml +++ b/prometheus-kube-state-metrics/templates/service-controller-manager.yaml @@ -16,7 +16,7 @@ limitations under the License. {{- if .Values.manifests.service_controller_manager }} {{- $envAll := . }} -{{- $endpoint := $envAll.Values.endpoints.kube_controller_manager }} +{{- $prometheus_annotations := $envAll.Values.monitoring.prometheus.kube_controller_manager }} --- apiVersion: v1 kind: Service @@ -25,7 +25,9 @@ metadata: labels: {{ tuple $envAll "controller-manager" "metrics" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 4 }} annotations: -{{ tuple $endpoint | include "helm-toolkit.snippets.prometheus_service_annotations" | indent 4 }} +{{- if .Values.monitoring.prometheus.enabled }} +{{ tuple $prometheus_annotations | include "helm-toolkit.snippets.prometheus_service_annotations" | indent 4 }} +{{- end }} spec: selector: component: kube-controller-manager diff --git a/prometheus-kube-state-metrics/templates/service-kube-metrics.yaml b/prometheus-kube-state-metrics/templates/service-kube-state-metrics.yaml similarity index 70% rename from prometheus-kube-state-metrics/templates/service-kube-metrics.yaml rename to prometheus-kube-state-metrics/templates/service-kube-state-metrics.yaml index c1991e822..bfc16a204 100644 --- a/prometheus-kube-state-metrics/templates/service-kube-metrics.yaml +++ b/prometheus-kube-state-metrics/templates/service-kube-state-metrics.yaml @@ -14,18 +14,20 @@ See the License for the specific language governing permissions and limitations under the License. */}} -{{- if .Values.manifests.service_kube_metrics }} +{{- if .Values.manifests.service_kube_state_metrics }} {{- $envAll := . }} -{{- $endpoint := $envAll.Values.endpoints.kube_metrics }} +{{- $prometheus_annotations := $envAll.Values.monitoring.prometheus.kube_state_metrics }} --- apiVersion: v1 kind: Service metadata: - name: {{ tuple "kube_metrics" "internal" . | include "helm-toolkit.endpoints.hostname_short_endpoint_lookup" }} + name: {{ tuple "kube_state_metrics" "internal" . | include "helm-toolkit.endpoints.hostname_short_endpoint_lookup" }} labels: {{ tuple $envAll "kube-state-metrics" "metrics" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 4 }} annotations: -{{ tuple $endpoint | include "helm-toolkit.snippets.prometheus_service_annotations" | indent 4 }} +{{- if .Values.monitoring.prometheus.enabled }} +{{ tuple $prometheus_annotations | include "helm-toolkit.snippets.prometheus_service_annotations" | indent 4 }} +{{- end }} spec: ports: - name: http diff --git a/prometheus-kube-state-metrics/templates/service-scheduler.yaml b/prometheus-kube-state-metrics/templates/service-scheduler.yaml index e921209c9..ef396a7e1 100644 --- a/prometheus-kube-state-metrics/templates/service-scheduler.yaml +++ b/prometheus-kube-state-metrics/templates/service-scheduler.yaml @@ -16,7 +16,7 @@ limitations under the License. {{- if .Values.manifests.service_scheduler }} {{- $envAll := . }} -{{- $endpoint := $envAll.Values.endpoints.kube_scheduler }} +{{- $prometheus_annotations := $envAll.Values.monitoring.prometheus.kube_scheduler }} --- apiVersion: v1 kind: Service @@ -25,7 +25,9 @@ metadata: labels: {{ tuple $envAll "kube-scheduler" "metrics" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 4 }} annotations: -{{ tuple $endpoint | include "helm-toolkit.snippets.prometheus_service_annotations" | indent 4 }} +{{- if .Values.monitoring.prometheus.enabled }} +{{ tuple $prometheus_annotations | include "helm-toolkit.snippets.prometheus_service_annotations" | indent 4 }} +{{- end }} spec: selector: component: kube-scheduler diff --git a/prometheus-kube-state-metrics/values.yaml b/prometheus-kube-state-metrics/values.yaml index e315f1ad0..1b7b96c02 100644 --- a/prometheus-kube-state-metrics/values.yaml +++ b/prometheus-kube-state-metrics/values.yaml @@ -102,10 +102,10 @@ endpoints: port: registry: node: 5000 - kube_metrics: + kube_state_metrics: namespace: null hosts: - default: kube-metrics + default: kube-state-metrics host_fqdn_override: default: null path: @@ -115,22 +115,26 @@ endpoints: port: http: default: 8080 - scrape: true - scrape_port: 8080 kube_scheduler: scheme: default: 'http' path: default: /metrics - scrape: true - scrape_port: 10251 kube_controller_manager: scheme: default: 'http' path: default: /metrics - scrape: true - scrape_port: 10252 + +monitoring: + prometheus: + enabled: true + kube_state_metrics: + scrape: true + kube_scheduler: + scrape: true + kube_controller_manager: + scrape: true network: kube_state_metrics: @@ -142,7 +146,7 @@ manifests: clusterrolebinding: true deployment: true job_image_repo_sync: true - service_kube_metrics: true + service_kube_state_metrics: true service_controller_manager: true service_scheduler: true serviceaccount: true diff --git a/prometheus-node-exporter/templates/service.yaml b/prometheus-node-exporter/templates/service.yaml index 1a0a9b69a..482ee48bb 100644 --- a/prometheus-node-exporter/templates/service.yaml +++ b/prometheus-node-exporter/templates/service.yaml @@ -16,7 +16,7 @@ limitations under the License. {{- if .Values.manifests.service }} {{- $envAll := . }} -{{- $endpoint := $envAll.Values.endpoints.node_metrics }} +{{- $prometheus_annotations := $envAll.Values.monitoring.prometheus.node_exporter }} --- apiVersion: v1 kind: Service @@ -25,7 +25,9 @@ metadata: labels: {{ tuple $envAll "node_exporter" "metrics" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 4 }} annotations: -{{ tuple $endpoint | include "helm-toolkit.snippets.prometheus_service_annotations" | indent 4 }} +{{- if .Values.monitoring.prometheus.enabled }} +{{ tuple $prometheus_annotations | include "helm-toolkit.snippets.prometheus_service_annotations" | indent 4 }} +{{- end }} spec: type: ClusterIP clusterIP: None diff --git a/prometheus-node-exporter/values.yaml b/prometheus-node-exporter/values.yaml index ff0d3e984..c8fada73b 100644 --- a/prometheus-node-exporter/values.yaml +++ b/prometheus-node-exporter/values.yaml @@ -92,6 +92,12 @@ conditional_dependencies: - service: local_image_registry endpoint: node +monitoring: + prometheus: + enabled: true + node_exporter: + scrape: true + network: node_exporter: port: 9100 @@ -123,8 +129,8 @@ endpoints: port: metrics: default: 9100 - scrape: true - scrape_port: 9100 + prometheus_port: + default: 9100 manifests: configmap_bin: true diff --git a/prometheus-openstack-exporter/templates/service.yaml b/prometheus-openstack-exporter/templates/service.yaml index 5657aafd5..faa14ff56 100644 --- a/prometheus-openstack-exporter/templates/service.yaml +++ b/prometheus-openstack-exporter/templates/service.yaml @@ -16,7 +16,7 @@ limitations under the License. {{- if .Values.manifests.service }} {{- $envAll := . }} -{{- $endpoint := $envAll.Values.endpoints.prometheus_openstack_exporter }} +{{- $prometheus_annotations := $envAll.Values.monitoring.prometheus.openstack_exporter }} --- apiVersion: v1 kind: Service @@ -25,7 +25,9 @@ metadata: labels: {{ tuple $envAll "prometheus-openstack-exporter" "metrics" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 4 }} annotations: -{{ tuple $endpoint | include "helm-toolkit.snippets.prometheus_service_annotations" | indent 4 }} +{{- if .Values.monitoring.prometheus.enabled }} +{{ tuple $prometheus_annotations | include "helm-toolkit.snippets.prometheus_service_annotations" | indent 4 }} +{{- end }} spec: ports: - name: http diff --git a/prometheus-openstack-exporter/values.yaml b/prometheus-openstack-exporter/values.yaml index 8aad85587..018838673 100644 --- a/prometheus-openstack-exporter/values.yaml +++ b/prometheus-openstack-exporter/values.yaml @@ -144,7 +144,6 @@ endpoints: port: exporter: default: 9103 - scrape: true identity: name: keystone auth: @@ -178,6 +177,16 @@ endpoints: api: default: 80 +monitoring: + prometheus: + enabled: true + openstack_exporter: + scrape: true + +network: + openstack_metrics_exporter: + port: 9103 + manifests: configmap_bin: true deployment: true diff --git a/prometheus/templates/service.yaml b/prometheus/templates/service.yaml index dd8e4985d..34e2e6772 100644 --- a/prometheus/templates/service.yaml +++ b/prometheus/templates/service.yaml @@ -16,7 +16,7 @@ limitations under the License. {{- if .Values.manifests.service }} {{- $envAll := . }} -{{- $endpoint := $envAll.Values.endpoints.monitoring }} +{{- $prometheus_annotations := $envAll.Values.monitoring.prometheus.prometheus }} --- apiVersion: v1 kind: Service @@ -25,7 +25,9 @@ metadata: labels: {{ tuple $envAll "prometheus" "metrics" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 4 }} annotations: -{{ tuple $endpoint | include "helm-toolkit.snippets.prometheus_service_annotations" | indent 4 }} +{{- if .Values.monitoring.prometheus.enabled }} +{{ tuple $prometheus_annotations | include "helm-toolkit.snippets.prometheus_service_annotations" | indent 4 }} +{{- end }} spec: ports: - name: prom-metrics diff --git a/prometheus/values.yaml b/prometheus/values.yaml index 233c1ab31..ea915249b 100644 --- a/prometheus/values.yaml +++ b/prometheus/values.yaml @@ -112,8 +112,6 @@ endpoints: api: default: 9090 public: 80 - scrape: true - scrape_port: 9090 alerts: name: alertmanager namespace: null @@ -147,6 +145,12 @@ conditional_dependencies: - service: local_image_registry endpoint: node +monitoring: + prometheus: + enabled: true + prometheus: + scrape: true + network: prometheus: ingress: