From f4623715f3e81177a057d2799e29f82dd065c518 Mon Sep 17 00:00:00 2001 From: Vladimir Kozhukalov Date: Mon, 23 Feb 2026 16:14:26 -0600 Subject: [PATCH] Deploy memcached exporter from extraContainers This is aligned with the Helm best practices when users can inject optional snippets into templates and exporter sidecars is exactly one of such optional things. Change-Id: I273e03dfc0cd70f918bc6c407aa5f857504611e2 Signed-off-by: Vladimir Kozhukalov --- .../templates/bin/_memcached-exporter.sh.tpl | 28 ----------- memcached/templates/configmap-bin.yaml | 2 - memcached/templates/service.yaml | 11 ++--- memcached/templates/statefulset.yaml | 35 ++------------ memcached/values.yaml | 41 +++-------------- .../notes/memcached-1ae10613b2e36813.yaml | 7 +++ values_overrides/memcached/exporter.yaml | 46 +++++++++++++++++++ zuul.d/base.yaml | 6 ++- 8 files changed, 69 insertions(+), 107 deletions(-) delete mode 100644 memcached/templates/bin/_memcached-exporter.sh.tpl create mode 100644 releasenotes/notes/memcached-1ae10613b2e36813.yaml create mode 100644 values_overrides/memcached/exporter.yaml diff --git a/memcached/templates/bin/_memcached-exporter.sh.tpl b/memcached/templates/bin/_memcached-exporter.sh.tpl deleted file mode 100644 index 08b4d919e9..0000000000 --- a/memcached/templates/bin/_memcached-exporter.sh.tpl +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh - -{{/* -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. -*/}} - -set -ex -COMMAND="${@:-start}" - -function start () { - exec /bin/memcached_exporter --memcached.address "$MEMCACHED_HOST:$MEMCACHED_PORT" -} - -function stop () { - kill -TERM 1 -} - -$COMMAND diff --git a/memcached/templates/configmap-bin.yaml b/memcached/templates/configmap-bin.yaml index f14bd242e0..1e65401f09 100644 --- a/memcached/templates/configmap-bin.yaml +++ b/memcached/templates/configmap-bin.yaml @@ -33,6 +33,4 @@ 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/service.yaml b/memcached/templates/service.yaml index 982647b1b4..06a929717e 100644 --- a/memcached/templates/service.yaml +++ b/memcached/templates/service.yaml @@ -24,14 +24,9 @@ spec: ports: - name: memcache port: {{ tuple "oslo_cache" "internal" "memcache" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }} -{{/* -Keep exporter port here to be able to scrape over endpoints. -https://prometheus.io/docs/prometheus/latest/configuration/configuration/#endpoints -*/}} -{{- if .Values.monitoring.prometheus.enabled }} - - name: metrics - port: {{ tuple "oslo_cache" "internal" "metrics" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }} -{{- end }} + {{- with .Values.memcached.extraServicePorts }} + {{- tpl (toYaml .) $ | nindent 4 }} + {{- end }} selector: {{ tuple $envAll "memcached" "server" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 4 }} {{ .Values.network.memcached | include "helm-toolkit.snippets.service_params" | indent 2 }} diff --git a/memcached/templates/statefulset.yaml b/memcached/templates/statefulset.yaml index 77692d1bb4..bfa2527d04 100644 --- a/memcached/templates/statefulset.yaml +++ b/memcached/templates/statefulset.yaml @@ -23,12 +23,6 @@ tcpSocket: port: {{ tuple "oslo_cache" "internal" "memcache" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }} {{- end }} -{{- define "exporterProbeTemplate" }} -httpGet: - path: /metrics - port: {{ tuple "oslo_cache" "internal" "metrics" . | include "helm-toolkit.endpoints.endpoint_port_lookup" }} -{{- end }} - {{- if .Values.manifests.statefulset }} {{- $envAll := . }} @@ -100,32 +94,9 @@ spec: mountPath: /tmp/memcached.sh subPath: memcached.sh readOnly: true -{{- if .Values.monitoring.prometheus.enabled }} - - name: memcached-exporter - env: - - name: MEMCACHED_HOST - value: 127.0.0.1 - - name: MEMCACHED_PORT - value: {{ tuple "oslo_cache" "internal" "memcache" . | include "helm-toolkit.endpoints.endpoint_port_lookup" | quote }} -{{ tuple $envAll "prometheus_memcached_exporter" | include "helm-toolkit.snippets.image" | indent 10 }} -{{ 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" }} -{{ dict "envAll" $envAll "component" "memcached" "container" "memcached_exporter" "type" "readiness" "probeTemplate" (include "exporterProbeTemplate" $envAll | fromYaml) | include "helm-toolkit.snippets.kubernetes_probe" | indent 10 }} -{{ dict "envAll" $envAll "component" "memcached" "container" "memcached_exporter" "type" "liveness" "probeTemplate" (include "exporterProbeTemplate" $envAll | fromYaml) | include "helm-toolkit.snippets.kubernetes_probe" | indent 10 }} - volumeMounts: - - name: pod-tmp - mountPath: /tmp - - name: memcached-bin - mountPath: /tmp/memcached-exporter.sh - subPath: memcached-exporter.sh - readOnly: true -{{- end }} + {{- with .Values.memcached.extraContainers }} + {{- tpl (toYaml .) $ | nindent 8 }} + {{- end }} volumes: - name: pod-tmp emptyDir: {} diff --git a/memcached/values.yaml b/memcached/values.yaml index b6ac8d719a..5ea6de4ada 100644 --- a/memcached/values.yaml +++ b/memcached/values.yaml @@ -84,8 +84,6 @@ endpoints: port: memcache: default: 11211 - metrics: - default: 9150 kube_dns: namespace: kube-system name: kubernetes-dns @@ -113,18 +111,11 @@ network_policy: egress: - {} -monitoring: - prometheus: - enabled: false - memcached_exporter: - scrape: true - images: pull_policy: IfNotPresent tags: dep_check: 'quay.io/airshipit/kubernetes-entrypoint:latest-ubuntu_jammy' memcached: 'quay.io/airshipit/memcached:1.6.32' - prometheus_memcached_exporter: docker.io/prom/memcached-exporter:v0.4.1 image_repo_sync: quay.io/airshipit/docker:27.5.0 local_registry: active: false @@ -145,6 +136,10 @@ manifests: service: true secret_registry: true +memcached: + extraContainers: [] + extraServicePorts: [] + pod: security_context: server: @@ -159,12 +154,7 @@ pod: capabilities: drop: - ALL - memcached_exporter: - allowPrivilegeEscalation: false - readOnlyRootFilesystem: true - capabilities: - drop: - - ALL + probes: memcached: memcached: @@ -180,19 +170,7 @@ pod: initialDelaySeconds: 10 periodSeconds: 15 timeoutSeconds: 10 - memcached_exporter: - liveness: - enabled: True - params: - initialDelaySeconds: 15 - periodSeconds: 60 - timeoutSeconds: 10 - readiness: - enabled: True - params: - initialDelaySeconds: 5 - periodSeconds: 60 - timeoutSeconds: 10 + affinity: anti: topologyKey: @@ -232,13 +210,6 @@ pod: requests: cpu: "500m" memory: "128Mi" - prometheus_memcached_exporter: - limits: - memory: "1024Mi" - cpu: "2000m" - requests: - cpu: 500m - memory: 128Mi jobs: image_repo_sync: requests: diff --git a/releasenotes/notes/memcached-1ae10613b2e36813.yaml b/releasenotes/notes/memcached-1ae10613b2e36813.yaml new file mode 100644 index 0000000000..01826e691a --- /dev/null +++ b/releasenotes/notes/memcached-1ae10613b2e36813.yaml @@ -0,0 +1,7 @@ +--- +memcached: + - | + Add .Values.memcached.extraContainers hook to make it possible to + add extra containers to memcached statefulset, e.g. for monitoring + purposes. Also move the exporter sidecar to values_overrides. +... diff --git a/values_overrides/memcached/exporter.yaml b/values_overrides/memcached/exporter.yaml new file mode 100644 index 0000000000..ce5c13ccaf --- /dev/null +++ b/values_overrides/memcached/exporter.yaml @@ -0,0 +1,46 @@ +--- +memcached: + extraServicePorts: + - name: metrics + port: 9150 + targetPort: 9150 + protocol: TCP + extraContainers: + - name: memcached-exporter + image: docker.io/prom/memcached-exporter:v0.15.5 + imagePullPolicy: IfNotPresent + command: + - /bin/memcached_exporter + args: + - --memcached.address=127.0.0.1:11211 + ports: + - name: metrics + containerPort: 9150 + livenessProbe: + httpGet: + path: /metrics + port: 9150 + initialDelaySeconds: 15 + periodSeconds: 60 + timeoutSeconds: 10 + readinessProbe: + httpGet: + path: /metrics + port: 9150 + initialDelaySeconds: 5 + periodSeconds: 60 + timeoutSeconds: 10 + securityContext: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: true + capabilities: + drop: + - ALL + resources: + requests: + memory: "128Mi" + cpu: "500m" + limits: + memory: "1024Mi" + cpu: "2000m" +... diff --git a/zuul.d/base.yaml b/zuul.d/base.yaml index 9f82bdb188..ced498f412 100644 --- a/zuul.d/base.yaml +++ b/zuul.d/base.yaml @@ -143,7 +143,9 @@ - ./tools/deployment/common/setup-client.sh - export VOLUME_HELM_ARGS="--set volume.enabled=false"; ./tools/deployment/component/common/rabbitmq.sh - ./tools/deployment/db/mariadb.sh - - ./tools/deployment/component/common/memcached.sh + - >- + export OSH_EXTRA_HELM_ARGS="--values ../openstack-helm/values_overrides/memcached/exporter.yaml"; + ./tools/deployment/component/common/memcached.sh - ./tools/deployment/component/keystone/keystone.sh - ./tools/deployment/component/heat/heat.sh - export GLANCE_BACKEND=local; ./tools/deployment/component/glance/glance.sh @@ -152,7 +154,7 @@ export OSH_EXTRA_HELM_ARGS="--values ../openstack-helm/values_overrides/libvirt/inovex_exporter.yaml"; ./tools/deployment/component/compute-kit/libvirt.sh - ./tools/deployment/component/compute-kit/compute-kit.sh - - export OSH_TEST_TIMEOUT=1200;./tools/deployment/common/run-helm-tests.sh neutron + - export OSH_TEST_TIMEOUT=1200; ./tools/deployment/common/run-helm-tests.sh neutron - ./tools/deployment/common/run-helm-tests.sh nova - ./tools/deployment/common/run-helm-tests.sh glance - ./tools/deployment/common/run-helm-tests.sh keystone