From 51ef39fc76dd2e8f53682f060ef57871912f1bc4 Mon Sep 17 00:00:00 2001 From: Emanuele Leopardi <28568180+emanuele-leopardi@users.noreply.github.com> Date: Wed, 28 Jan 2026 22:08:20 +0100 Subject: [PATCH] Update Helm hook annotations for post-install and upgrade (#8150) * Update Helm hook annotations for post-install and upgrade I believe it makes sense to allow this job to run also after installation. Assuming weed shell is idempotent, and assuming someone wants to add a new bucket after the initial installation, it makes sense to trigger the job again. * Add check for existing buckets before creation * Enhances S3 bucket existence check Improves the reliability of checking for existing S3 buckets in the post-install hook. The previous `grep -w` command could lead to imprecise matches. This update extracts only the bucket name and performs an exact, whole-line match to ensure accurate detection of existing buckets. This prevents potential issues with redundant creation attempts or false negatives. * Currently Bucket Creation is ignored if filer.s3.enabled is disabled This commit enables bucket creation on both scenarios,i.e. if any of filer.s3.enabled or s3.enabled are used. --------- Co-authored-by: Emanuele --- .../shared/post-install-bucket-hook.yaml | 25 ++++++++++++------- k8s/charts/seaweedfs/values.yaml | 9 ++++++- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/k8s/charts/seaweedfs/templates/shared/post-install-bucket-hook.yaml b/k8s/charts/seaweedfs/templates/shared/post-install-bucket-hook.yaml index 269919d19..930c474e9 100644 --- a/k8s/charts/seaweedfs/templates/shared/post-install-bucket-hook.yaml +++ b/k8s/charts/seaweedfs/templates/shared/post-install-bucket-hook.yaml @@ -15,14 +15,18 @@ {{- $existingConfigSecret = or .Values.allInOne.s3.existingConfigSecret .Values.s3.existingConfigSecret .Values.filer.s3.existingConfigSecret }} {{- end }} {{- else if .Values.master.enabled }} - {{- /* Check standalone filer.s3 mode */}} - {{- if .Values.filer.s3.enabled }} + {{- /* Check if embedded (in filer) or standalone S3 gateway is enabled */}} + {{- if or .Values.filer.s3.enabled .Values.s3.enabled }} {{- $s3Enabled = true }} - {{- if .Values.filer.s3.createBuckets }} + {{- if .Values.s3.createBuckets }} + {{- $createBuckets = .Values.s3.createBuckets }} + {{- $enableAuth = .Values.s3.enableAuth }} + {{- $existingConfigSecret = .Values.s3.existingConfigSecret }} + {{- else if .Values.filer.s3.createBuckets }} {{- $createBuckets = .Values.filer.s3.createBuckets }} + {{- $enableAuth = .Values.filer.s3.enableAuth }} + {{- $existingConfigSecret = .Values.filer.s3.existingConfigSecret }} {{- end }} - {{- $enableAuth = .Values.filer.s3.enableAuth }} - {{- $existingConfigSecret = .Values.filer.s3.existingConfigSecret }} {{- end }} {{- end }} @@ -36,7 +40,7 @@ metadata: app.kubernetes.io/managed-by: {{ .Release.Service | quote }} app.kubernetes.io/instance: {{ .Release.Name | quote }} annotations: - "helm.sh/hook": post-install + "helm.sh/hook": post-install,post-upgrade "helm.sh/hook-weight": "-5" "helm.sh/hook-delete-policy": hook-succeeded spec: @@ -105,9 +109,12 @@ spec: wait_for_service "http://$WEED_CLUSTER_SW_FILER{{ .Values.filer.readinessProbe.httpGet.path }}" {{- end }} {{- range $createBuckets }} - /bin/echo \ - "s3.bucket.create --name {{ .name }}" |\ - /usr/bin/weed shell + if /bin/echo "s3.bucket.list" | /usr/bin/weed shell | awk '{print $1}' | grep -Fxq "{{ .name }}"; then + echo "Bucket '{{ .name }}' already exists, skipping creation." + else + echo "Creating bucket '{{ .name }}'..." + /bin/echo "s3.bucket.create --name {{ .name }}" | /usr/bin/weed shell + fi {{- end }} {{- range $createBuckets }} {{- if .anonymousRead }} diff --git a/k8s/charts/seaweedfs/values.yaml b/k8s/charts/seaweedfs/values.yaml index 35befc3d1..f9d93dab6 100644 --- a/k8s/charts/seaweedfs/values.yaml +++ b/k8s/charts/seaweedfs/values.yaml @@ -891,7 +891,7 @@ filer: # should have a secret key called seaweedfs_s3_config with an inline json configure existingConfigSecret: null auditLogConfig: {} - # You may specify buckets to be created during the install process. + # You may specify buckets to be created during the install or upgrade process. # Buckets may be exposed publicly by setting `anonymousRead` to `true` # createBuckets: # - name: bucket-a @@ -916,6 +916,13 @@ s3: # should have a secret key called seaweedfs_s3_config with an inline json config existingConfigSecret: null auditLogConfig: {} + # You may specify buckets to be created during the install or upgrade process. + # Buckets may be exposed publicly by setting `anonymousRead` to `true` + # createBuckets: + # - name: bucket-a + # anonymousRead: true + # - name: bucket-b + # anonymousRead: false # Suffix of the host name, {bucket}.{domainName} domainName: ""