From fd5963777dc1dfe72a720b9d14588ee343523fc2 Mon Sep 17 00:00:00 2001 From: Abhishek Sharma <235850498+lvg-dexters@users.noreply.github.com> Date: Fri, 24 Apr 2026 15:00:48 +0200 Subject: [PATCH] helm: allow Service creation and custom annotations for Prometheus scraping Adds two opt-in values to the chart: - service.create: when true in IMDS/DaemonSet mode, creates a headless Service (clusterIP: None) selecting DaemonSet pods. Default false preserves existing behavior. SQS mode continues to auto-create a Service as before. - service.annotations: applied to the Service metadata. Enables attaching prometheus.io/* annotations for scrape discovery via endpointslice-based mechanisms (vanilla Prometheus, Grafana Alloy, grafana/k8s-monitoring). Strictly additive and backward-compatible. Existing SQS users see no change. Existing IMDS users who do not set service.create see no change. Only IMDS users who explicitly opt in get the new Service. Verified via helm template across behavior matrix: - enablePrometheusServer=false: no Service (all modes) - SQS=false, PromServer=true, service.create=false: no Service (legacy IMDS) - SQS=false, PromServer=true, service.create=true: headless Service with DaemonSet selector - SQS=true, PromServer=true: ClusterIP Service with Deployment selector (legacy SQS, unchanged) Refs #1266 --- .../templates/service.yaml | 17 ++++++++++++++++- .../aws-node-termination-handler/values.yaml | 14 ++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/config/helm/aws-node-termination-handler/templates/service.yaml b/config/helm/aws-node-termination-handler/templates/service.yaml index 19f7b067..917da36e 100644 --- a/config/helm/aws-node-termination-handler/templates/service.yaml +++ b/config/helm/aws-node-termination-handler/templates/service.yaml @@ -1,15 +1,30 @@ -{{- if and .Values.enableSqsTerminationDraining .Values.enablePrometheusServer -}} +{{- if and .Values.enablePrometheusServer (or .Values.enableSqsTerminationDraining .Values.service.create) -}} apiVersion: v1 kind: Service metadata: name: {{ include "aws-node-termination-handler.fullname" . }} namespace: {{ .Release.Namespace }} labels: + {{- if .Values.enableSqsTerminationDraining }} {{- include "aws-node-termination-handler.labelsDeployment" . | nindent 4 }} + {{- else }} + {{- include "aws-node-termination-handler.labelsDaemonset" . | nindent 4 }} + {{- end }} + {{- with .Values.service.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} spec: type: ClusterIP + {{- if not .Values.enableSqsTerminationDraining }} + clusterIP: None + {{- end }} selector: + {{- if .Values.enableSqsTerminationDraining }} {{- include "aws-node-termination-handler.selectorLabelsDeployment" . | nindent 4 }} + {{- else }} + {{- include "aws-node-termination-handler.selectorLabelsDaemonset" . | nindent 4 }} + {{- end }} ports: - name: http-metrics port: {{ .Values.prometheusServerPort }} diff --git a/config/helm/aws-node-termination-handler/values.yaml b/config/helm/aws-node-termination-handler/values.yaml index ada2864e..e1f6afe6 100644 --- a/config/helm/aws-node-termination-handler/values.yaml +++ b/config/helm/aws-node-termination-handler/values.yaml @@ -155,6 +155,20 @@ strategy: {} podDisruptionBudget: {} # maxUnavailable: 1 +service: + # Controls Service creation for the metrics server. + # - In SQS mode (enableSqsTerminationDraining=true): a Service is auto-created + # when enablePrometheusServer=true (legacy behavior, unchanged by this value). + # - In IMDS mode (enableSqsTerminationDraining=false): opt in by setting + # service.create=true. Creates a headless Service (clusterIP: None) pointing + # at DaemonSet pods, for Prometheus scrape discovery via Kubernetes endpoint + # slices. + # When enablePrometheusServer=false, no Service is created regardless. + create: false + # Annotations to add to the Service metadata. Useful for attaching + # prometheus.io/* annotations for endpoint-based scrape discovery. + annotations: {} + serviceMonitor: # Specifies whether ServiceMonitor should be created # this needs enableSqsTerminationDraining: true