From 696e37e3f760b2119024fe3b95c0a322e6b5f677 Mon Sep 17 00:00:00 2001 From: Mohammed Naser Date: Wed, 26 Jan 2022 16:07:08 -0500 Subject: [PATCH] memcached: switch to sidecar Instead of running the exporter as a seperate deployemnt that talks to the service, which will NOT be reporting reliable information if you have more than 1 replica of memcached, this patch insteads moves things into a sidecar model that runs in the same pod and exposes the service. Change-Id: Ia4801b47f44df91db10886f7cb4e8e174557aded --- memcached/Chart.yaml | 2 +- .../bin/_memcached-exporter.sh.tpl | 2 +- memcached/templates/configmap-bin.yaml | 2 + memcached/templates/deployment.yaml | 23 ++++++ .../prometheus/exporter-configmap-bin.yaml | 26 ------ .../prometheus/exporter-deployment.yaml | 81 ------------------- .../prometheus/exporter-service.yaml | 35 -------- memcached/templates/service.yaml | 7 +- memcached/values.yaml | 36 +-------- releasenotes/notes/memcached.yaml | 1 + 10 files changed, 37 insertions(+), 178 deletions(-) rename memcached/templates/{monitoring/prometheus => }/bin/_memcached-exporter.sh.tpl (90%) delete mode 100644 memcached/templates/monitoring/prometheus/exporter-configmap-bin.yaml delete mode 100644 memcached/templates/monitoring/prometheus/exporter-deployment.yaml delete mode 100644 memcached/templates/monitoring/prometheus/exporter-service.yaml diff --git a/memcached/Chart.yaml b/memcached/Chart.yaml index 85877992b..c0c1ffb30 100644 --- a/memcached/Chart.yaml +++ b/memcached/Chart.yaml @@ -15,6 +15,6 @@ apiVersion: v1 appVersion: v1.5.5 description: OpenStack-Helm Memcached name: memcached -version: 0.1.5 +version: 0.1.6 home: https://github.com/memcached/memcached ... diff --git a/memcached/templates/monitoring/prometheus/bin/_memcached-exporter.sh.tpl b/memcached/templates/bin/_memcached-exporter.sh.tpl similarity index 90% rename from memcached/templates/monitoring/prometheus/bin/_memcached-exporter.sh.tpl rename to memcached/templates/bin/_memcached-exporter.sh.tpl index c42358bf1..d10e6b723 100644 --- a/memcached/templates/monitoring/prometheus/bin/_memcached-exporter.sh.tpl +++ b/memcached/templates/bin/_memcached-exporter.sh.tpl @@ -18,7 +18,7 @@ set -ex COMMAND="${@:-start}" function start () { - exec /bin/memcached_exporter --memcached.address "$MEMCACHED_HOST" + exec /bin/memcached_exporter } function stop () { diff --git a/memcached/templates/configmap-bin.yaml b/memcached/templates/configmap-bin.yaml index 42d20e8d4..2fc4e2b2b 100644 --- a/memcached/templates/configmap-bin.yaml +++ b/memcached/templates/configmap-bin.yaml @@ -27,4 +27,6 @@ data: {{- end }} memcached.sh: | {{ tuple "bin/_memcached.sh.tpl" . | include "helm-toolkit.utils.template" | indent 4 }} + memcached-exporter.sh: | +{{ tuple "bin/_memcached-exporter.sh.tpl" . | include "helm-toolkit.utils.template" | indent 4 }} {{- end }} diff --git a/memcached/templates/deployment.yaml b/memcached/templates/deployment.yaml index 1b4e20277..fc827495b 100644 --- a/memcached/templates/deployment.yaml +++ b/memcached/templates/deployment.yaml @@ -80,6 +80,29 @@ spec: mountPath: /tmp/memcached.sh subPath: memcached.sh readOnly: true +{{- if .Values.monitoring.prometheus.enabled }} + - name: memcached-exporter + image: {{ .Values.images.tags.prometheus_memcached_exporter }} + imagePullPolicy: {{ .Values.images.pull_policy }} +{{ tuple $envAll $envAll.Values.pod.resources.prometheus_memcached_exporter | include "helm-toolkit.snippets.kubernetes_resources" | indent 10 }} +{{ dict "envAll" $envAll "application" "server" "container" "memcached_exporter" | include "helm-toolkit.snippets.kubernetes_container_security_context" | indent 10 }} + command: + - /tmp/memcached-exporter.sh + - start + ports: + - name: metrics + containerPort: {{ tuple "oslo_cache" "internal" "metrics" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }} + readinessProbe: + tcpSocket: + port: {{ tuple "oslo_cache" "internal" "metrics" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }} + volumeMounts: + - name: pod-tmp + mountPath: /tmp + - name: memcached-bin + mountPath: /tmp/memcached-exporter.sh + subPath: memcached-exporter.sh + readOnly: true +{{- end }} volumes: - name: pod-tmp emptyDir: {} diff --git a/memcached/templates/monitoring/prometheus/exporter-configmap-bin.yaml b/memcached/templates/monitoring/prometheus/exporter-configmap-bin.yaml deleted file mode 100644 index 89cec710a..000000000 --- a/memcached/templates/monitoring/prometheus/exporter-configmap-bin.yaml +++ /dev/null @@ -1,26 +0,0 @@ -{{/* -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. -See the License for the specific language governing permissions and -limitations under the License. -*/}} - -{{- if and .Values.manifests.monitoring.prometheus.configmap_bin .Values.monitoring.prometheus.enabled }} -{{- $envAll := . }} - ---- -apiVersion: v1 -kind: ConfigMap -metadata: - name: {{ printf "%s-%s" $envAll.Release.Name "memcached-exporter-bin" | quote }} -data: - memcached-exporter.sh: | -{{ tuple "bin/_memcached-exporter.sh.tpl" . | include "helm-toolkit.utils.template" | indent 4 }} -{{- end }} diff --git a/memcached/templates/monitoring/prometheus/exporter-deployment.yaml b/memcached/templates/monitoring/prometheus/exporter-deployment.yaml deleted file mode 100644 index 21736e925..000000000 --- a/memcached/templates/monitoring/prometheus/exporter-deployment.yaml +++ /dev/null @@ -1,81 +0,0 @@ -{{/* -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. -See the License for the specific language governing permissions and -limitations under the License. -*/}} - -{{- if and .Values.manifests.monitoring.prometheus.deployment_exporter .Values.monitoring.prometheus.enabled }} -{{- $envAll := . }} - -{{- $rcControllerName := printf "%s-%s" $envAll.Release.Name "memcached-exporter" }} -{{- $configMapBinName := printf "%s-%s" $envAll.Release.Name "memcached-exporter-bin" }} - -{{ tuple $envAll "prometheus_memcached_exporter" $rcControllerName | include "helm-toolkit.snippets.kubernetes_pod_rbac_serviceaccount" }} ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ $rcControllerName | quote }} - labels: -{{ tuple $envAll "prometheus_memcached_exporter" "exporter" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 4 }} -spec: - replicas: {{ .Values.pod.replicas.prometheus_memcached_exporter }} - selector: - matchLabels: -{{ tuple $envAll "prometheus_memcached_exporter" "exporter" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 6 }} -{{ tuple $envAll | include "helm-toolkit.snippets.kubernetes_upgrades_deployment" | indent 2 }} - template: - metadata: - labels: -{{ tuple $envAll "prometheus_memcached_exporter" "exporter" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 8 }} - namespace: {{ .Values.endpoints.prometheus_memcached_exporter.namespace }} - annotations: -{{ tuple $envAll | include "helm-toolkit.snippets.release_uuid" | indent 8 }} -{{ dict "envAll" $envAll "podName" "prometheus_memcached_exporter" "containerNames" (list "init" "memcached-exporter") | include "helm-toolkit.snippets.kubernetes_mandatory_access_control_annotation" | indent 8 }} - spec: -{{ dict "envAll" $envAll "application" "memcached_exporter" | include "helm-toolkit.snippets.kubernetes_pod_security_context" | indent 6 }} - shareProcessNamespace: true - serviceAccountName: {{ $rcControllerName | quote }} - nodeSelector: - {{ .Values.labels.prometheus_memcached_exporter.node_selector_key }}: {{ .Values.labels.prometheus_memcached_exporter.node_selector_value | quote }} - terminationGracePeriodSeconds: {{ .Values.pod.lifecycle.termination_grace_period.prometheus_memcached_exporter.timeout | default "30" }} - initContainers: -{{ tuple $envAll "prometheus_memcached_exporter" list | include "helm-toolkit.snippets.kubernetes_entrypoint_init_container" | indent 8 }} - containers: - - name: memcached-exporter - image: {{ .Values.images.tags.prometheus_memcached_exporter }} - imagePullPolicy: {{ .Values.images.pull_policy }} -{{ tuple $envAll $envAll.Values.pod.resources.prometheus_memcached_exporter | include "helm-toolkit.snippets.kubernetes_resources" | indent 10 }} -{{ dict "envAll" $envAll "application" "memcached_exporter" "container" "memcached_exporter" | include "helm-toolkit.snippets.kubernetes_container_security_context" | indent 10 }} - command: - - /tmp/memcached-exporter.sh - - start - ports: - - name: metrics - containerPort: {{ tuple "prometheus_memcached_exporter" "internal" "metrics" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }} - env: - - name: MEMCACHED_HOST - value: {{ tuple "oslo_cache" "internal" "memcache" . | include "helm-toolkit.endpoints.host_and_port_endpoint_uri_lookup" }} - volumeMounts: - - name: pod-tmp - mountPath: /tmp - - name: memcached-exporter-bin - mountPath: /tmp/memcached-exporter.sh - subPath: memcached-exporter.sh - readOnly: true - volumes: - - name: pod-tmp - emptyDir: {} - - name: memcached-exporter-bin - configMap: - name: {{ $configMapBinName | quote }} - defaultMode: 0555 -{{- end }} diff --git a/memcached/templates/monitoring/prometheus/exporter-service.yaml b/memcached/templates/monitoring/prometheus/exporter-service.yaml deleted file mode 100644 index 65be42d6e..000000000 --- a/memcached/templates/monitoring/prometheus/exporter-service.yaml +++ /dev/null @@ -1,35 +0,0 @@ -{{/* -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. -See the License for the specific language governing permissions and -limitations under the License. -*/}} - -{{- if and .Values.manifests.monitoring.prometheus.service_exporter .Values.monitoring.prometheus.enabled }} -{{- $envAll := . }} -{{- $prometheus_annotations := $envAll.Values.monitoring.prometheus.memcached_exporter }} ---- -apiVersion: v1 -kind: Service -metadata: - name: {{ tuple "prometheus_memcached_exporter" "internal" . | include "helm-toolkit.endpoints.hostname_short_endpoint_lookup" }} - labels: -{{ tuple $envAll "prometheus_memcached_exporter" "metrics" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 4 }} - annotations: -{{- if .Values.monitoring.prometheus.enabled }} -{{ tuple $prometheus_annotations | include "helm-toolkit.snippets.prometheus_service_annotations" | indent 4 }} -{{- end }} -spec: - ports: - - name: metrics - port: {{ tuple "prometheus_memcached_exporter" "internal" "metrics" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }} - selector: -{{ tuple $envAll "prometheus_memcached_exporter" "exporter" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 4 }} -{{- end }} diff --git a/memcached/templates/service.yaml b/memcached/templates/service.yaml index 9125572f5..0280d6388 100644 --- a/memcached/templates/service.yaml +++ b/memcached/templates/service.yaml @@ -22,7 +22,12 @@ metadata: spec: sessionAffinity: ClientIP ports: - - port: {{ tuple "oslo_cache" "internal" "memcache" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }} + - name: memcache + port: {{ tuple "oslo_cache" "internal" "memcache" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }} +{{- if .Values.monitoring.prometheus.enabled }} + - name: metrics + port: {{ tuple "oslo_cache" "internal" "metrics" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }} +{{- end }} selector: {{ tuple $envAll "memcached" "server" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 4 }} {{- end }} diff --git a/memcached/values.yaml b/memcached/values.yaml index 7ad6d29ed..889f8cb32 100644 --- a/memcached/values.yaml +++ b/memcached/values.yaml @@ -41,10 +41,6 @@ dependencies: services: - endpoint: internal service: local_image_registry - prometheus_memcached_exporter: - services: - - endpoint: internal - service: oslo_cache endpoints: cluster_domain_suffix: cluster.local @@ -69,17 +65,6 @@ endpoints: port: memcache: default: 11211 - prometheus_memcached_exporter: - namespace: null - hosts: - default: memcached-exporter - host_fqdn_override: - default: null - path: - default: /metrics - scheme: - default: 'http' - port: metrics: default: 9150 kube_dns: @@ -129,9 +114,6 @@ labels: server: node_selector_key: openstack-control-plane node_selector_value: enabled - prometheus_memcached_exporter: - node_selector_key: openstack-control-plane - node_selector_value: enabled manifests: configmap_bin: true @@ -139,21 +121,9 @@ manifests: job_image_repo_sync: true network_policy: false service: true - monitoring: - prometheus: - configmap_bin: true - deployment_exporter: true - service_exporter: true pod: security_context: - memcached_exporter: - pod: - runAsUser: 65534 - container: - memcached_exporter: - readOnlyRootFilesystem: true - allowPrivilegeEscalation: false server: pod: runAsUser: 65534 @@ -161,6 +131,9 @@ pod: memcached: allowPrivilegeEscalation: false readOnlyRootFilesystem: true + memcached_exporter: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: true affinity: anti: topologyKey: @@ -180,11 +153,8 @@ pod: termination_grace_period: memcached: timeout: 30 - prometheus_memcached_exporter: - timeout: 30 replicas: server: 1 - prometheus_memcached_exporter: 1 resources: enabled: false memcached: diff --git a/releasenotes/notes/memcached.yaml b/releasenotes/notes/memcached.yaml index 31d2efc01..a90c940e3 100644 --- a/releasenotes/notes/memcached.yaml +++ b/releasenotes/notes/memcached.yaml @@ -6,4 +6,5 @@ memcached: - 0.1.3 Remove panko residue - 0.1.4 Use full image ref for docker official images - 0.1.5 Update htk requirements + - 0.1.6 Switch to using sidecar for exporter ...