From 73e6542eea0b5cf80dab3c74bc8859837dcd3a46 Mon Sep 17 00:00:00 2001 From: Strangerxxx Date: Wed, 15 Apr 2026 13:16:10 +0300 Subject: [PATCH] feat(helm): add generic service and ingress annotation support (#2541) Co-authored-by: cxymds Co-authored-by: houseme --- helm/rustfs/templates/_helpers.tpl | 60 ++++++++++++++++++++++++++++++ helm/rustfs/templates/ingress.yaml | 13 +------ helm/rustfs/templates/service.yaml | 12 +++--- helm/rustfs/values.yaml | 18 +++++---- 4 files changed, 79 insertions(+), 24 deletions(-) diff --git a/helm/rustfs/templates/_helpers.tpl b/helm/rustfs/templates/_helpers.tpl index 3120f1f33..c07dace5e 100644 --- a/helm/rustfs/templates/_helpers.tpl +++ b/helm/rustfs/templates/_helpers.tpl @@ -99,6 +99,66 @@ Render imagePullSecrets for workloads - appends registry secret {{- toYaml $secrets }} {{- end }} +{{/* +Render annotations for the main Service resource. +Merges (in order of increasing precedence): + - service.traefikAnnotations (when ingress.className=traefik) + - ingress.traefikAnnotations (when ingress.className=traefik, backwards-compat alias) + - service.annotations +*/}} +{{- define "rustfs.serviceAnnotations" -}} +{{- $annotations := dict }} +{{- if and .Values.mode.distributed.enabled (eq .Values.ingress.className "traefik") }} +{{- $annotations = merge $annotations (default (dict) .Values.service.traefikAnnotations) }} +{{- $annotations = merge $annotations (default (dict) .Values.ingress.traefikAnnotations) }} +{{- end }} +{{- $annotations = merge $annotations (default (dict) .Values.service.annotations) }} +{{- if and .Values.mode.distributed.enabled .Values.mtls.enabled (eq .Values.ingress.className "traefik") }} +{{- $mtls := dict + "traefik.ingress.kubernetes.io/service.serversscheme" "https" + "traefik.ingress.kubernetes.io/service.serverstransport" (printf "%s-%s-transport@kubernetescrd" .Release.Namespace (include "rustfs.fullname" .)) +}} +{{- $annotations = merge $annotations $mtls }} +{{- end }} +{{- if $annotations }} +{{- toYaml $annotations }} +{{- end }} +{{- end }} + +{{/* +Render annotations for the headless Service resource. +Merges: + - service.headlessAnnotations +*/}} +{{- define "rustfs.headlessServiceAnnotations" -}} +{{- $annotations := default (dict) .Values.service.headlessAnnotations }} +{{- if $annotations }} +{{- toYaml $annotations }} +{{- end }} +{{- end }} + +{{/* +Render annotations for the Ingress resource. +Merges (in order of increasing precedence): + - ingress.nginxAnnotations (when ingress.className=nginx) + - ingress.traefikAnnotations (when ingress.className=traefik) + - ingress.customAnnotations (backwards-compat) + - ingress.annotations +*/}} +{{- define "rustfs.ingressAnnotations" -}} +{{- $annotations := dict }} +{{- if eq .Values.ingress.className "nginx" }} +{{- $annotations = merge $annotations (default (dict) .Values.ingress.nginxAnnotations) }} +{{- else if eq .Values.ingress.className "traefik" }} +{{- $annotations = merge $annotations (default (dict) .Values.ingress.traefikAnnotations) }} +{{- end }} +{{- $annotations = merge $annotations (default (dict) .Values.ingress.customAnnotations) }} +{{- $annotations = merge $annotations (default (dict) .Values.ingress.annotations) }} +{{- if $annotations }} +{{- toYaml $annotations }} +{{- end }} +{{- end }} + {{/* Render RUSTFS_VOLUMES */}} diff --git a/helm/rustfs/templates/ingress.yaml b/helm/rustfs/templates/ingress.yaml index c2b841d7e..aa5770abf 100644 --- a/helm/rustfs/templates/ingress.yaml +++ b/helm/rustfs/templates/ingress.yaml @@ -1,13 +1,4 @@ {{- if .Values.ingress.enabled -}} -{{- $ingressAnnotations := dict }} -{{- if eq .Values.ingress.className "nginx" }} -{{- $ingressAnnotations = deepCopy (default (dict) .Values.ingress.nginxAnnotations) }} -{{- else if eq .Values.ingress.className "traefik" }} -{{- $ingressAnnotations = deepCopy (default (dict) .Values.ingress.traefikAnnotations) }} -{{- end }} -{{- with .Values.ingress.customAnnotations }} -{{- $ingressAnnotations = merge $ingressAnnotations . }} -{{- end }} apiVersion: networking.k8s.io/v1 kind: Ingress metadata: @@ -18,9 +9,9 @@ metadata: {{- with .Values.commonLabels }} {{- toYaml . | nindent 4 }} {{- end }} - {{- with $ingressAnnotations }} + {{- with (include "rustfs.ingressAnnotations" .) }} annotations: - {{- toYaml . | nindent 4 }} + {{- . | nindent 4 }} {{- end }} spec: {{- with .Values.ingress.className }} diff --git a/helm/rustfs/templates/service.yaml b/helm/rustfs/templates/service.yaml index 7b6eca2f7..56d6b146b 100644 --- a/helm/rustfs/templates/service.yaml +++ b/helm/rustfs/templates/service.yaml @@ -4,6 +4,10 @@ kind: Service metadata: name: {{ include "rustfs.fullname" . }}-headless namespace: {{ .Release.Namespace }} + {{- with (include "rustfs.headlessServiceAnnotations" .) }} + annotations: + {{- . | nindent 4 }} + {{- end }} labels: {{- include "rustfs.labels" . | nindent 4 }} {{- with .Values.commonLabels }} @@ -29,13 +33,9 @@ kind: Service metadata: name: {{ include "rustfs.fullname" . }}-svc namespace: {{ .Release.Namespace }} - {{- if and .Values.mode.distributed.enabled (eq .Values.ingress.className "traefik")}} + {{- with (include "rustfs.serviceAnnotations" .) }} annotations: - {{- toYaml .Values.ingress.traefikAnnotations | nindent 4 }} - {{- if and .Values.mtls.enabled (eq .Values.ingress.className "traefik") }} - traefik.ingress.kubernetes.io/service.serversscheme: https - traefik.ingress.kubernetes.io/service.serverstransport: {{ .Release.Namespace }}-{{ include "rustfs.fullname" . }}-transport@kubernetescrd - {{- end }} + {{- . | nindent 4 }} {{- end }} labels: {{- include "rustfs.labels" . | nindent 4 }} diff --git a/helm/rustfs/values.yaml b/helm/rustfs/values.yaml index a61089821..88d1888e6 100644 --- a/helm/rustfs/values.yaml +++ b/helm/rustfs/values.yaml @@ -143,6 +143,14 @@ containerSecurityContext: runAsNonRoot: true service: + annotations: {} + headlessAnnotations: {} # Applied to the headless Service when mode.distributed.enabled=true + traefikAnnotations: # Applied to the Service when mode.distributed.enabled=true and ingress.className=traefik + traefik.ingress.kubernetes.io/service.sticky.cookie: "true" + traefik.ingress.kubernetes.io/service.sticky.cookie.httponly: "true" + traefik.ingress.kubernetes.io/service.sticky.cookie.name: rustfs + traefik.ingress.kubernetes.io/service.sticky.cookie.samesite: none + traefik.ingress.kubernetes.io/service.sticky.cookie.secure: "true" type: ClusterIP endpoint: port: 9000 @@ -155,12 +163,7 @@ service: ingress: enabled: true className: "nginx" # Specify the classname, traefik or nginx. Different classname has different annotations for session sticky. - traefikAnnotations: - traefik.ingress.kubernetes.io/service.sticky.cookie: "true" - traefik.ingress.kubernetes.io/service.sticky.cookie.httponly: "true" - traefik.ingress.kubernetes.io/service.sticky.cookie.name: rustfs - traefik.ingress.kubernetes.io/service.sticky.cookie.samesite: none - traefik.ingress.kubernetes.io/service.sticky.cookie.secure: "true" + traefikAnnotations: {} # Deprecated: use service.traefikAnnotations instead nginxAnnotations: nginx.ingress.kubernetes.io/affinity: cookie nginx.ingress.kubernetes.io/proxy-body-size: "0" @@ -168,7 +171,8 @@ ingress: nginx.ingress.kubernetes.io/session-cookie-hash: sha1 nginx.ingress.kubernetes.io/session-cookie-max-age: "3600" nginx.ingress.kubernetes.io/session-cookie-name: rustfs - customAnnotations: # Additional custom annotations (merged with class-specific annotations) + annotations: {} + customAnnotations: # Deprecated: use ingress.annotations instead {} hosts: - host: example.rustfs.com