From c87fcffb21352f14f0987ad54c2cfff22b6c85ad Mon Sep 17 00:00:00 2001 From: Aleksei Sviridkin Date: Thu, 12 Nov 2026 23:40:49 +0300 Subject: [PATCH 1/4] chore(seaweedfs): bump chart and in-tree image to 4.48 Re-vendor the chart from the 4.48 source archive and apply the carried patches in order; every one applies without fuzz. The s3-grpc-tls patch is dropped: 4.48 ships the same [grpc.s3] section, and the forward guard in make update stops at that patch by design. images/seaweedfs moves to the same tag so the binary matches the chart. The source checksum comes from the archive and the upstream digest from the registry. The builder tag is unchanged in 4.48, and the read-ahead patch still applies there. The crowded-lock patch is dropped: 4.48 already carries seaweedfs/seaweedfs#11216, so git apply rejects it. The new checksum annotations include the master ConfigMap and the s3 Secret templates, so the suites rendering those workloads now list them. weed admin refuses an unauthenticated non-loopback bind since 4.46, so the admin fixtures carry the credentials Secret the parent chart always sets. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin --- packages/system/seaweedfs/Makefile | 5 -- .../seaweedfs/charts/seaweedfs/Chart.yaml | 4 +- .../seaweedfs/charts/seaweedfs/README.md | 26 +++++- .../charts/seaweedfs/ci/admin-values.yaml | 7 ++ .../templates/admin/admin-ingress.yaml | 3 + .../templates/admin/admin-statefulset.yaml | 17 +++- .../all-in-one/all-in-one-deployment.yaml | 16 ++-- .../filer/filer-grpc-ingressroutetcp.yaml | 3 + .../templates/filer/filer-ingress.yaml | 6 ++ .../templates/filer/filer-statefulset.yaml | 16 ++-- .../templates/master/master-ingress.yaml | 3 + .../templates/master/master-statefulset.yaml | 9 +- .../seaweedfs/templates/s3/s3-deployment.yaml | 14 +-- .../templates/s3/s3-iceberg-ingress.yaml | 3 + .../seaweedfs/templates/s3/s3-ingress.yaml | 3 + .../templates/s3/s3-lance-ingress.yaml | 3 + .../seaweedfs/templates/s3/s3-secret.yaml | 2 +- .../seaweedfs/templates/shared/_helpers.tpl | 37 ++++++++ .../templates/volume/volume-ingress.yaml | 3 + .../seaweedfs/charts/seaweedfs/values.yaml | 39 ++++++++- .../seaweedfs/images/seaweedfs/Dockerfile | 15 +--- .../patches/volume-layout-crowded-lock.diff | 87 ------------------- .../seaweedfs/patches/s3-grpc-tls.patch | 24 ----- .../system/seaweedfs/tests/image_test.yaml | 1 + .../seaweedfs/tests/lifecycle_test.yaml | 48 ++++++++++ .../seaweedfs/tests/master_affinity_test.yaml | 2 + .../tests/master_probe_timeout_test.yaml | 3 + .../tests/s3_catalog_ports_test.yaml | 1 + .../seaweedfs/tests/s3_grpc_tls_test.yaml | 3 +- .../seaweedfs/tests/s3_tls_cosi_sa_test.yaml | 1 + .../tests/storage_class_string_test.yaml | 3 + .../tests/volume_slot_ceiling_test.yaml | 1 + packages/system/seaweedfs/values.yaml | 6 +- 33 files changed, 245 insertions(+), 169 deletions(-) create mode 100644 packages/system/seaweedfs/charts/seaweedfs/ci/admin-values.yaml delete mode 100644 packages/system/seaweedfs/images/seaweedfs/patches/volume-layout-crowded-lock.diff delete mode 100644 packages/system/seaweedfs/patches/s3-grpc-tls.patch diff --git a/packages/system/seaweedfs/Makefile b/packages/system/seaweedfs/Makefile index 54a9c0338..ffac56829 100644 --- a/packages/system/seaweedfs/Makefile +++ b/packages/system/seaweedfs/Makefile @@ -61,11 +61,6 @@ update: patch --no-backup-if-mismatch -p4 < patches/s3-service-name.patch patch --no-backup-if-mismatch -p4 < patches/s3-service-name-consumers.patch patch --no-backup-if-mismatch -p4 < patches/cluster-scoped-names-per-namespace.patch - # Backport of seaweedfs/seaweedfs#11157, released in 4.46: drop the patch - # once the vendored chart carries [grpc.s3]. --forward makes that point - # fail here, where BSD patch would otherwise reverse it and remove the - # section without an error. - patch --forward --no-backup-if-mismatch -p4 < patches/s3-grpc-tls.patch patch --forward --no-backup-if-mismatch -p4 < patches/storage-class-string.patch #patch --no-backup-if-mismatch -p4 < patches/retention-policy-delete.yaml $(MAKE) update-image diff --git a/packages/system/seaweedfs/charts/seaweedfs/Chart.yaml b/packages/system/seaweedfs/charts/seaweedfs/Chart.yaml index bfb39d484..1a7fac150 100644 --- a/packages/system/seaweedfs/charts/seaweedfs/Chart.yaml +++ b/packages/system/seaweedfs/charts/seaweedfs/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v1 description: SeaweedFS name: seaweedfs -appVersion: "4.45" +appVersion: "4.48" # Dev note: Trigger a helm chart release by `git tag -a helm-` -version: 4.45.0 +version: 4.48.0 diff --git a/packages/system/seaweedfs/charts/seaweedfs/README.md b/packages/system/seaweedfs/charts/seaweedfs/README.md index f787f8bb4..bebf3b0bc 100644 --- a/packages/system/seaweedfs/charts/seaweedfs/README.md +++ b/packages/system/seaweedfs/charts/seaweedfs/README.md @@ -286,7 +286,7 @@ metadata: app.kubernetes.io/component: s3 stringData: # this key must be an inline json config file - seaweedfs_s3_config: '{"identities":[{"name":"anvAdmin","credentials":[{"accessKey":"snu8yoP6QAlY0ne4","secretKey":"PNzBcmeLNEdR0oviwm04NQAicOrDH1Km"}],"actions":["Admin","Read","Write"]},{"name":"anvReadOnly","credentials":[{"accessKey":"SCigFee6c5lbi04A","secretKey":"kgFhbT38R8WUYVtiFQ1OiSVOrYr3NKku"}],"actions":["Read"]}]}' + seaweedfs_s3_config: '{"identities":[{"name":"anvAdmin","credentials":[{"accessKey":"snu8yoP6QAlY0ne4","secretKey":"PNzBcmeLNEdR0oviwm04NQAicOrDH1Km"}],"actions":["Admin","Read","Write"]},{"name":"anvReadOnly","credentials":[{"accessKey":"SCigFee6c5lbi04A","secretKey":"kgFhbT38R8WUYVtiFQ1OiSVOrYr3NKku"}],"actions":["Read","List"]}]}' ``` #### Source S3 credentials from an existing Secret @@ -363,6 +363,30 @@ If `adminPassword` is empty or not set, the admin interface runs without authent As an alternative, a kubernetes Secret can be used (`admin.secret.existingSecret`). +### Admin listen address + +Since SeaweedFS 4.46, `weed admin` defaults to listening on loopback (`127.0.0.1`). +The chart's httpGet readiness/liveness probes dial the pod IP, so the admin +server must bind a non-loopback address for the probes to succeed. The chart +therefore passes `-ip={{ .Values.admin.ip }}`, defaulting `admin.ip` to `0.0.0.0` +(the pre-4.46 behaviour of listening on all interfaces). + +Binding a non-loopback address requires authentication: `weed admin` refuses to +start on a non-loopback address without `-adminPassword`, so the chart fails at +render time if `admin.ip` is non-loopback and authentication is not configured via +`admin.secret.adminPassword`, `admin.secret.existingSecret`, or +`WEED_ADMIN_PASSWORD` supplied through `admin.extraEnvironmentVars` / +`admin.secretExtraEnvironmentVars`. Setting `admin.allowInsecureBind` renders +`-allowInsecureBind` and bypasses this guard; it leaves the admin API +unauthenticated on the network, so use it only when access is otherwise +restricted (e.g. network policies). The whole `127.0.0.0/8` range and `::1` are +treated as loopback (matching `weed admin`); `localhost` is treated as +non-loopback. Set `admin.ip` to a loopback address only if you also replace the +httpGet probes (e.g. with an `exec` probe that checks `127.0.0.1`). + +The `-ip` flag requires SeaweedFS 4.46 or newer; pinning `admin.imageOverride` +to an older image is not supported with this chart version. + ### Admin Data Persistence The admin component can store configuration and maintenance data. You can configure storage in several ways: diff --git a/packages/system/seaweedfs/charts/seaweedfs/ci/admin-values.yaml b/packages/system/seaweedfs/charts/seaweedfs/ci/admin-values.yaml new file mode 100644 index 000000000..021d5302c --- /dev/null +++ b/packages/system/seaweedfs/charts/seaweedfs/ci/admin-values.yaml @@ -0,0 +1,7 @@ +# Admin install: exercises the admin StatefulSet, which passes -ip (default +# 0.0.0.0) and therefore requires authentication to bind a non-loopback address. +admin: + enabled: true + secret: + adminUser: "admin" + adminPassword: "ci-admin-password" diff --git a/packages/system/seaweedfs/charts/seaweedfs/templates/admin/admin-ingress.yaml b/packages/system/seaweedfs/charts/seaweedfs/templates/admin/admin-ingress.yaml index d5106d163..1d9bd8b71 100644 --- a/packages/system/seaweedfs/charts/seaweedfs/templates/admin/admin-ingress.yaml +++ b/packages/system/seaweedfs/charts/seaweedfs/templates/admin/admin-ingress.yaml @@ -23,6 +23,9 @@ metadata: app.kubernetes.io/managed-by: {{ .Release.Service }} app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/component: admin + {{- with .Values.admin.ingress.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} spec: {{- if and (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) .Values.admin.ingress.className }} ingressClassName: {{ .Values.admin.ingress.className | quote }} diff --git a/packages/system/seaweedfs/charts/seaweedfs/templates/admin/admin-statefulset.yaml b/packages/system/seaweedfs/charts/seaweedfs/templates/admin/admin-statefulset.yaml index 1ce6f3cab..5947f0d1f 100644 --- a/packages/system/seaweedfs/charts/seaweedfs/templates/admin/admin-statefulset.yaml +++ b/packages/system/seaweedfs/charts/seaweedfs/templates/admin/admin-statefulset.yaml @@ -6,6 +6,11 @@ {{- if and (not .Values.admin.masters) (not .Values.global.seaweedfs.masterServer) (not .Values.master.enabled) }} {{- fail "admin.masters or global.seaweedfs.masterServer must be set if master.enabled is false" -}} {{- end }} +{{- $adminAuthEnabled := include "seaweedfs.admin.authEnabled" . }} +{{- $adminIp := .Values.admin.ip | default "0.0.0.0" }} +{{- if and (not (include "seaweedfs.admin.isLoopbackIp" $adminIp)) (ne $adminAuthEnabled "true") }} +{{- fail (printf "admin.ip is set to %q (non-loopback) but admin authentication is not configured. Since `weed admin` 4.46 refuses to bind a non-loopback address without authentication, the admin container would exit on startup. Set admin.secret.adminPassword or admin.secret.existingSecret, or supply WEED_ADMIN_PASSWORD via admin.extraEnvironmentVars / admin.secretExtraEnvironmentVars, or set admin.ip to a loopback address such as 127.0.0.1 (note: a loopback bind makes the chart's httpGet readiness/liveness probes fail), or set admin.allowInsecureBind to true to opt out via -allowInsecureBind (INSECURE: exposes the admin API unauthenticated on the network)." $adminIp) -}} +{{- end }} apiVersion: apps/v1 kind: StatefulSet metadata: @@ -162,6 +167,7 @@ spec: -v={{ .Values.global.seaweedfs.loggingLevel }} \ {{- end }} admin \ + -ip={{ .Values.admin.ip | default "0.0.0.0" }} \ -port={{ .Values.admin.port }} \ -port.grpc={{ .Values.admin.grpcPort }} \ {{- if or (eq .Values.admin.data.type "hostPath") (eq .Values.admin.data.type "persistentVolumeClaim") (eq .Values.admin.data.type "emptyDir") (eq .Values.admin.data.type "existingClaim") }} @@ -170,14 +176,17 @@ spec: -dataDir={{ .Values.admin.dataDir }} \ {{- end }} {{- if .Values.admin.masters }} - -masters={{ .Values.admin.masters }}{{- if or $urlPrefix .Values.admin.extraArgs }} \{{ end }} + -masters={{ .Values.admin.masters }} \ {{- else if .Values.global.seaweedfs.masterServer }} - -masters={{ .Values.global.seaweedfs.masterServer }}{{- if or $urlPrefix .Values.admin.extraArgs }} \{{ end }} + -masters={{ .Values.global.seaweedfs.masterServer }} \ {{- else }} - -masters={{ range $index := until (.Values.master.replicas | int) }}${SEAWEEDFS_FULLNAME}-master-{{ $index }}.${SEAWEEDFS_FULLNAME}-master.{{ $.Release.Namespace }}:{{ $.Values.master.port }}{{ if lt $index (sub ($.Values.master.replicas | int) 1) }},{{ end }}{{ end }}{{- if or $urlPrefix .Values.admin.extraArgs }} \{{ end }} + -masters={{ range $index := until (.Values.master.replicas | int) }}${SEAWEEDFS_FULLNAME}-master-{{ $index }}.${SEAWEEDFS_FULLNAME}-master.{{ $.Release.Namespace }}:{{ $.Values.master.port }}{{ if lt $index (sub ($.Values.master.replicas | int) 1) }},{{ end }}{{ end }} \ {{- end }} {{- if $urlPrefix }} - -urlPrefix={{ $urlPrefix }}{{- if .Values.admin.extraArgs }} \{{ end }} + -urlPrefix={{ $urlPrefix }} \ + {{- end }} + {{- if .Values.admin.allowInsecureBind }} + -allowInsecureBind \ {{- end }} {{- range $index, $arg := .Values.admin.extraArgs }} {{ $arg }}{{- if lt $index (sub (len $.Values.admin.extraArgs) 1) }} \{{ end }} diff --git a/packages/system/seaweedfs/charts/seaweedfs/templates/all-in-one/all-in-one-deployment.yaml b/packages/system/seaweedfs/charts/seaweedfs/templates/all-in-one/all-in-one-deployment.yaml index 9202ae8cd..9f4a92e75 100644 --- a/packages/system/seaweedfs/charts/seaweedfs/templates/all-in-one/all-in-one-deployment.yaml +++ b/packages/system/seaweedfs/charts/seaweedfs/templates/all-in-one/all-in-one-deployment.yaml @@ -37,13 +37,17 @@ spec: {{- with .Values.allInOne.podLabels }} {{- toYaml . | nindent 8 }} {{- end }} + {{- $podAnnotations := mergeOverwrite (deepCopy (.Values.podAnnotations | default dict)) (.Values.allInOne.podAnnotations | default dict) }} + {{- $existingS3ConfigSecret := or .Values.allInOne.s3.existingConfigSecret .Values.s3.existingConfigSecret .Values.filer.s3.existingConfigSecret }} + {{- if $existingS3ConfigSecret }} + {{- $configSecret := (lookup "v1" "Secret" .Release.Namespace $existingS3ConfigSecret) | default dict }} + {{- $_ := set $podAnnotations "checksum/s3config" ($configSecret | toYaml | sha256sum) }} + {{- else }} + {{- $_ := set $podAnnotations "checksum/s3config" (include (print .Template.BasePath "/s3/s3-secret.yaml") . | sha256sum) }} + {{- end }} + {{- $_ := set $podAnnotations "checksum/master-config" (include (print .Template.BasePath "/master/master-configmap.yaml") . | sha256sum) }} annotations: - {{- with .Values.podAnnotations }} - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.allInOne.podAnnotations }} - {{- toYaml . | nindent 8 }} - {{- end }} + {{- toYaml $podAnnotations | nindent 8 }} spec: restartPolicy: {{ default .Values.global.seaweedfs.restartPolicy .Values.allInOne.restartPolicy }} {{- if .Values.allInOne.affinity }} diff --git a/packages/system/seaweedfs/charts/seaweedfs/templates/filer/filer-grpc-ingressroutetcp.yaml b/packages/system/seaweedfs/charts/seaweedfs/templates/filer/filer-grpc-ingressroutetcp.yaml index c1c2f7d78..8c150971d 100644 --- a/packages/system/seaweedfs/charts/seaweedfs/templates/filer/filer-grpc-ingressroutetcp.yaml +++ b/packages/system/seaweedfs/charts/seaweedfs/templates/filer/filer-grpc-ingressroutetcp.yaml @@ -24,6 +24,9 @@ metadata: app.kubernetes.io/managed-by: {{ .Release.Service }} app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/component: filer + {{- with .Values.filer.ingresses.grpc.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} spec: {{- if $securityEnabled }} tls: diff --git a/packages/system/seaweedfs/charts/seaweedfs/templates/filer/filer-ingress.yaml b/packages/system/seaweedfs/charts/seaweedfs/templates/filer/filer-ingress.yaml index b747cd2d8..335f250b0 100644 --- a/packages/system/seaweedfs/charts/seaweedfs/templates/filer/filer-ingress.yaml +++ b/packages/system/seaweedfs/charts/seaweedfs/templates/filer/filer-ingress.yaml @@ -29,6 +29,9 @@ metadata: app.kubernetes.io/managed-by: {{ .Release.Service }} app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/component: filer + {{- with .Values.filer.ingresses.http.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} spec: {{- if and (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) .Values.filer.ingresses.http.className }} ingressClassName: {{ .Values.filer.ingresses.http.className | quote }} @@ -87,6 +90,9 @@ metadata: app.kubernetes.io/managed-by: {{ .Release.Service }} app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/component: filer + {{- with .Values.filer.ingresses.grpc.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} spec: {{- if and (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) .Values.filer.ingresses.grpc.className }} ingressClassName: {{ .Values.filer.ingresses.grpc.className | quote }} diff --git a/packages/system/seaweedfs/charts/seaweedfs/templates/filer/filer-statefulset.yaml b/packages/system/seaweedfs/charts/seaweedfs/templates/filer/filer-statefulset.yaml index ced2d597a..b432ebd6f 100644 --- a/packages/system/seaweedfs/charts/seaweedfs/templates/filer/filer-statefulset.yaml +++ b/packages/system/seaweedfs/charts/seaweedfs/templates/filer/filer-statefulset.yaml @@ -43,19 +43,15 @@ spec: {{- with .Values.filer.podLabels }} {{- toYaml . | nindent 8 }} {{- end }} - annotations: - {{- with .Values.podAnnotations }} - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.filer.podAnnotations }} - {{- toYaml . | nindent 8 }} - {{- end }} + {{- $podAnnotations := mergeOverwrite (deepCopy (.Values.podAnnotations | default dict)) (.Values.filer.podAnnotations | default dict) }} {{- if .Values.filer.s3.existingConfigSecret }} - {{- $configSecret := (lookup "v1" "Secret" .Release.Namespace .Values.filer.s3.existingConfigSecret) | default dict }} - checksum/s3config: {{ $configSecret | toYaml | sha256sum }} + {{- $configSecret := (lookup "v1" "Secret" .Release.Namespace .Values.filer.s3.existingConfigSecret) | default dict }} + {{- $_ := set $podAnnotations "checksum/s3config" ($configSecret | toYaml | sha256sum) }} {{- else }} - checksum/s3config: {{ include (print .Template.BasePath "/s3/s3-secret.yaml") . | sha256sum }} + {{- $_ := set $podAnnotations "checksum/s3config" (include (print .Template.BasePath "/s3/s3-secret.yaml") . | sha256sum) }} {{- end }} + annotations: + {{- toYaml $podAnnotations | nindent 8 }} spec: restartPolicy: {{ default .Values.global.seaweedfs.restartPolicy .Values.filer.restartPolicy }} {{- if .Values.filer.affinity }} diff --git a/packages/system/seaweedfs/charts/seaweedfs/templates/master/master-ingress.yaml b/packages/system/seaweedfs/charts/seaweedfs/templates/master/master-ingress.yaml index 75319709a..9ec8819a2 100644 --- a/packages/system/seaweedfs/charts/seaweedfs/templates/master/master-ingress.yaml +++ b/packages/system/seaweedfs/charts/seaweedfs/templates/master/master-ingress.yaml @@ -21,6 +21,9 @@ metadata: app.kubernetes.io/managed-by: {{ .Release.Service }} app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/component: master + {{- with .Values.master.ingress.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} spec: ingressClassName: {{ .Values.master.ingress.className | quote }} tls: diff --git a/packages/system/seaweedfs/charts/seaweedfs/templates/master/master-statefulset.yaml b/packages/system/seaweedfs/charts/seaweedfs/templates/master/master-statefulset.yaml index 5df83e687..211bd66d2 100644 --- a/packages/system/seaweedfs/charts/seaweedfs/templates/master/master-statefulset.yaml +++ b/packages/system/seaweedfs/charts/seaweedfs/templates/master/master-statefulset.yaml @@ -43,13 +43,10 @@ spec: {{- with .Values.master.podLabels }} {{- toYaml . | nindent 8 }} {{- end }} + {{- $podAnnotations := mergeOverwrite (deepCopy (.Values.podAnnotations | default dict)) (.Values.master.podAnnotations | default dict) }} + {{- $_ := set $podAnnotations "checksum/master-config" (include (print .Template.BasePath "/master/master-configmap.yaml") . | sha256sum) }} annotations: - {{ with .Values.podAnnotations }} - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.master.podAnnotations }} - {{- toYaml . | nindent 8 }} - {{- end }} + {{- toYaml $podAnnotations | nindent 8 }} spec: restartPolicy: {{ default .Values.global.seaweedfs.restartPolicy .Values.master.restartPolicy }} {{- if .Values.master.affinity }} diff --git a/packages/system/seaweedfs/charts/seaweedfs/templates/s3/s3-deployment.yaml b/packages/system/seaweedfs/charts/seaweedfs/templates/s3/s3-deployment.yaml index cf5710ba0..a0ed1c7fb 100644 --- a/packages/system/seaweedfs/charts/seaweedfs/templates/s3/s3-deployment.yaml +++ b/packages/system/seaweedfs/charts/seaweedfs/templates/s3/s3-deployment.yaml @@ -35,13 +35,15 @@ spec: {{- with .Values.s3.podLabels }} {{- toYaml . | nindent 8 }} {{- end }} + {{- $podAnnotations := mergeOverwrite (deepCopy (.Values.podAnnotations | default dict)) (.Values.s3.podAnnotations | default dict) }} + {{- if .Values.s3.existingConfigSecret }} + {{- $configSecret := (lookup "v1" "Secret" .Release.Namespace .Values.s3.existingConfigSecret) | default dict }} + {{- $_ := set $podAnnotations "checksum/s3config" ($configSecret | toYaml | sha256sum) }} + {{- else }} + {{- $_ := set $podAnnotations "checksum/s3config" (include (print .Template.BasePath "/s3/s3-secret.yaml") . | sha256sum) }} + {{- end }} annotations: - {{ with .Values.podAnnotations }} - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.s3.podAnnotations }} - {{- toYaml . | nindent 8 }} - {{- end }} + {{- toYaml $podAnnotations | nindent 8 }} spec: restartPolicy: {{ default .Values.global.seaweedfs.restartPolicy .Values.s3.restartPolicy }} {{- if .Values.s3.affinity }} diff --git a/packages/system/seaweedfs/charts/seaweedfs/templates/s3/s3-iceberg-ingress.yaml b/packages/system/seaweedfs/charts/seaweedfs/templates/s3/s3-iceberg-ingress.yaml index 68db538dc..a1551336f 100644 --- a/packages/system/seaweedfs/charts/seaweedfs/templates/s3/s3-iceberg-ingress.yaml +++ b/packages/system/seaweedfs/charts/seaweedfs/templates/s3/s3-iceberg-ingress.yaml @@ -41,6 +41,9 @@ metadata: app.kubernetes.io/managed-by: {{ .Release.Service }} app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/component: s3-iceberg + {{- with .Values.s3.icebergIngress.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} spec: {{- if .Values.s3.icebergIngress.className }} ingressClassName: {{ .Values.s3.icebergIngress.className | quote }} diff --git a/packages/system/seaweedfs/charts/seaweedfs/templates/s3/s3-ingress.yaml b/packages/system/seaweedfs/charts/seaweedfs/templates/s3/s3-ingress.yaml index c92063f8c..852b29f0c 100644 --- a/packages/system/seaweedfs/charts/seaweedfs/templates/s3/s3-ingress.yaml +++ b/packages/system/seaweedfs/charts/seaweedfs/templates/s3/s3-ingress.yaml @@ -32,6 +32,9 @@ metadata: app.kubernetes.io/managed-by: {{ .Release.Service }} app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/component: s3 + {{- with .Values.s3.ingress.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} spec: ingressClassName: {{ .Values.s3.ingress.className | quote }} tls: diff --git a/packages/system/seaweedfs/charts/seaweedfs/templates/s3/s3-lance-ingress.yaml b/packages/system/seaweedfs/charts/seaweedfs/templates/s3/s3-lance-ingress.yaml index 32033a8f1..eeca7b02e 100644 --- a/packages/system/seaweedfs/charts/seaweedfs/templates/s3/s3-lance-ingress.yaml +++ b/packages/system/seaweedfs/charts/seaweedfs/templates/s3/s3-lance-ingress.yaml @@ -41,6 +41,9 @@ metadata: app.kubernetes.io/managed-by: {{ .Release.Service }} app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/component: s3-lance + {{- with .Values.s3.lanceIngress.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} spec: {{- if .Values.s3.lanceIngress.className }} ingressClassName: {{ .Values.s3.lanceIngress.className | quote }} diff --git a/packages/system/seaweedfs/charts/seaweedfs/templates/s3/s3-secret.yaml b/packages/system/seaweedfs/charts/seaweedfs/templates/s3/s3-secret.yaml index 2c1d87da5..595d9091d 100644 --- a/packages/system/seaweedfs/charts/seaweedfs/templates/s3/s3-secret.yaml +++ b/packages/system/seaweedfs/charts/seaweedfs/templates/s3/s3-secret.yaml @@ -60,7 +60,7 @@ stringData: read_access_key_id: {{ $access_key_read }} read_secret_access_key: {{ $secret_key_read }} {{- end }} - seaweedfs_s3_config: '{"identities":[{"name":"anvAdmin","credentials":[{"accessKey":"{{ $access_key_admin }}","secretKey":"{{ $secret_key_admin }}"}],"actions":["Admin","Read","Write"]},{"name":"anvReadOnly","credentials":[{"accessKey":"{{ $access_key_read }}","secretKey":"{{ $secret_key_read }}"}],"actions":["Read"]}]}' + seaweedfs_s3_config: '{"identities":[{"name":"anvAdmin","credentials":[{"accessKey":"{{ $access_key_admin }}","secretKey":"{{ $secret_key_admin }}"}],"actions":["Admin","Read","Write"]},{"name":"anvReadOnly","credentials":[{"accessKey":"{{ $access_key_read }}","secretKey":"{{ $secret_key_read }}"}],"actions":["Read","List"]}]}' {{- if .Values.filer.s3.auditLogConfig }} filer_s3_auditLogConfig.json: | {{ toJson .Values.filer.s3.auditLogConfig | nindent 4 }} diff --git a/packages/system/seaweedfs/charts/seaweedfs/templates/shared/_helpers.tpl b/packages/system/seaweedfs/charts/seaweedfs/templates/shared/_helpers.tpl index 6fc10efe6..d9d0dfdce 100644 --- a/packages/system/seaweedfs/charts/seaweedfs/templates/shared/_helpers.tpl +++ b/packages/system/seaweedfs/charts/seaweedfs/templates/shared/_helpers.tpl @@ -88,6 +88,43 @@ true {{- end -}} {{- end -}} +{{/* Classify an admin bind address as loopback, mirroring weed admin's + isLoopbackIp (net.ParseIP + IsLoopback). Helm templates cannot call + net.ParseIP, so we approximate: valid IPv4 addresses in 127.0.0.0/8 + (validated via regex to reject malformed values like "127.not-an-ip") + and the IPv6 loopback "::1" / its expanded form "0:0:0:0:0:0:0:1" are + loopback. Hostnames (e.g. "localhost") and wildcard addresses + ("0.0.0.0", "::") are non-loopback, matching the binary, which + treats unparseable hostnames as non-loopback to be safe. Other IPv6 + loopback representations are not matched; the binary's own runtime + validation is the authoritative guard. */}} +{{- define "seaweedfs.admin.isLoopbackIp" -}} +{{- $ip := toString . -}} +{{- if or (regexMatch "^127\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$" $ip) (eq $ip "::1") (eq $ip "0:0:0:0:0:0:0:1") -}} +true +{{- end -}} +{{- end -}} + +{{/* Whether the admin non-loopback bind guard is satisfied: admin.secret + (adminPassword or existingSecret), WEED_ADMIN_PASSWORD via + extraEnvironmentVars / secretExtraEnvironmentVars, or + admin.allowInsecureBind. A secret-backed entry counts as enabled even + though the chart cannot read its value. */}} +{{- define "seaweedfs.admin.authEnabled" -}} +{{- if or .Values.admin.secret.existingSecret .Values.admin.secret.adminPassword .Values.admin.allowInsecureBind -}} +true +{{- else -}} +{{- $merged := dict -}} +{{- $_ := include "seaweedfs.mergeExtraEnvironmentVars" (dict "global" .Values.global.seaweedfs "component" .Values.admin "target" $merged) -}} +{{- $envPassword := index $merged "WEED_ADMIN_PASSWORD" -}} +{{- if or (kindIs "map" $envPassword) (hasKey (.Values.admin.secretExtraEnvironmentVars | default dict) "WEED_ADMIN_PASSWORD") -}} +true +{{- else if and $envPassword (ne (toString $envPassword) "") -}} +true +{{- end -}} +{{- end -}} +{{- end -}} + {{/* Return the proper filer image */}} {{- define "seaweedfs.filer.image" -}} {{- if .Values.filer.imageOverride -}} diff --git a/packages/system/seaweedfs/charts/seaweedfs/templates/volume/volume-ingress.yaml b/packages/system/seaweedfs/charts/seaweedfs/templates/volume/volume-ingress.yaml index b36c29867..15d24de5f 100644 --- a/packages/system/seaweedfs/charts/seaweedfs/templates/volume/volume-ingress.yaml +++ b/packages/system/seaweedfs/charts/seaweedfs/templates/volume/volume-ingress.yaml @@ -27,6 +27,9 @@ metadata: app.kubernetes.io/managed-by: {{ .Release.Service }} app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/component: volume + {{- with .Values.volume.ingress.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} spec: {{- if and (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) .Values.volume.ingress.className }} ingressClassName: {{ .Values.volume.ingress.className | quote }} diff --git a/packages/system/seaweedfs/charts/seaweedfs/values.yaml b/packages/system/seaweedfs/charts/seaweedfs/values.yaml index 6bae8df66..5b8a8c2e5 100644 --- a/packages/system/seaweedfs/charts/seaweedfs/values.yaml +++ b/packages/system/seaweedfs/charts/seaweedfs/values.yaml @@ -55,7 +55,7 @@ global: gatewayHost: null gatewayPort: null additionalLabels: {} - # if enabled will use global.seaweedfs.replicationPlacement and override master & filer defaultReplicaPlacement config + # if enabled will use global.seaweedfs.replicationPlacement and override master.defaultReplication & filer.defaultReplicaPlacement config enableReplication: false # replication type is XYZ: # X number of replica in other data centers @@ -190,6 +190,8 @@ master: podLabels: {} # Annotations to be added to the master pods + # The chart sets checksum/master-config on master pods; other checksum/* keys + # can be used for custom rollouts. podAnnotations: {} # Annotations to be added to the master resources @@ -276,6 +278,7 @@ master: host: "master.seaweedfs.local" path: "/sw-master/?(.*)" pathType: ImplementationSpecific + labels: {} annotations: {} # nginx.ingress.kubernetes.io/auth-type: "basic" # nginx.ingress.kubernetes.io/auth-secret: "default/ingress-basic-auth-secret" @@ -600,6 +603,7 @@ volume: host: "volume.seaweedfs.local" path: "/" pathType: Prefix + labels: {} annotations: nginx.ingress.kubernetes.io/app-root: /ui/index.html # nginx.ingress.kubernetes.io/use-regex: "true" @@ -771,6 +775,8 @@ filer: podLabels: {} # Annotations to be added to the filer pods + # The chart sets checksum/s3config on filer pods; other checksum/* keys can be + # used for custom rollouts. podAnnotations: {} # Annotations to be added to the filer resource @@ -858,6 +864,7 @@ filer: host: "seaweedfs.cluster.local" path: "/sw-filer/?(.*)" pathType: ImplementationSpecific + labels: {} annotations: {} # nginx.ingress.kubernetes.io/backend-protocol: GRPC # nginx.ingress.kubernetes.io/auth-type: "basic" @@ -884,6 +891,7 @@ filer: # whole host, not the HTTP UI's regex path. path: "/" pathType: Prefix + labels: {} annotations: # Ingress terminates TLS and re-originates gRPC (HTTP/2) to the filer. nginx.ingress.kubernetes.io/backend-protocol: "GRPC" @@ -1074,6 +1082,8 @@ s3: podLabels: {} # Annotations to be added to the s3 pods + # The chart sets checksum/s3config on s3 pods; other checksum/* keys can be + # used for custom rollouts. podAnnotations: {} # Annotations to be added to the s3 resources @@ -1180,6 +1190,7 @@ s3: host: "seaweedfs.cluster.local" path: "/" pathType: Prefix + labels: {} # additional ingress annotations for the s3 endpoint annotations: {} tls: [] @@ -1205,6 +1216,7 @@ s3: host: "seaweedfs-iceberg.cluster.local" path: "/" pathType: Prefix + labels: {} annotations: {} tls: [] @@ -1214,6 +1226,7 @@ s3: host: "seaweedfs-lance.cluster.local" path: "/" pathType: Prefix + labels: {} annotations: {} tls: [] @@ -1321,8 +1334,26 @@ admin: replicas: 1 port: 23646 # Default admin port grpcPort: 33646 # Default gRPC port for worker connections + # IP address the admin server listens on. Since `weed admin` 4.46 defaults to + # loopback (127.0.0.1), the chart must bind a non-loopback address for the + # kubelet's httpGet readiness/liveness probes (which dial the pod IP) to ever + # succeed. "0.0.0.0" restores the pre-4.46 behaviour of listening on all + # interfaces. A non-loopback address requires authentication: set + # admin.secret.adminPassword or admin.secret.existingSecret, supply + # WEED_ADMIN_PASSWORD via admin.extraEnvironmentVars / + # admin.secretExtraEnvironmentVars, or opt out with admin.allowInsecureBind; + # otherwise the admin container will exit with a clear error rather than + # silently staying unready. The whole + # 127.0.0.0/8 range and ::1 are treated as loopback (matching weed admin). + # Set to a loopback address only if you also replace the httpGet probes. + # Note: the -ip flag requires SeaweedFS 4.46 or newer; pinning + # admin.imageOverride to an older image is not supported with this chart. + ip: "0.0.0.0" loggingOverrideLevel: null + # INSECURE: allow binding a non-loopback ip without authentication. + allowInsecureBind: false + # Admin authentication secret: # Name of an existing secret containing admin credentials. If set, adminUser and adminPassword below are ignored. @@ -1445,6 +1476,7 @@ admin: host: "admin.seaweedfs.local" path: "/" pathType: Prefix + labels: {} annotations: {} tls: [] @@ -1766,6 +1798,8 @@ allInOne: initContainers: "" # Init containers sidecars: "" # Sidecar containers annotations: {} # Annotations for the deployment + # The chart sets checksum/master-config and checksum/s3config on all-in-one + # pods; other checksum/* keys can be used for custom rollouts. podAnnotations: {} # Annotations for the pods podLabels: {} # Labels for the pods @@ -1900,6 +1934,9 @@ certificates: # Labels to be added to all the created pods podLabels: {} # Annotations to be added to all the created pods +# The chart sets checksum/master-config and checksum/s3config on pods whose +# rendered ConfigMaps or Secrets should trigger rollouts. Other checksum/* keys +# can be used for custom rollout annotations. podAnnotations: {} networkPolicy: diff --git a/packages/system/seaweedfs/images/seaweedfs/Dockerfile b/packages/system/seaweedfs/images/seaweedfs/Dockerfile index d52ee7329..8e942ee97 100644 --- a/packages/system/seaweedfs/images/seaweedfs/Dockerfile +++ b/packages/system/seaweedfs/images/seaweedfs/Dockerfile @@ -16,22 +16,13 @@ # seaweedfs/seaweedfs#11674 after 4.48; drop the patch on the first vendored # release that carries it. # -# patches/volume-layout-crowded-lock.diff makes SetVolumeCrowded take the write -# lock of the volume layout. Upstream 4.45 mutates the crowded map under the -# read lock, while Assign reads it under the same read lock through -# GetWritableVolumeCount, so under a steady stream of writes the master dies on -# a fatal "concurrent map read and map write", which recover cannot catch, and -# S3 answers 500 until it is back. Backport of seaweedfs/seaweedfs#11216, -# released in 4.46; drop the patch on the first vendored release that carries -# it. -# # `make update` re-pins VERSION from the vendored chart, SOURCE_SHA256 from the # source archive of that tag, UPSTREAM_DIGEST from the upstream image of that # tag and the builder from upstream's docker/Dockerfile.go_build, and checks # that the patches still apply. -ARG VERSION=4.45 -ARG SOURCE_SHA256=800a91693e2a4e974ef0e2a157b6a04eff9f4df507303b1cff31b0601081fc30 -ARG UPSTREAM_DIGEST=sha256:fc9f76fa993ad69966ffeb2f65d0318fcae39c6f8e20cf68ef7b3a5cb97769e5 +ARG VERSION=4.48 +ARG SOURCE_SHA256=93199495e93a981451d1fefecb5aa71e12aa1692093eed2338bbfe7f08960bfb +ARG UPSTREAM_DIGEST=sha256:4e61d15fd35994cb1e43e1e553dff106794841fd9a99ade2fc8c8bfce4d7872d # The Go toolchain of upstream's builder (docker/Dockerfile.go_build), which # compiles the upstream weed. diff --git a/packages/system/seaweedfs/images/seaweedfs/patches/volume-layout-crowded-lock.diff b/packages/system/seaweedfs/images/seaweedfs/patches/volume-layout-crowded-lock.diff deleted file mode 100644 index 12e09ca67..000000000 --- a/packages/system/seaweedfs/images/seaweedfs/patches/volume-layout-crowded-lock.diff +++ /dev/null @@ -1,87 +0,0 @@ -diff --git a/weed/topology/crowded_writable_test.go b/weed/topology/crowded_writable_test.go ---- a/weed/topology/crowded_writable_test.go -+++ b/weed/topology/crowded_writable_test.go -@@ -1,6 +1,7 @@ - package topology - - import ( -+ "sync" - "testing" - "time" - -@@ -73,3 +74,52 @@ func TestCrowdedCountStillMatchesWritables(t *testing.T) { - t.Errorf("writable=%d crowded=%d, want 1 and 1", writable, crowded) - } - } -+ -+// SetVolumeCrowded mutates the crowded map while GetWritableVolumeCount reads -+// it on the Assign hot path. Under RLock both could run at once and the Go -+// runtime aborts with "concurrent map read and map write". Run with -race to -+// reproduce the original bug; the write lock makes this pass. -+func TestSetVolumeCrowdedNoRaceWithGetWritableVolumeCount(t *testing.T) { -+ rp, _ := super_block.NewReplicaPlacementFromString("000") -+ vl := NewVolumeLayout(rp, needle.EMPTY_TTL, types.HardDriveType, 10000, false) -+ // GetWritableVolumeCount iterates vl.writables, so give it something to -+ // read while the crowded map is being mutated. -+ vl.writables = []needle.VolumeId{1, 2, 3} -+ -+ var wg sync.WaitGroup -+ stop := make(chan struct{}) -+ for range 8 { -+ wg.Add(1) -+ go func() { -+ defer wg.Done() -+ for { -+ select { -+ case <-stop: -+ return -+ default: -+ vl.SetVolumeCrowded(needle.VolumeId(2)) -+ } -+ } -+ }() -+ } -+ for range 8 { -+ wg.Add(1) -+ go func() { -+ defer wg.Done() -+ for { -+ select { -+ case <-stop: -+ return -+ default: -+ vl.GetWritableVolumeCount() -+ } -+ } -+ }() -+ } -+ -+ // The race detector needs only a brief window to flag a concurrent -+ // map read/write; let the goroutines hammer the lock briefly. -+ time.Sleep(50 * time.Millisecond) -+ close(stop) -+ wg.Wait() -+} -diff --git a/weed/topology/volume_layout.go b/weed/topology/volume_layout.go ---- a/weed/topology/volume_layout.go -+++ b/weed/topology/volume_layout.go -@@ -1019,11 +1019,14 @@ func (vl *VolumeLayout) setVolumeCrowded(vid needle.VolumeId) { - } - - func (vl *VolumeLayout) SetVolumeCrowded(vid needle.VolumeId) { -- // since delete is guarded by accessLock.Lock(), -- // and is always called in sequential order, -- // RLock() should be safe enough -- vl.accessLock.RLock() -- defer vl.accessLock.RUnlock() -+ // setVolumeCrowded mutates the crowded map, and GetWritableVolumeCount -+ // reads it under RLock on the Assign hot path. Two concurrent RLock -+ // holders with one writing the map triggers a fatal -+ // "concurrent map read and map write". Take the write lock: this path -+ // is a low-frequency single consumer driven by the crowded-volume -+ // event loop, and every other mutation of crowded already holds Lock(). -+ vl.accessLock.Lock() -+ defer vl.accessLock.Unlock() - - vl.setVolumeCrowded(vid) - } diff --git a/packages/system/seaweedfs/patches/s3-grpc-tls.patch b/packages/system/seaweedfs/patches/s3-grpc-tls.patch deleted file mode 100644 index d4d45fbd0..000000000 --- a/packages/system/seaweedfs/patches/s3-grpc-tls.patch +++ /dev/null @@ -1,24 +0,0 @@ -diff --git a/packages/system/seaweedfs/charts/seaweedfs/templates/shared/security-configmap.yaml b/packages/system/seaweedfs/charts/seaweedfs/templates/shared/security-configmap.yaml -index a067e1de9..17b82cca0 100644 ---- a/packages/system/seaweedfs/charts/seaweedfs/templates/shared/security-configmap.yaml -+++ b/packages/system/seaweedfs/charts/seaweedfs/templates/shared/security-configmap.yaml -@@ -97,6 +97,19 @@ data: - cert = "/usr/local/share/ca-certificates/worker/tls.crt" - key = "/usr/local/share/ca-certificates/worker/tls.key" - -+ {{- /* S3 gRPC server identity (weed s3 -port.grpc, default httpPort+10000). -+ Without this section, LoadServerTLS("grpc.s3") returns nil and the S3 -+ server serves its internal gRPC (IAM cache propagation, s3 lifecycle -+ delete RPCs) as plaintext, while peers dial it with mTLS credentials: -+ "tls: first record does not look like a TLS handshake". -+ Always uses the internal CA-signed client certificate (already mounted -+ on s3 pods by s3-deployment.yaml). Deliberately NOT s3.tlsSecret: that -+ secret is for the public HTTPS listener and may be issued by a public -+ CA which internal gRPC peers (trusting only grpc.ca) would reject. */}} -+ [grpc.s3] -+ cert = "/usr/local/share/ca-certificates/client/tls.crt" -+ key = "/usr/local/share/ca-certificates/client/tls.key" -+ - # use this for any place needs a grpc client - # i.e., "weed backup|benchmark|filer.copy|filer.replicate|mount|s3|upload" - [grpc.client] diff --git a/packages/system/seaweedfs/tests/image_test.yaml b/packages/system/seaweedfs/tests/image_test.yaml index e9532497a..8edfa2a15 100644 --- a/packages/system/seaweedfs/tests/image_test.yaml +++ b/packages/system/seaweedfs/tests/image_test.yaml @@ -8,6 +8,7 @@ suite: seaweedfs image templates: - charts/seaweedfs/templates/master/master-statefulset.yaml + - charts/seaweedfs/templates/master/master-configmap.yaml - charts/seaweedfs/templates/volume/volume-statefulset.yaml - charts/seaweedfs/templates/filer/filer-statefulset.yaml - charts/seaweedfs/templates/s3/s3-deployment.yaml diff --git a/packages/system/seaweedfs/tests/lifecycle_test.yaml b/packages/system/seaweedfs/tests/lifecycle_test.yaml index 0fd02b8a8..4d30177ea 100644 --- a/packages/system/seaweedfs/tests/lifecycle_test.yaml +++ b/packages/system/seaweedfs/tests/lifecycle_test.yaml @@ -14,6 +14,43 @@ release: namespace: tenant-root tests: + - it: refuses a non-loopback admin without authentication + template: charts/seaweedfs/templates/admin/admin-statefulset.yaml + set: + seaweedfs: + global: + seaweedfs: + extraEnvironmentVars: null + admin: &unauthenticatedAdmin + enabled: true + ip: "0.0.0.0" + allowInsecureBind: false + secret: + existingSecret: "" + adminPassword: "" + extraEnvironmentVars: null + secretExtraEnvironmentVars: null + asserts: + - failedTemplate: + errorPattern: 'admin\.ip is set to "0\.0\.0\.0" \(non-loopback\) but admin authentication is not configured\.' + + - it: allows an explicitly unauthenticated non-loopback admin + template: charts/seaweedfs/templates/admin/admin-statefulset.yaml + set: + seaweedfs: + global: + seaweedfs: + extraEnvironmentVars: null + admin: + <<: *unauthenticatedAdmin + allowInsecureBind: true + asserts: + - isKind: + of: StatefulSet + - matchRegex: + path: spec.template.spec.containers[0].command[2] + pattern: '-allowInsecureBind ' + - it: runs the admin server that schedules lifecycle jobs template: charts/seaweedfs/templates/admin/admin-statefulset.yaml set: &enabled @@ -47,6 +84,17 @@ tests: path: spec.volumeClaimTemplates[0].spec.resources.requests.storage value: 1Gi + # weed admin keeps its worker gRPC port on loopback unless -ip is given + # explicitly (weed/command/admin.go at 4.48), and the worker runs in its own + # pod. + - it: lets the worker reach the admin gRPC port + template: charts/seaweedfs/templates/admin/admin-statefulset.yaml + set: *enabled + asserts: + - matchRegex: + path: spec.template.spec.containers[0].command[2] + pattern: '-ip=0\.0\.0\.0 ' + - it: runs the worker against the admin of the same release template: charts/seaweedfs/templates/worker/worker-deployment.yaml set: *enabled diff --git a/packages/system/seaweedfs/tests/master_affinity_test.yaml b/packages/system/seaweedfs/tests/master_affinity_test.yaml index 8fd4eaba5..838d4fa4d 100644 --- a/packages/system/seaweedfs/tests/master_affinity_test.yaml +++ b/packages/system/seaweedfs/tests/master_affinity_test.yaml @@ -12,6 +12,7 @@ suite: seaweedfs master anti-affinity templates: - charts/seaweedfs/templates/master/master-statefulset.yaml + - charts/seaweedfs/templates/master/master-configmap.yaml release: name: seaweedfs @@ -19,6 +20,7 @@ release: tests: - it: softens the master hostname anti-affinity to a preference + template: charts/seaweedfs/templates/master/master-statefulset.yaml asserts: - notExists: path: spec.template.spec.affinity.podAntiAffinity.requiredDuringSchedulingIgnoredDuringExecution diff --git a/packages/system/seaweedfs/tests/master_probe_timeout_test.yaml b/packages/system/seaweedfs/tests/master_probe_timeout_test.yaml index dabcfb963..6a5d1fd9f 100644 --- a/packages/system/seaweedfs/tests/master_probe_timeout_test.yaml +++ b/packages/system/seaweedfs/tests/master_probe_timeout_test.yaml @@ -13,6 +13,7 @@ suite: seaweedfs master probe timeouts templates: - charts/seaweedfs/templates/master/master-statefulset.yaml + - charts/seaweedfs/templates/master/master-configmap.yaml release: name: seaweedfs @@ -20,6 +21,7 @@ release: tests: - it: raises both master probe timeouts above the cluster-status backoff + template: charts/seaweedfs/templates/master/master-statefulset.yaml asserts: - equal: path: spec.template.spec.containers[0].livenessProbe.timeoutSeconds @@ -29,6 +31,7 @@ tests: value: 30 - it: preserves the other master probe fields through the deep-merge + template: charts/seaweedfs/templates/master/master-statefulset.yaml asserts: # liveness: only timeoutSeconds is overridden, the rest survive - equal: diff --git a/packages/system/seaweedfs/tests/s3_catalog_ports_test.yaml b/packages/system/seaweedfs/tests/s3_catalog_ports_test.yaml index 7752e535a..37293bf1f 100644 --- a/packages/system/seaweedfs/tests/s3_catalog_ports_test.yaml +++ b/packages/system/seaweedfs/tests/s3_catalog_ports_test.yaml @@ -14,6 +14,7 @@ suite: seaweedfs s3 catalog listener ports templates: - charts/seaweedfs/templates/s3/s3-service.yaml - charts/seaweedfs/templates/s3/s3-deployment.yaml + - charts/seaweedfs/templates/s3/s3-secret.yaml release: name: seaweedfs diff --git a/packages/system/seaweedfs/tests/s3_grpc_tls_test.yaml b/packages/system/seaweedfs/tests/s3_grpc_tls_test.yaml index afac836ed..f9c6bb8f2 100644 --- a/packages/system/seaweedfs/tests/s3_grpc_tls_test.yaml +++ b/packages/system/seaweedfs/tests/s3_grpc_tls_test.yaml @@ -3,6 +3,7 @@ suite: seaweedfs s3 gRPC listener speaks mTLS templates: - charts/seaweedfs/templates/shared/security-configmap.yaml - charts/seaweedfs/templates/s3/s3-deployment.yaml + - charts/seaweedfs/templates/s3/s3-secret.yaml release: name: seaweedfs-system @@ -12,7 +13,7 @@ tests: # weed s3 serves its internal gRPC (the LifecycleDelete RPC among it) with # the [grpc.s3] identity and as plaintext without one, while the worker dials # it with [grpc.worker] mTLS credentials, so every delete failed the TLS - # handshake. patches/s3-grpc-tls.patch backports the section from upstream. + # handshake. The vendored chart carries the section since 4.46. - it: gives the s3 gRPC server a TLS identity signed by the internal CA template: charts/seaweedfs/templates/shared/security-configmap.yaml asserts: diff --git a/packages/system/seaweedfs/tests/s3_tls_cosi_sa_test.yaml b/packages/system/seaweedfs/tests/s3_tls_cosi_sa_test.yaml index 5dfff4294..13f72f161 100644 --- a/packages/system/seaweedfs/tests/s3_tls_cosi_sa_test.yaml +++ b/packages/system/seaweedfs/tests/s3_tls_cosi_sa_test.yaml @@ -19,6 +19,7 @@ suite: seaweedfs s3 TLS on main port + COSI provisioner SA name templates: - charts/seaweedfs/templates/s3/s3-deployment.yaml + - charts/seaweedfs/templates/s3/s3-secret.yaml - charts/seaweedfs/templates/cosi/cosi-deployment.yaml release: diff --git a/packages/system/seaweedfs/tests/storage_class_string_test.yaml b/packages/system/seaweedfs/tests/storage_class_string_test.yaml index 038cf1fed..be92b3467 100644 --- a/packages/system/seaweedfs/tests/storage_class_string_test.yaml +++ b/packages/system/seaweedfs/tests/storage_class_string_test.yaml @@ -7,6 +7,7 @@ suite: seaweedfs claims keep the storage class a string templates: - charts/seaweedfs/templates/master/master-statefulset.yaml + - charts/seaweedfs/templates/master/master-configmap.yaml - charts/seaweedfs/templates/filer/filer-statefulset.yaml - charts/seaweedfs/templates/volume/volume-statefulset.yaml - charts/seaweedfs/templates/admin/admin-statefulset.yaml @@ -97,6 +98,7 @@ tests: template: charts/seaweedfs/templates/admin/admin-statefulset.yaml set: seaweedfs.admin.enabled: true + seaweedfs.admin.secret.existingSecret: seaweedfs-admin-credentials seaweedfs.admin.logs: {type: persistentVolumeClaim, size: 1Gi, storageClass: "456"} asserts: - equal: @@ -107,6 +109,7 @@ tests: template: charts/seaweedfs/templates/admin/admin-statefulset.yaml set: seaweedfs.admin.enabled: true + seaweedfs.admin.secret.existingSecret: seaweedfs-admin-credentials seaweedfs.admin.logs: {type: persistentVolumeClaim, size: 1Gi} asserts: - notExists: diff --git a/packages/system/seaweedfs/tests/volume_slot_ceiling_test.yaml b/packages/system/seaweedfs/tests/volume_slot_ceiling_test.yaml index 441a45d22..443f56cfa 100644 --- a/packages/system/seaweedfs/tests/volume_slot_ceiling_test.yaml +++ b/packages/system/seaweedfs/tests/volume_slot_ceiling_test.yaml @@ -28,6 +28,7 @@ suite: seaweedfs volume slot ceiling templates: - charts/seaweedfs/templates/master/master-statefulset.yaml + - charts/seaweedfs/templates/master/master-configmap.yaml - charts/seaweedfs/templates/volume/volume-statefulset.yaml release: diff --git a/packages/system/seaweedfs/values.yaml b/packages/system/seaweedfs/values.yaml index 98b81d0ff..a2bec170f 100644 --- a/packages/system/seaweedfs/values.yaml +++ b/packages/system/seaweedfs/values.yaml @@ -207,9 +207,9 @@ seaweedfs: # weed skip startLanceServer and drops the container port and Service port # with it. lancePort: 0 - # patches/s3-grpc-tls.patch adds [grpc.s3] to security.toml, which the s3 - # pods mount by subPath and so never re-read. This annotation changes the - # pod template in the release that brings the section, so an upgrade + # The chart adds [grpc.s3] to security.toml, which the s3 pods mount by + # subPath and so never re-read. This annotation changes the pod + # template in the release that brings the section, so an upgrade # restarts s3 onto it instead of leaving its gRPC in plaintext. The # upstream s3 template carries no checksum of that ConfigMap, and adding # one would be another vendored patch for a change made once. From bdbf1ca8107e2ecd22ae7847bb06f9a485bf9cce Mon Sep 17 00:00:00 2001 From: Aleksei Sviridkin Date: Mon, 12 Oct 2026 08:05:38 +0300 Subject: [PATCH 2/4] feat(seaweedfs): backport Gateway API HTTPRoutes for s3 and filer Moving the platform's tenant ingress to Gateway API needs a route object for the S3 endpoint and the filer. Upstream added them after 4.48 and first shipped them in 4.49; this package stays on 4.48, so they arrive here as a patch that `make update` applies until the chart moves to a release that carries them. Both stay off by default, so the rendered release is unchanged; nothing is switched to Gateway API by this change. Adapted from upstream commit 68af030e381f ("helm: add Gateway API HTTPRoute for master, volume, filer, s3 and admin"): - The s3 route's default backend is `-s3` instead of componentName, the name s3-service-name.patch gives the Service. Upstream's form diverges from the real Service whenever the fullname differs from seaweedfs.name, the chart name unless nameOverride is set. - Only the s3 and filer routes and their values blocks are taken; the master, volume and admin routes, the README section and the CI workflow change are left out. With security enabled and no httpsPort, the standalone s3 gateway serves TLS on its main port (s3-tls-main-port.patch), so a Gateway sending plaintext to the default backend needs a BackendTLSPolicy alongside the route. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin --- packages/system/seaweedfs/Makefile | 1 + .../templates/filer/filer-httproute.yaml | 57 +++++ .../seaweedfs/templates/s3/s3-httproute.yaml | 64 ++++++ .../seaweedfs/charts/seaweedfs/values.yaml | 39 ++++ .../patches/httproute-backport.patch | 204 ++++++++++++++++++ .../seaweedfs/tests/httproute_test.yaml | 149 +++++++++++++ 6 files changed, 514 insertions(+) create mode 100644 packages/system/seaweedfs/charts/seaweedfs/templates/filer/filer-httproute.yaml create mode 100644 packages/system/seaweedfs/charts/seaweedfs/templates/s3/s3-httproute.yaml create mode 100644 packages/system/seaweedfs/patches/httproute-backport.patch create mode 100644 packages/system/seaweedfs/tests/httproute_test.yaml diff --git a/packages/system/seaweedfs/Makefile b/packages/system/seaweedfs/Makefile index ffac56829..76d9a92c4 100644 --- a/packages/system/seaweedfs/Makefile +++ b/packages/system/seaweedfs/Makefile @@ -62,6 +62,7 @@ update: patch --no-backup-if-mismatch -p4 < patches/s3-service-name-consumers.patch patch --no-backup-if-mismatch -p4 < patches/cluster-scoped-names-per-namespace.patch patch --forward --no-backup-if-mismatch -p4 < patches/storage-class-string.patch + patch --forward --no-backup-if-mismatch -p4 < patches/httproute-backport.patch #patch --no-backup-if-mismatch -p4 < patches/retention-policy-delete.yaml $(MAKE) update-image diff --git a/packages/system/seaweedfs/charts/seaweedfs/templates/filer/filer-httproute.yaml b/packages/system/seaweedfs/charts/seaweedfs/templates/filer/filer-httproute.yaml new file mode 100644 index 000000000..e655c1c19 --- /dev/null +++ b/packages/system/seaweedfs/charts/seaweedfs/templates/filer/filer-httproute.yaml @@ -0,0 +1,57 @@ +{{- $filerEnabled := or .Values.filer.enabled .Values.allInOne.enabled }} +{{- if and $filerEnabled .Values.filer.httpRoute.enabled }} +{{- $serviceName := ternary (include "seaweedfs.componentName" (list . "all-in-one")) (include "seaweedfs.componentName" (list . "filer")) .Values.allInOne.enabled }} +apiVersion: gateway.networking.k8s.io/v1 +kind: HTTPRoute +metadata: + name: {{ include "seaweedfs.componentName" (list . "filer") }} + namespace: {{ .Release.Namespace }} + {{- with .Values.filer.httpRoute.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} + labels: + app.kubernetes.io/name: {{ template "seaweedfs.name" . }} + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/component: filer + {{- with .Values.filer.httpRoute.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- with .Values.filer.httpRoute.parentRefs }} + parentRefs: + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with .Values.filer.httpRoute.hostnames }} + hostnames: + {{- toYaml . | nindent 4 }} + {{- end }} + rules: + {{- range .Values.filer.httpRoute.rules | default (list dict) }} + - backendRefs: + {{- with .backendRefs }} + {{- toYaml . | nindent 8 }} + {{- else }} + - group: "" + kind: Service + name: {{ $serviceName }} + namespace: {{ $.Release.Namespace }} + port: {{ $.Values.filer.port }} + weight: 1 + {{- end }} + {{- with .matches }} + matches: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .filters }} + filters: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .timeouts }} + timeouts: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- end }} +{{- end }} diff --git a/packages/system/seaweedfs/charts/seaweedfs/templates/s3/s3-httproute.yaml b/packages/system/seaweedfs/charts/seaweedfs/templates/s3/s3-httproute.yaml new file mode 100644 index 000000000..4d8afee3c --- /dev/null +++ b/packages/system/seaweedfs/charts/seaweedfs/templates/s3/s3-httproute.yaml @@ -0,0 +1,64 @@ +{{- $s3Enabled := or .Values.s3.enabled (and .Values.filer.s3.enabled (not .Values.allInOne.enabled)) (and .Values.allInOne.enabled .Values.allInOne.s3.enabled) }} +{{- if and $s3Enabled .Values.s3.httpRoute.enabled }} +{{- $serviceName := printf "%s-s3" (include "seaweedfs.name" .) }} +{{- $s3Port := .Values.filer.s3.port }} +{{- if and .Values.allInOne.enabled .Values.allInOne.s3.enabled }} +{{- $serviceName = include "seaweedfs.componentName" (list . "all-in-one") }} +{{- $s3Port = .Values.allInOne.s3.port | default .Values.s3.port }} +{{- else if .Values.s3.enabled }} +{{- $s3Port = .Values.s3.port }} +{{- end }} +apiVersion: gateway.networking.k8s.io/v1 +kind: HTTPRoute +metadata: + name: {{ include "seaweedfs.componentName" (list . "s3") }} + namespace: {{ .Release.Namespace }} + {{- with .Values.s3.httpRoute.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} + labels: + app.kubernetes.io/name: {{ template "seaweedfs.name" . }} + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/component: s3 + {{- with .Values.s3.httpRoute.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- with .Values.s3.httpRoute.parentRefs }} + parentRefs: + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with .Values.s3.httpRoute.hostnames }} + hostnames: + {{- toYaml . | nindent 4 }} + {{- end }} + rules: + {{- range .Values.s3.httpRoute.rules | default (list dict) }} + - backendRefs: + {{- with .backendRefs }} + {{- toYaml . | nindent 8 }} + {{- else }} + - group: "" + kind: Service + name: {{ $serviceName }} + namespace: {{ $.Release.Namespace }} + port: {{ $s3Port }} + weight: 1 + {{- end }} + {{- with .matches }} + matches: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .filters }} + filters: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .timeouts }} + timeouts: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- end }} +{{- end }} diff --git a/packages/system/seaweedfs/charts/seaweedfs/values.yaml b/packages/system/seaweedfs/charts/seaweedfs/values.yaml index 5b8a8c2e5..1e2c3b110 100644 --- a/packages/system/seaweedfs/charts/seaweedfs/values.yaml +++ b/packages/system/seaweedfs/charts/seaweedfs/values.yaml @@ -903,6 +903,24 @@ filer: # requires ingress-nginx to run with --enable-ssl-passthrough. tls: [] + # Gateway API HTTPRoute, an alternative to the ingress above. + httpRoute: + enabled: false + labels: {} + annotations: {} + # Gateways this route attaches to, for example: + # - group: gateway.networking.k8s.io + # kind: Gateway + # name: my-gateway + # namespace: gateway-system + # sectionName: https + parentRefs: [] + hostnames: [] + # Each rule may set matches, filters, timeouts and backendRefs. + # A rule without backendRefs routes to the filer service. + # An empty list routes all traffic there. + rules: [] + # extraEnvVars is a list of extra environment variables to set with the stateful set. extraEnvironmentVars: # the WEED_MYSQL_* keys and the db credential secret only render while this is "true" @@ -1195,6 +1213,27 @@ s3: annotations: {} tls: [] + # Gateway API HTTPRoute, an alternative to the ingress above. + # With global.seaweedfs.enableSecurity and no httpsPort, the standalone s3 + # gateway (s3.enabled) serves TLS on s3.port, so the Gateway also needs a + # BackendTLSPolicy for the s3 Service, which this chart does not render. + httpRoute: + enabled: false + labels: {} + annotations: {} + # Gateways this route attaches to, for example: + # - group: gateway.networking.k8s.io + # kind: Gateway + # name: my-gateway + # namespace: gateway-system + # sectionName: https + parentRefs: [] + hostnames: [] + # Each rule may set matches, filters, timeouts and backendRefs. + # A rule without backendRefs routes to the s3 service. + # An empty list routes all traffic there. + rules: [] + # Service settings service: type: ClusterIP diff --git a/packages/system/seaweedfs/patches/httproute-backport.patch b/packages/system/seaweedfs/patches/httproute-backport.patch new file mode 100644 index 000000000..661a07243 --- /dev/null +++ b/packages/system/seaweedfs/patches/httproute-backport.patch @@ -0,0 +1,204 @@ +Backport of the s3 and filer HTTPRoutes from upstream seaweedfs commit +68af030e381f, which no release carried when this patch was written. + +Drop this patch and its Makefile line when bumping to the first +seaweedfs release that contains 68af030e381f (expected 4.49 or later): +it creates both templates, so `make update` fails on it once upstream +ships them. Before dropping it, carry over the two deliberate +differences: the s3 route's default backendRef here targets the renamed +`-s3` Service from s3-service-name.patch, where upstream uses +componentName, so that line moves into s3-service-name-consumers.patch; +and the BackendTLSPolicy note on s3.httpRoute, which belongs with +s3-tls-main-port.patch. +Upstream's master, volume and admin routes were not backported. + +diff --git a/packages/system/seaweedfs/charts/seaweedfs/templates/filer/filer-httproute.yaml b/packages/system/seaweedfs/charts/seaweedfs/templates/filer/filer-httproute.yaml +new file mode 100644 +index 000000000..e655c1c19 +--- /dev/null ++++ b/packages/system/seaweedfs/charts/seaweedfs/templates/filer/filer-httproute.yaml +@@ -0,0 +1,57 @@ ++{{- $filerEnabled := or .Values.filer.enabled .Values.allInOne.enabled }} ++{{- if and $filerEnabled .Values.filer.httpRoute.enabled }} ++{{- $serviceName := ternary (include "seaweedfs.componentName" (list . "all-in-one")) (include "seaweedfs.componentName" (list . "filer")) .Values.allInOne.enabled }} ++apiVersion: gateway.networking.k8s.io/v1 ++kind: HTTPRoute ++metadata: ++ name: {{ include "seaweedfs.componentName" (list . "filer") }} ++ namespace: {{ .Release.Namespace }} ++ {{- with .Values.filer.httpRoute.annotations }} ++ annotations: ++ {{- toYaml . | nindent 4 }} ++ {{- end }} ++ labels: ++ app.kubernetes.io/name: {{ template "seaweedfs.name" . }} ++ helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} ++ app.kubernetes.io/managed-by: {{ .Release.Service }} ++ app.kubernetes.io/instance: {{ .Release.Name }} ++ app.kubernetes.io/component: filer ++ {{- with .Values.filer.httpRoute.labels }} ++ {{- toYaml . | nindent 4 }} ++ {{- end }} ++spec: ++ {{- with .Values.filer.httpRoute.parentRefs }} ++ parentRefs: ++ {{- toYaml . | nindent 4 }} ++ {{- end }} ++ {{- with .Values.filer.httpRoute.hostnames }} ++ hostnames: ++ {{- toYaml . | nindent 4 }} ++ {{- end }} ++ rules: ++ {{- range .Values.filer.httpRoute.rules | default (list dict) }} ++ - backendRefs: ++ {{- with .backendRefs }} ++ {{- toYaml . | nindent 8 }} ++ {{- else }} ++ - group: "" ++ kind: Service ++ name: {{ $serviceName }} ++ namespace: {{ $.Release.Namespace }} ++ port: {{ $.Values.filer.port }} ++ weight: 1 ++ {{- end }} ++ {{- with .matches }} ++ matches: ++ {{- toYaml . | nindent 8 }} ++ {{- end }} ++ {{- with .filters }} ++ filters: ++ {{- toYaml . | nindent 8 }} ++ {{- end }} ++ {{- with .timeouts }} ++ timeouts: ++ {{- toYaml . | nindent 8 }} ++ {{- end }} ++ {{- end }} ++{{- end }} +diff --git a/packages/system/seaweedfs/charts/seaweedfs/templates/s3/s3-httproute.yaml b/packages/system/seaweedfs/charts/seaweedfs/templates/s3/s3-httproute.yaml +new file mode 100644 +index 000000000..4d8afee3c +--- /dev/null ++++ b/packages/system/seaweedfs/charts/seaweedfs/templates/s3/s3-httproute.yaml +@@ -0,0 +1,64 @@ ++{{- $s3Enabled := or .Values.s3.enabled (and .Values.filer.s3.enabled (not .Values.allInOne.enabled)) (and .Values.allInOne.enabled .Values.allInOne.s3.enabled) }} ++{{- if and $s3Enabled .Values.s3.httpRoute.enabled }} ++{{- $serviceName := printf "%s-s3" (include "seaweedfs.name" .) }} ++{{- $s3Port := .Values.filer.s3.port }} ++{{- if and .Values.allInOne.enabled .Values.allInOne.s3.enabled }} ++{{- $serviceName = include "seaweedfs.componentName" (list . "all-in-one") }} ++{{- $s3Port = .Values.allInOne.s3.port | default .Values.s3.port }} ++{{- else if .Values.s3.enabled }} ++{{- $s3Port = .Values.s3.port }} ++{{- end }} ++apiVersion: gateway.networking.k8s.io/v1 ++kind: HTTPRoute ++metadata: ++ name: {{ include "seaweedfs.componentName" (list . "s3") }} ++ namespace: {{ .Release.Namespace }} ++ {{- with .Values.s3.httpRoute.annotations }} ++ annotations: ++ {{- toYaml . | nindent 4 }} ++ {{- end }} ++ labels: ++ app.kubernetes.io/name: {{ template "seaweedfs.name" . }} ++ helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} ++ app.kubernetes.io/managed-by: {{ .Release.Service }} ++ app.kubernetes.io/instance: {{ .Release.Name }} ++ app.kubernetes.io/component: s3 ++ {{- with .Values.s3.httpRoute.labels }} ++ {{- toYaml . | nindent 4 }} ++ {{- end }} ++spec: ++ {{- with .Values.s3.httpRoute.parentRefs }} ++ parentRefs: ++ {{- toYaml . | nindent 4 }} ++ {{- end }} ++ {{- with .Values.s3.httpRoute.hostnames }} ++ hostnames: ++ {{- toYaml . | nindent 4 }} ++ {{- end }} ++ rules: ++ {{- range .Values.s3.httpRoute.rules | default (list dict) }} ++ - backendRefs: ++ {{- with .backendRefs }} ++ {{- toYaml . | nindent 8 }} ++ {{- else }} ++ - group: "" ++ kind: Service ++ name: {{ $serviceName }} ++ namespace: {{ $.Release.Namespace }} ++ port: {{ $s3Port }} ++ weight: 1 ++ {{- end }} ++ {{- with .matches }} ++ matches: ++ {{- toYaml . | nindent 8 }} ++ {{- end }} ++ {{- with .filters }} ++ filters: ++ {{- toYaml . | nindent 8 }} ++ {{- end }} ++ {{- with .timeouts }} ++ timeouts: ++ {{- toYaml . | nindent 8 }} ++ {{- end }} ++ {{- end }} ++{{- end }} +diff --git a/packages/system/seaweedfs/charts/seaweedfs/values.yaml b/packages/system/seaweedfs/charts/seaweedfs/values.yaml +index 5b8a8c2e5..3a188323b 100644 +--- a/packages/system/seaweedfs/charts/seaweedfs/values.yaml ++++ b/packages/system/seaweedfs/charts/seaweedfs/values.yaml +@@ -903,6 +903,24 @@ filer: + # requires ingress-nginx to run with --enable-ssl-passthrough. + tls: [] + ++ # Gateway API HTTPRoute, an alternative to the ingress above. ++ httpRoute: ++ enabled: false ++ labels: {} ++ annotations: {} ++ # Gateways this route attaches to, for example: ++ # - group: gateway.networking.k8s.io ++ # kind: Gateway ++ # name: my-gateway ++ # namespace: gateway-system ++ # sectionName: https ++ parentRefs: [] ++ hostnames: [] ++ # Each rule may set matches, filters, timeouts and backendRefs. ++ # A rule without backendRefs routes to the filer service. ++ # An empty list routes all traffic there. ++ rules: [] ++ + # extraEnvVars is a list of extra environment variables to set with the stateful set. + extraEnvironmentVars: + # the WEED_MYSQL_* keys and the db credential secret only render while this is "true" +@@ -1195,6 +1213,27 @@ s3: + annotations: {} + tls: [] + ++ # Gateway API HTTPRoute, an alternative to the ingress above. ++ # With global.seaweedfs.enableSecurity and no httpsPort, the standalone s3 ++ # gateway (s3.enabled) serves TLS on s3.port, so the Gateway also needs a ++ # BackendTLSPolicy for the s3 Service, which this chart does not render. ++ httpRoute: ++ enabled: false ++ labels: {} ++ annotations: {} ++ # Gateways this route attaches to, for example: ++ # - group: gateway.networking.k8s.io ++ # kind: Gateway ++ # name: my-gateway ++ # namespace: gateway-system ++ # sectionName: https ++ parentRefs: [] ++ hostnames: [] ++ # Each rule may set matches, filters, timeouts and backendRefs. ++ # A rule without backendRefs routes to the s3 service. ++ # An empty list routes all traffic there. ++ rules: [] ++ + # Service settings + service: + type: ClusterIP diff --git a/packages/system/seaweedfs/tests/httproute_test.yaml b/packages/system/seaweedfs/tests/httproute_test.yaml new file mode 100644 index 000000000..5998298f1 --- /dev/null +++ b/packages/system/seaweedfs/tests/httproute_test.yaml @@ -0,0 +1,149 @@ +suite: seaweedfs Gateway API HTTPRoutes + +# The routes come from patches/httproute-backport.patch. Its s3 route names +# the backend -s3, as s3-service-name.patch names the Service. Upstream +# uses componentName (-s3) there, which renders the same name while +# fullnameOverride equals the chart name, so the routing cases override it to +# make upstream's form render a different name and fail. + +templates: + - charts/seaweedfs/templates/s3/s3-httproute.yaml + - charts/seaweedfs/templates/s3/s3-service.yaml + - charts/seaweedfs/templates/filer/filer-httproute.yaml + - charts/seaweedfs/templates/filer/filer-service.yaml + +release: + name: seaweedfs-system + namespace: cozy-seaweedfs + +tests: + - it: renders no s3 route by default + template: charts/seaweedfs/templates/s3/s3-httproute.yaml + asserts: + - hasDocuments: + count: 0 + + - it: renders no filer route by default + template: charts/seaweedfs/templates/filer/filer-httproute.yaml + asserts: + - hasDocuments: + count: 0 + + - it: s3 route targets the renamed s3 service on the s3 port + template: charts/seaweedfs/templates/s3/s3-httproute.yaml + set: + seaweedfs.fullnameOverride: seaweedfs-system + seaweedfs.filer.s3.port: 8334 + seaweedfs.s3.httpRoute.enabled: true + seaweedfs.s3.httpRoute.parentRefs: + - name: gw + namespace: gateway-system + seaweedfs.s3.httpRoute.hostnames: + - s3.example.com + asserts: + - isKind: + of: HTTPRoute + - equal: + path: spec.rules[0].backendRefs[0].name + value: seaweedfs-s3 + - equal: + path: spec.rules[0].backendRefs[0].port + value: 8333 + - equal: + path: spec.parentRefs[0].name + value: gw + - equal: + path: spec.hostnames[0] + value: s3.example.com + + - it: the s3 service it targets is the one the chart renders + template: charts/seaweedfs/templates/s3/s3-service.yaml + set: + seaweedfs.fullnameOverride: seaweedfs-system + asserts: + - equal: + path: metadata.name + value: seaweedfs-s3 + + - it: s3 route on a filer-embedded gateway targets the renamed service on the filer s3 port + template: charts/seaweedfs/templates/s3/s3-httproute.yaml + set: + seaweedfs.fullnameOverride: seaweedfs-system + seaweedfs.s3.enabled: false + seaweedfs.filer.s3.enabled: true + seaweedfs.filer.s3.port: 8334 + seaweedfs.s3.httpRoute.enabled: true + asserts: + - equal: + path: spec.rules[0].backendRefs[0].name + value: seaweedfs-s3 + - equal: + path: spec.rules[0].backendRefs[0].port + value: 8334 + + - it: filer route targets the filer service on the filer port + template: charts/seaweedfs/templates/filer/filer-httproute.yaml + set: + seaweedfs.fullnameOverride: seaweedfs-system + seaweedfs.filer.httpRoute.enabled: true + asserts: + - isKind: + of: HTTPRoute + - equal: + path: spec.rules[0].backendRefs[0].name + value: seaweedfs-system-filer + - equal: + path: spec.rules[0].backendRefs[0].port + value: 8888 + + - it: the filer service it targets is the one the chart renders + template: charts/seaweedfs/templates/filer/filer-service.yaml + set: + seaweedfs.fullnameOverride: seaweedfs-system + asserts: + - equal: + path: metadata.name + value: seaweedfs-system-filer + + - it: an s3 rule without backendRefs keeps its matches and routes to the s3 service + template: charts/seaweedfs/templates/s3/s3-httproute.yaml + set: + seaweedfs.fullnameOverride: seaweedfs-system + seaweedfs.s3.httpRoute.enabled: true + seaweedfs.s3.httpRoute.rules: + - matches: + - path: + type: PathPrefix + value: /bucket + asserts: + - lengthEqual: + path: spec.rules + count: 1 + - equal: + path: spec.rules[0].matches[0].path.value + value: /bucket + - equal: + path: spec.rules[0].backendRefs + value: + - group: "" + kind: Service + name: seaweedfs-s3 + namespace: cozy-seaweedfs + port: 8333 + weight: 1 + + - it: an empty s3 rule list renders one catch-all rule to the s3 service + template: charts/seaweedfs/templates/s3/s3-httproute.yaml + set: + seaweedfs.fullnameOverride: seaweedfs-system + seaweedfs.s3.httpRoute.enabled: true + seaweedfs.s3.httpRoute.rules: [] + asserts: + - lengthEqual: + path: spec.rules + count: 1 + - notExists: + path: spec.rules[0].matches + - equal: + path: spec.rules[0].backendRefs[0].name + value: seaweedfs-s3 From fe21a46b63b7dbde8cebbe5c78c01052f222ca6b Mon Sep 17 00:00:00 2001 From: Aleksei Sviridkin Date: Fri, 13 Nov 2026 00:01:24 +0300 Subject: [PATCH 3/4] build(seaweedfs): stamp the re-pinned in-tree image The in-tree image now builds SeaweedFS 4.48, so values.yaml has to name that build for the components to run the binary that matches the chart. The digest comes from the CI build of this change; the public registry serves it once the release mirror copies it, and release preparation restamps first-party references in any case. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin --- packages/system/seaweedfs/values.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/system/seaweedfs/values.yaml b/packages/system/seaweedfs/values.yaml index a2bec170f..609e305b4 100644 --- a/packages/system/seaweedfs/values.yaml +++ b/packages/system/seaweedfs/values.yaml @@ -31,7 +31,7 @@ seaweedfs: # `make image` rewrites both keys on every build. image: repository: "ghcr.io/cozystack/cozystack/seaweedfs" - tag: "4.45@sha256:2a063deb9992ac0c06f8c09589ae063a30ac8c87af2c6aa1f4d4420cc544535c" + tag: "4.48@sha256:5360a02bbf1156947a7bae64182cfcc14d03aa67ab4499859721a87fabe580ca" master: # At the shipped replicationFactor of 2 the size limit and # extraEnvironmentVars.WEED_MASTER_VOLUME_GROWTH_COPY_2 below are one From b9266a4a1e17e2fb521b530a7da144e447325c9e Mon Sep 17 00:00:00 2001 From: Aleksei Sviridkin Date: Wed, 18 Nov 2026 04:37:59 +0300 Subject: [PATCH 4/4] fix(seaweedfs): preserve peer discovery across metadata startup Peer changes received during initialization were lost before the metadata consumer attached. Gateways could then remain subscribed to a single filer and reject credentials written through its peer. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin --- .../seaweedfs/images/seaweedfs/Dockerfile | 3 + .../patches/peer-membership-handoff.diff | 631 ++++++++++++++++++ 2 files changed, 634 insertions(+) create mode 100644 packages/system/seaweedfs/images/seaweedfs/patches/peer-membership-handoff.diff diff --git a/packages/system/seaweedfs/images/seaweedfs/Dockerfile b/packages/system/seaweedfs/images/seaweedfs/Dockerfile index 8e942ee97..cb72066df 100644 --- a/packages/system/seaweedfs/images/seaweedfs/Dockerfile +++ b/packages/system/seaweedfs/images/seaweedfs/Dockerfile @@ -16,6 +16,9 @@ # seaweedfs/seaweedfs#11674 after 4.48; drop the patch on the first vendored # release that carries it. # +# patches/peer-membership-handoff.diff prevents a startup peer-discovery gap +# from leaving S3 gateways subscribed to only one filer's metadata changes. +# # `make update` re-pins VERSION from the vendored chart, SOURCE_SHA256 from the # source archive of that tag, UPSTREAM_DIGEST from the upstream image of that # tag and the builder from upstream's docker/Dockerfile.go_build, and checks diff --git a/packages/system/seaweedfs/images/seaweedfs/patches/peer-membership-handoff.diff b/packages/system/seaweedfs/images/seaweedfs/patches/peer-membership-handoff.diff new file mode 100644 index 000000000..d9e09c444 --- /dev/null +++ b/packages/system/seaweedfs/images/seaweedfs/patches/peer-membership-handoff.diff @@ -0,0 +1,631 @@ +diff --git a/weed/filer/filer.go b/weed/filer/filer.go +index d83486c..a48c9df 100644 +--- a/weed/filer/filer.go ++++ b/weed/filer/filer.go +@@ -165,14 +165,6 @@ func (f *Filer) AggregateFromPeers(self pb.ServerAddress, existingNodes []*maste + // The ring starts empty while peer history sits on disk: mark the pre-startFrom + // range evicted so a cursor there reads disk, not the ring's earliest entry. + f.MetaAggregator.MetaLogBuffer.MarkEvictedThrough(startFrom.UnixNano()) +- f.MasterClient.SetOnPeerUpdateFn(func(update *master_pb.ClusterNodeUpdate, startFrom time.Time) { +- if update.NodeType != cluster.FilerType { +- return +- } +- // Lock ring is now managed by the master via LockRingUpdate, +- // so we no longer call AddServer/RemoveServer here. +- f.MetaAggregator.OnPeerUpdate(update, startFrom) +- }) + f.MasterClient.SetOnLockRingUpdateFn(func(update *master_pb.LockRingUpdate) { + var servers []pb.ServerAddress + for _, s := range update.Servers { +@@ -186,19 +178,31 @@ func (f *Filer) AggregateFromPeers(self pb.ServerAddress, existingNodes []*maste + f.Dlm.LockRing.Reset() + }) + +- // Subscribe to the local filer first: its events reach the aggregated +- // buffer only through this subscription, and the peer watermarks must +- // account for it before any remote peer - a remotes-only watermark set +- // would claim completeness without self. existingNodes can omit self +- // (master registration races this bootstrap); duplicate adds are no-ops. ++ // Remote-only watermarks could claim completeness without the local merge source. + f.MetaAggregator.OnPeerUpdate(&master_pb.ClusterNodeUpdate{ + NodeType: cluster.FilerType, + Address: string(self), + IsAdd: true, + }, startFrom) +- for _, peerUpdate := range existingNodes { +- f.MetaAggregator.OnPeerUpdate(peerUpdate, startFrom) ++ initialPeers := make(map[string]struct{}, len(existingNodes)) ++ for _, peer := range existingNodes { ++ initialPeers[pb.ServerAddress(peer.Address).ToHttpAddress()] = struct{}{} + } ++ // The bootstrap snapshot can predate a streamed removal; use the stream's retained state. ++ f.MasterClient.SetOnPeerUpdateFn(func(update *master_pb.ClusterNodeUpdate, observedAt time.Time) { ++ if update.NodeType != cluster.FilerType { ++ return ++ } ++ address := pb.ServerAddress(update.Address).ToHttpAddress() ++ if _, initial := initialPeers[address]; initial { ++ delete(initialPeers, address) ++ // A delayed initial ADD must not skip the bootstrap replay window. ++ if update.IsAdd && startFrom.Before(observedAt) { ++ observedAt = startFrom ++ } ++ } ++ f.MetaAggregator.OnPeerUpdate(update, observedAt) ++ }) + + } + +diff --git a/weed/filer/peer_discovery_gap_test.go b/weed/filer/peer_discovery_gap_test.go +new file mode 100644 +index 0000000..4c70b40 +--- /dev/null ++++ b/weed/filer/peer_discovery_gap_test.go +@@ -0,0 +1,184 @@ ++package filer ++ ++import ( ++ "context" ++ "net" ++ "testing" ++ "time" ++ ++ "github.com/seaweedfs/seaweedfs/weed/cluster" ++ "github.com/seaweedfs/seaweedfs/weed/cluster/lock_manager" ++ "github.com/seaweedfs/seaweedfs/weed/pb" ++ "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb" ++ "github.com/seaweedfs/seaweedfs/weed/pb/master_pb" ++ "github.com/seaweedfs/seaweedfs/weed/wdclient" ++ "google.golang.org/grpc" ++ "google.golang.org/grpc/credentials/insecure" ++) ++ ++type discoveryGapMaster struct { ++ master_pb.UnimplementedSeaweedServer ++ self pb.ServerAddress ++ peer pb.ServerAddress ++ announce chan struct{} ++ snapshotHasPeer bool ++ events []bool ++ delayInitial bool ++} ++ ++func (s *discoveryGapMaster) KeepConnected(stream master_pb.Seaweed_KeepConnectedServer) error { ++ if _, err := stream.Recv(); err != nil { ++ return err ++ } ++ if err := stream.Send(&master_pb.KeepConnectedResponse{VolumeLocation: &master_pb.VolumeLocation{Leader: string(s.self)}}); err != nil { ++ return err ++ } ++ initial := []pb.ServerAddress{s.self} ++ if s.snapshotHasPeer && !s.delayInitial { ++ initial = append(initial, s.peer) ++ } ++ for _, address := range initial { ++ if err := stream.Send(&master_pb.KeepConnectedResponse{ClusterNodeUpdate: &master_pb.ClusterNodeUpdate{NodeType: cluster.FilerType, Address: string(address), IsAdd: true}}); err != nil { ++ return err ++ } ++ } ++ select { ++ case <-s.announce: ++ case <-stream.Context().Done(): ++ return stream.Context().Err() ++ } ++ for _, add := range s.events { ++ if err := stream.Send(&master_pb.KeepConnectedResponse{ClusterNodeUpdate: &master_pb.ClusterNodeUpdate{NodeType: cluster.FilerType, Address: string(s.peer), IsAdd: add}}); err != nil { ++ return err ++ } ++ } ++ if err := stream.Send(&master_pb.KeepConnectedResponse{LockRingUpdate: &master_pb.LockRingUpdate{Version: 1}}); err != nil { ++ return err ++ } ++ <-stream.Context().Done() ++ return stream.Context().Err() ++} ++ ++func (s *discoveryGapMaster) ListClusterNodes(context.Context, *master_pb.ListClusterNodesRequest) (*master_pb.ListClusterNodesResponse, error) { ++ nodes := []*master_pb.ListClusterNodesResponse_ClusterNode{{Address: string(s.self)}} ++ if s.snapshotHasPeer { ++ nodes = append(nodes, &master_pb.ListClusterNodesResponse_ClusterNode{Address: string(s.peer)}) ++ } ++ return &master_pb.ListClusterNodesResponse{ClusterNodes: nodes}, nil ++} ++ ++type discoveryGapFiler struct { ++ filer_pb.UnimplementedSeaweedFilerServer ++ subscriptions chan int64 ++} ++ ++func (*discoveryGapFiler) GetFilerConfiguration(context.Context, *filer_pb.GetFilerConfigurationRequest) (*filer_pb.GetFilerConfigurationResponse, error) { ++ return &filer_pb.GetFilerConfigurationResponse{Signature: 41}, nil ++} ++func (s *discoveryGapFiler) SubscribeLocalMetadata(req *filer_pb.SubscribeMetadataRequest, stream filer_pb.SeaweedFiler_SubscribeLocalMetadataServer) error { ++ s.subscriptions <- req.SinceNs ++ <-stream.Context().Done() ++ return stream.Context().Err() ++} ++ ++func TestPeerDiscoveryAcrossAggregatorInitialization(t *testing.T) { ++ cases := []struct { ++ name string ++ before bool ++ snapshotHasPeer bool ++ events []bool ++ wantPeer bool ++ cursor bool ++ }{ ++ {"pre_init_add", true, false, []bool{true}, true, false}, ++ {"pre_init_remove", true, true, []bool{false}, false, false}, ++ {"pre_init_add_remove", true, false, []bool{true, false}, false, false}, ++ {"pre_init_remove_add", true, true, []bool{false, true}, true, false}, ++ {"post_init_add", false, false, []bool{true}, true, false}, ++ {"post_init_remove", false, true, []bool{false}, false, false}, ++ {"delayed_initial_add_replay_cursor", false, true, []bool{true}, true, true}, ++ } ++ for _, tc := range cases { ++ t.Run(tc.name, func(t *testing.T) { ++ ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) ++ defer cancel() ++ listener, err := net.Listen("tcp", "127.0.0.1:0") ++ if err != nil { ++ t.Fatal(err) ++ } ++ _, port, err := net.SplitHostPort(listener.Addr().String()) ++ if err != nil { ++ t.Fatal(err) ++ } ++ self := pb.ServerAddress("127.0.0.1:0." + port) ++ peer := pb.ServerAddress("localhost:0." + port) ++ master := &discoveryGapMaster{self: self, peer: peer, announce: make(chan struct{}), snapshotHasPeer: tc.snapshotHasPeer, events: tc.events, delayInitial: tc.cursor} ++ server := grpc.NewServer() ++ master_pb.RegisterSeaweedServer(server, master) ++ subscriptions := make(chan int64, 16) ++ filer_pb.RegisterSeaweedFilerServer(server, &discoveryGapFiler{subscriptions: subscriptions}) ++ go server.Serve(listener) ++ defer server.Stop() ++ dial := grpc.WithTransportCredentials(insecure.NewCredentials()) ++ mc := wdclient.NewMasterClient(dial, "", cluster.FilerType, self, "", "", *pb.NewServiceDiscoveryFromMap(map[string]pb.ServerAddress{"master": self})) ++ go mc.KeepConnectedToMaster(ctx) ++ f := &Filer{MasterClient: mc, GrpcDialOption: dial, Signature: 41, Dlm: lock_manager.NewDistributedLockManager(self)} ++ snapshot := f.ListExistingPeerUpdates(ctx) ++ wantSize := 1 ++ if tc.snapshotHasPeer { ++ wantSize++ ++ } ++ if len(snapshot) != wantSize { ++ t.Fatalf("snapshot = %v, want %d nodes", snapshot, wantSize) ++ } ++ if mc.OnPeerUpdate != nil { ++ t.Fatal("unexpected peer callback before initialization") ++ } ++ dispatched := make(chan struct{}) ++ barrier := func(*master_pb.LockRingUpdate) { close(dispatched) } ++ await := func() { ++ select { ++ case <-dispatched: ++ case <-ctx.Done(): ++ t.Fatal("master dispatch barrier not reached") ++ } ++ } ++ if tc.before { ++ mc.SetOnLockRingUpdateFn(barrier) ++ close(master.announce) ++ await() ++ t.Log("membership events passed through real MasterClient dispatch while OnPeerUpdate was nil") ++ } ++ replayFrom := time.Now().Add(-time.Minute) ++ f.AggregateFromPeers(self, snapshot, replayFrom) ++ defer func() { ++ f.MetaAggregator.OnPeerUpdate(&master_pb.ClusterNodeUpdate{Address: string(self)}, time.Now()) ++ f.MetaAggregator.OnPeerUpdate(&master_pb.ClusterNodeUpdate{Address: string(peer)}, time.Now()) ++ f.MetaAggregator.MetaLogBuffer.ShutdownLogBuffer() ++ }() ++ if mc.OnPeerUpdate == nil { ++ t.Fatal("initialization did not install callback") ++ } ++ if !tc.before { ++ mc.SetOnLockRingUpdateFn(barrier) ++ close(master.announce) ++ await() ++ } ++ if tc.cursor { ++ for range 2 { ++ select { ++ case since := <-subscriptions: ++ if since > replayFrom.UnixNano() { ++ t.Errorf("initial peer replay starts at %d, after bootstrap overlap %d", since, replayFrom.UnixNano()) ++ } ++ case <-ctx.Done(): ++ t.Fatal("metadata subscription not started") ++ } ++ } ++ } ++ if got := f.MetaAggregator.HasRemotePeers(); got != tc.wantPeer { ++ t.Fatalf("remote peer membership = %t, want %t after events %v", got, tc.wantPeer, tc.events) ++ } ++ }) ++ } ++} +diff --git a/weed/wdclient/masterclient.go b/weed/wdclient/masterclient.go +index 6d638b6..9f16364 100644 +--- a/weed/wdclient/masterclient.go ++++ b/weed/wdclient/masterclient.go +@@ -142,6 +142,16 @@ func (p *masterVolumeProvider) LookupVolumeIds(ctx context.Context, volumeIds [] + + // MasterClient connects to master servers and maintains volume location cache + // It receives real-time updates via KeepConnected streaming and uses vidMapClient for caching ++type peerUpdateKey struct { ++ nodeType string ++ address string ++} ++ ++type pendingPeerUpdate struct { ++ update *master_pb.ClusterNodeUpdate ++ startFrom time.Time ++} ++ + type MasterClient struct { + *vidMapClient // Embedded cache with shared logic + +@@ -157,6 +167,7 @@ type MasterClient struct { + grpcTimeout time.Duration // Timeout for gRPC calls to master + OnPeerUpdate func(update *master_pb.ClusterNodeUpdate, startFrom time.Time) + OnPeerUpdateLock sync.RWMutex ++ pendingPeerUpdates map[peerUpdateKey]pendingPeerUpdate + OnLockRingUpdate func(update *master_pb.LockRingUpdate) + OnLockRingUpdateLock sync.RWMutex + OnMasterChange func(previous, current pb.ServerAddress) +@@ -185,8 +196,58 @@ func NewMasterClient(grpcDialOption grpc.DialOption, filerGroup string, clientTy + + func (mc *MasterClient) SetOnPeerUpdateFn(onPeerUpdate func(update *master_pb.ClusterNodeUpdate, startFrom time.Time)) { + mc.OnPeerUpdateLock.Lock() +- mc.OnPeerUpdate = onPeerUpdate ++ if onPeerUpdate == nil || len(mc.pendingPeerUpdates) == 0 { ++ if onPeerUpdate != nil { ++ mc.pendingPeerUpdates = nil ++ } ++ mc.OnPeerUpdate = onPeerUpdate ++ mc.OnPeerUpdateLock.Unlock() ++ return ++ } ++ pending := mc.pendingPeerUpdates ++ mc.pendingPeerUpdates = nil ++ // Retained state must precede concurrently arriving live events. ++ replayed := make(chan struct{}) ++ mc.OnPeerUpdate = func(update *master_pb.ClusterNodeUpdate, startFrom time.Time) { ++ <-replayed ++ onPeerUpdate(update, startFrom) ++ } + mc.OnPeerUpdateLock.Unlock() ++ defer close(replayed) ++ for _, peer := range pending { ++ onPeerUpdate(peer.update, peer.startFrom) ++ } ++} ++ ++func (mc *MasterClient) dispatchPeerUpdate(update *master_pb.ClusterNodeUpdate) { ++ if update.FilerGroup != mc.FilerGroup { ++ return ++ } ++ startFrom := time.Now() ++ mc.OnPeerUpdateLock.Lock() ++ callback := mc.OnPeerUpdate ++ if callback == nil { ++ key := peerUpdateKey{nodeType: update.NodeType, address: update.Address} ++ if update.IsAdd { ++ if mc.pendingPeerUpdates == nil { ++ mc.pendingPeerUpdates = make(map[peerUpdateKey]pendingPeerUpdate) ++ } ++ mc.pendingPeerUpdates[key] = pendingPeerUpdate{update: update, startFrom: startFrom} ++ } else { ++ delete(mc.pendingPeerUpdates, key) ++ } ++ } ++ mc.OnPeerUpdateLock.Unlock() ++ if callback == nil { ++ return ++ } ++ if update.IsAdd { ++ glog.V(0).Infof("+ %s@%s noticed %s.%s %s", mc.clientType, mc.clientHost, update.FilerGroup, update.NodeType, update.Address) ++ } else { ++ glog.V(0).Infof("- %s@%s noticed %s.%s %s", mc.clientType, mc.clientHost, update.FilerGroup, update.NodeType, update.Address) ++ } ++ stats.MasterClientConnectCounter.WithLabelValues(stats.OnPeerUpdate).Inc() ++ callback(update, startFrom) + } + + func (mc *MasterClient) SetOnLockRingUpdateFn(fn func(update *master_pb.LockRingUpdate)) { +@@ -289,6 +350,14 @@ func (mc *MasterClient) tryConnectToMaster(ctx context.Context, master pb.Server + // Still need to reset cache to ensure we don't use stale data from previous master + mc.resetVidMap() + } ++ // Retained peers are valid only while this stream lives: the next ++ // stream lists just its current members and never reports removals ++ // made before it connected. ++ defer func() { ++ mc.OnPeerUpdateLock.Lock() ++ mc.pendingPeerUpdates = nil ++ mc.OnPeerUpdateLock.Unlock() ++ }() + if previous := mc.markServingMaster(master); previous != "" { + mc.OnMasterChangeLock.RLock() + if mc.OnMasterChange != nil { +@@ -323,20 +392,7 @@ func (mc *MasterClient) tryConnectToMaster(ctx context.Context, master pb.Server + mc.updateVidMap(resp) + } + if resp.ClusterNodeUpdate != nil { +- update := resp.ClusterNodeUpdate +- mc.OnPeerUpdateLock.RLock() +- if mc.OnPeerUpdate != nil { +- if update.FilerGroup == mc.FilerGroup { +- if update.IsAdd { +- glog.V(0).Infof("+ %s@%s noticed %s.%s %s\n", mc.clientType, mc.clientHost, update.FilerGroup, update.NodeType, update.Address) +- } else { +- glog.V(0).Infof("- %s@%s noticed %s.%s %s\n", mc.clientType, mc.clientHost, update.FilerGroup, update.NodeType, update.Address) +- } +- stats.MasterClientConnectCounter.WithLabelValues(stats.OnPeerUpdate).Inc() +- mc.OnPeerUpdate(update, time.Now()) +- } +- } +- mc.OnPeerUpdateLock.RUnlock() ++ mc.dispatchPeerUpdate(resp.ClusterNodeUpdate) + } + if resp.LockRingUpdate != nil { + update := resp.LockRingUpdate +diff --git a/weed/wdclient/masterclient_peer_handoff_test.go b/weed/wdclient/masterclient_peer_handoff_test.go +new file mode 100644 +index 0000000..38730ec +--- /dev/null ++++ b/weed/wdclient/masterclient_peer_handoff_test.go +@@ -0,0 +1,99 @@ ++package wdclient ++ ++import ( ++ "reflect" ++ "sync" ++ "testing" ++ "testing/synctest" ++ "time" ++ ++ "github.com/seaweedfs/seaweedfs/weed/pb/master_pb" ++) ++ ++func TestPeerUpdateHandoffRetainsActiveState(t *testing.T) { ++ mc := &MasterClient{FilerGroup: "test"} ++ event := func(kind, address, group string, add bool) *master_pb.ClusterNodeUpdate { ++ return &master_pb.ClusterNodeUpdate{NodeType: kind, Address: address, FilerGroup: group, IsAdd: add} ++ } ++ for i := 0; i < 100; i++ { ++ mc.dispatchPeerUpdate(event("filer", "gone:8888", "test", true)) ++ mc.dispatchPeerUpdate(event("filer", "gone:8888", "test", false)) ++ } ++ mc.dispatchPeerUpdate(event("filer", "keep:8888", "test", true)) ++ mc.dispatchPeerUpdate(event("s3", "keep:8888", "test", true)) ++ mc.dispatchPeerUpdate(event("filer", "foreign:8888", "other", true)) ++ if len(mc.pendingPeerUpdates) != 2 { ++ t.Fatalf("retained entries = %d, want two active peer keys", len(mc.pendingPeerUpdates)) ++ } ++ got := make(map[string]bool) ++ mc.SetOnPeerUpdateFn(func(update *master_pb.ClusterNodeUpdate, _ time.Time) { ++ got[update.NodeType+"/"+update.Address] = true ++ }) ++ want := map[string]bool{"filer/keep:8888": true, "s3/keep:8888": true} ++ if !reflect.DeepEqual(got, want) { ++ t.Fatalf("handoff = %v, want %v", got, want) ++ } ++ if len(mc.pendingPeerUpdates) != 0 { ++ t.Fatal("handoff retained state after consumer installation") ++ } ++} ++ ++func TestPeerUpdateHandoffOrdersConcurrentDispatch(t *testing.T) { ++ synctest.Test(t, func(t *testing.T) { ++ mc := &MasterClient{} ++ add := &master_pb.ClusterNodeUpdate{NodeType: "filer", Address: "peer:8888", IsAdd: true} ++ remove := &master_pb.ClusterNodeUpdate{NodeType: "filer", Address: "peer:8888"} ++ mc.dispatchPeerUpdate(add) ++ replayEntered := make(chan struct{}) ++ releaseReplay := make(chan struct{}) ++ callbackReturned := make(chan struct{}) ++ var got []bool ++ var mu sync.Mutex ++ var wg sync.WaitGroup ++ wg.Add(1) ++ go func() { ++ defer wg.Done() ++ mc.SetOnPeerUpdateFn(func(update *master_pb.ClusterNodeUpdate, _ time.Time) { ++ if update.IsAdd { ++ close(replayEntered) ++ <-releaseReplay ++ } ++ mu.Lock() ++ got = append(got, update.IsAdd) ++ mu.Unlock() ++ }) ++ }() ++ <-replayEntered ++ wg.Add(1) ++ go func() { ++ defer wg.Done() ++ mc.dispatchPeerUpdate(remove) ++ close(callbackReturned) ++ }() ++ synctest.Wait() ++ mu.Lock() ++ early := len(got) ++ mu.Unlock() ++ if early != 0 { ++ t.Errorf("live callback overtook retained-state replay: %d callbacks", early) ++ } ++ close(releaseReplay) ++ wg.Wait() ++ <-callbackReturned ++ if !reflect.DeepEqual(got, []bool{true, false}) { ++ t.Fatalf("callback order = %v, want ADD then REMOVE", got) ++ } ++ }) ++} ++ ++func TestPeerUpdateHandoffCallbackRunsOutsideStateLock(t *testing.T) { ++ mc := &MasterClient{} ++ mc.dispatchPeerUpdate(&master_pb.ClusterNodeUpdate{NodeType: "filer", Address: "peer:8888", IsAdd: true}) ++ mc.SetOnPeerUpdateFn(func(*master_pb.ClusterNodeUpdate, time.Time) { ++ if !mc.OnPeerUpdateLock.TryLock() { ++ t.Fatal("callback invoked with state lock held") ++ } ++ mc.OnPeerUpdateLock.Unlock() ++ }) ++ mc.dispatchPeerUpdate(&master_pb.ClusterNodeUpdate{NodeType: "filer", Address: "peer:8888"}) ++} +diff --git a/weed/wdclient/masterclient_peer_reconnect_test.go b/weed/wdclient/masterclient_peer_reconnect_test.go +new file mode 100644 +index 0000000..70efe0f +--- /dev/null ++++ b/weed/wdclient/masterclient_peer_reconnect_test.go +@@ -0,0 +1,146 @@ ++package wdclient ++ ++import ( ++ "context" ++ "sync/atomic" ++ "testing" ++ "time" ++ ++ "github.com/seaweedfs/seaweedfs/weed/pb" ++ "github.com/seaweedfs/seaweedfs/weed/pb/master_pb" ++ "google.golang.org/grpc" ++ "google.golang.org/grpc/codes" ++ "google.golang.org/grpc/credentials/insecure" ++ "google.golang.org/grpc/status" ++) ++ ++type peerReconnectMaster struct { ++ master_pb.UnimplementedSeaweedServer ++ address pb.ServerAddress ++ streams [][]string ++ connections atomic.Int32 ++} ++ ++func (s *peerReconnectMaster) KeepConnected(stream master_pb.Seaweed_KeepConnectedServer) error { ++ if _, err := stream.Recv(); err != nil { ++ return err ++ } ++ n := s.connections.Add(1) ++ if err := stream.Send(&master_pb.KeepConnectedResponse{VolumeLocation: &master_pb.VolumeLocation{Leader: string(s.address)}}); err != nil { ++ return err ++ } ++ for _, address := range s.streams[min(int(n), len(s.streams))-1] { ++ if err := stream.Send(&master_pb.KeepConnectedResponse{ClusterNodeUpdate: &master_pb.ClusterNodeUpdate{NodeType: "filer", Address: address, IsAdd: true}}); err != nil { ++ return err ++ } ++ } ++ if n == 1 { ++ return status.Error(codes.Unavailable, "reconnect") ++ } ++ if err := stream.Send(&master_pb.KeepConnectedResponse{LockRingUpdate: &master_pb.LockRingUpdate{Version: 2}}); err != nil { ++ return err ++ } ++ <-stream.Context().Done() ++ return stream.Context().Err() ++} ++ ++func TestPeerUpdateHandoffReconnectInitialAdds(t *testing.T) { ++ server := &peerReconnectMaster{streams: [][]string{{"peer-a:8888"}, {"peer-a:8888", "peer-b:8888"}}} ++ server.address = startFakeMasterServer(t, server) ++ mc := NewMasterClient(grpc.WithTransportCredentials(insecure.NewCredentials()), "", "filer", "", "", "", pb.ServerDiscovery{}) ++ ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ++ defer cancel() ++ mc.tryConnectToMaster(ctx, server.address) ++ if server.connections.Load() != 1 { ++ t.Fatal("first stream did not register") ++ } ++ updates := make(chan string, 3) ++ mc.SetOnPeerUpdateFn(func(update *master_pb.ClusterNodeUpdate, _ time.Time) { updates <- update.Address }) ++ barrier := make(chan struct{}) ++ mc.SetOnLockRingUpdateFn(func(*master_pb.LockRingUpdate) { close(barrier) }) ++ done := make(chan struct{}) ++ go func() { mc.tryConnectToMaster(ctx, server.address); close(done) }() ++ select { ++ case <-barrier: ++ case <-ctx.Done(): ++ t.Fatal("reconnected stream did not dispatch its initial ADDs") ++ } ++ cancel() ++ <-done ++ for _, want := range []string{"peer-a:8888", "peer-b:8888"} { ++ select { ++ case got := <-updates: ++ if got != want { ++ t.Fatalf("update = %q, want %q", got, want) ++ } ++ default: ++ t.Fatalf("missing update %q", want) ++ } ++ } ++} ++ ++func TestPeerUpdateHandoffReconnectDropsPeersAbsentFromNewStream(t *testing.T) { ++ server := &peerReconnectMaster{streams: [][]string{{"peer-a:8888"}, {"peer-b:8888"}}} ++ server.address = startFakeMasterServer(t, server) ++ mc := NewMasterClient(grpc.WithTransportCredentials(insecure.NewCredentials()), "", "filer", "", "", "", pb.ServerDiscovery{}) ++ ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ++ defer cancel() ++ mc.tryConnectToMaster(ctx, server.address) ++ if server.connections.Load() != 1 { ++ t.Fatal("first stream did not register") ++ } ++ barrier := make(chan struct{}) ++ mc.SetOnLockRingUpdateFn(func(*master_pb.LockRingUpdate) { close(barrier) }) ++ done := make(chan struct{}) ++ go func() { mc.tryConnectToMaster(ctx, server.address); close(done) }() ++ select { ++ case <-barrier: ++ case <-ctx.Done(): ++ t.Fatal("reconnected stream did not deliver its initial ADDs") ++ } ++ var replayed []string ++ mc.SetOnPeerUpdateFn(func(update *master_pb.ClusterNodeUpdate, _ time.Time) { replayed = append(replayed, update.Address) }) ++ cancel() ++ <-done ++ if len(replayed) != 1 || replayed[0] != "peer-b:8888" { ++ t.Fatalf("replayed %v, want only the reconnected stream's [peer-b:8888]", replayed) ++ } ++} ++ ++func TestPeerUpdateHandoffReconnectSkipsPeersOfEndedStream(t *testing.T) { ++ server := &peerReconnectMaster{streams: [][]string{{"peer-a:8888"}, {"peer-b:8888"}}} ++ server.address = startFakeMasterServer(t, server) ++ mc := NewMasterClient(grpc.WithTransportCredentials(insecure.NewCredentials()), "", "filer", "", "", "", pb.ServerDiscovery{}) ++ ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ++ defer cancel() ++ mc.tryConnectToMaster(ctx, server.address) ++ if server.connections.Load() != 1 { ++ t.Fatal("first stream did not register") ++ } ++ updates := make(chan string, 3) ++ mc.SetOnPeerUpdateFn(func(update *master_pb.ClusterNodeUpdate, _ time.Time) { updates <- update.Address }) ++ select { ++ case got := <-updates: ++ t.Fatalf("replayed %q from a stream that already ended", got) ++ default: ++ } ++ barrier := make(chan struct{}) ++ mc.SetOnLockRingUpdateFn(func(*master_pb.LockRingUpdate) { close(barrier) }) ++ done := make(chan struct{}) ++ go func() { mc.tryConnectToMaster(ctx, server.address); close(done) }() ++ select { ++ case <-barrier: ++ case <-ctx.Done(): ++ t.Fatal("reconnected stream did not deliver its initial ADDs") ++ } ++ cancel() ++ <-done ++ close(updates) ++ var got []string ++ for address := range updates { ++ got = append(got, address) ++ } ++ if len(got) != 1 || got[0] != "peer-b:8888" { ++ t.Fatalf("updates %v, want only the reconnected stream's [peer-b:8888]", got) ++ } ++}