Skip to content

Commit 821308c

Browse files
authored
refactor: s3 integration and environment variable handling (#11)
* Refactor S3 integration and environment variable handling Introduces helper templates for S3 configuration, refactors S3-related environment variables in deployments, and updates the S3 integration schema and values. Adds support for more flexible S3 configuration (endpoint, port, region, SSL, domain, pathStyle) and improves Traefik middleware for MinIO. Also standardizes image tag formatting in helper templates. * Quote Helm template values in deployment YAMLs Updated environment variable values in swanlab-house and swanlab-server deployment templates to consistently use Helm's | quote filter. This ensures correct YAML rendering and prevents type-related issues when values are rendered as booleans or numbers.
1 parent 2c7bba6 commit 821308c

15 files changed

Lines changed: 225 additions & 57 deletions

File tree

.idea/dictionaries/project.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/self-hosted/templates/s3/_helpers.tpl

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,83 @@ S3 PVC Name
4646
*/}}
4747
{{- define "swanlab.s3.pvcName" -}}
4848
{{.Values.dependencies.s3.persistence.existingClaim | default (printf "%s-pvc" (include "swanlab.s3.fullname" .)) }}
49-
{{- end -}}
49+
{{- end -}}
50+
51+
{{/*
52+
S3 Type
53+
*/}}
54+
{{- define "swanlab.s3.type" }}
55+
{{- if .Values.integrations.s3.enabled -}}
56+
{{- "remote" -}}
57+
{{- else -}}
58+
{{- "local" -}}
59+
{{- end -}}
60+
{{- end -}}
61+
62+
63+
{{/*
64+
S3 SSL
65+
*/}}
66+
{{- define "swanlab.s3.ssl" }}
67+
{{- if .Values.integrations.s3.enabled -}}
68+
{{- .Values.integrations.s3.ssl | default false -}}
69+
{{- else -}}
70+
{{- false -}}
71+
{{- end -}}
72+
{{- end -}}
73+
74+
{{/*
75+
S3 Endpoint
76+
*/}}
77+
{{- define "swanlab.s3.endpoint" }}
78+
{{- if .Values.integrations.s3.enabled -}}
79+
{{- required "If .Values.integrations.s3.enabled is true, you must specify the S3 endpoint via .Values.integrations.s3.endpoint." .Values.integrations.s3.endpoint -}}
80+
{{- else -}}
81+
{{- include "swanlab.s3.fullname" . -}}
82+
{{- end -}}
83+
{{- end -}}
84+
85+
{{/*
86+
S3 Port
87+
*/}}
88+
{{- define "swanlab.s3.port" }}
89+
{{- if .Values.integrations.s3.enabled -}}
90+
{{- required "If .Values.integrations.s3.enabled is true, you must specify the S3 port via .Values.integrations.s3.port." .Values.integrations.s3.port -}}
91+
{{- else -}}
92+
{{- 9000 -}}
93+
{{- end -}}
94+
{{- end -}}
95+
96+
{{/*
97+
S3 Region
98+
*/}}
99+
{{- define "swanlab.s3.region" }}
100+
{{- if .Values.integrations.s3.enabled -}}
101+
{{- required "If .Values.integrations.s3.enabled is true, you must specify the S3 region via .Values.integrations.s3.region." .Values.integrations.s3.region -}}
102+
{{- else -}}
103+
{{- "local" -}}
104+
{{- end -}}
105+
{{- end -}}
106+
107+
{{/*
108+
S3 Domain
109+
*/}}
110+
{{- define "swanlab.s3.domain" }}
111+
{{- if .Values.integrations.s3.enabled -}}
112+
{{- required "If .Values.integrations.s3.enabled is true, you must specify the S3 domain via .Values.integrations.s3.domain." .Values.integrations.s3.domain -}}
113+
{{- else -}}
114+
{{- "" -}}
115+
{{- end -}}
116+
{{- end -}}
117+
118+
{{/*
119+
S3 Path Style
120+
*/}}
121+
{{- define "swanlab.s3.pathStyle" }}
122+
{{- if .Values.integrations.s3.enabled -}}
123+
{{- .Values.integrations.s3.pathStyle | default true -}}
124+
{{- else -}}
125+
{{- true -}}
126+
{{- end -}}
127+
{{- end -}}
128+

charts/self-hosted/templates/s3/deployment.yaml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ spec:
8484
selector:
8585
{{- include "swanlab.s3.selectorLabels" . | nindent 4 }}
8686
ports:
87-
- port: 9000
87+
- port: {{ include "swanlab.s3.port" . }}
8888
name: minio
8989
- port: 9001
9090
name: minio-console
@@ -116,10 +116,7 @@ spec:
116116
echo "MinIO Service is up!"
117117
env:
118118
- name: MINIO_ENDPOINT
119-
valueFrom:
120-
secretKeyRef:
121-
name: {{ include "swanlab.s3.secretName" . }}
122-
key: endpoint
119+
value: "http://{{ include "swanlab.s3.fullname" . }}:{{ include "swanlab.s3.port" . }}"
123120
containers:
124121
- name: minio-mc-job
125122
image: "{{ .Values.dependencies.s3.mcImage.repository }}:{{ .Values.dependencies.s3.mcImage.tag }}"
@@ -136,10 +133,7 @@ spec:
136133
name: {{ include "swanlab.s3.secretName" . }}
137134
key: accessKey
138135
- name: MINIO_ENDPOINT
139-
valueFrom:
140-
secretKeyRef:
141-
name: {{ include "swanlab.s3.secretName" . }}
142-
key: endpoint
136+
value: "http://{{ include "swanlab.s3.fullname" . }}:{{ include "swanlab.s3.port" . }}"
143137
- name: MINIO_PRIVATE_BUCKET
144138
valueFrom:
145139
secretKeyRef:
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
{{- if .Values.integrations.s3.enabled }}
22
{{- $_ := required "You must provide a value for .Values.integrations.s3.existingSecret when .Values.integrations.s3.enabled is true" .Values.integrations.s3.existingSecret }}
33
{{- else }}
4-
{{- $region := "local"}}
5-
{{- $privateBucket := "swanlab-private"}}
6-
{{- $publicBucket := "swanlab-public"}}
7-
{{- $accessKey := .Values.dependencies.s3.accessKey | default "swanlab"}}
8-
{{- $secretKey := .Values.dependencies.s3.secretKey | default "swanlab-s3"}}
9-
{{- $endpoint := printf "http://%s:9000" (include "swanlab.s3.fullname" .) }}
4+
{{- $privateBucket := "swanlab-private" }}
5+
{{- $publicBucket := "swanlab-public" }}
6+
{{- $accessKey := .Values.dependencies.s3.accessKey | default "swanlab" }}
7+
{{- $secretKey := .Values.dependencies.s3.secretKey | default "swanlab-s3" }}
108

119
apiVersion: v1
1210
kind: Secret
@@ -18,8 +16,6 @@ type: Opaque
1816
data:
1917
accessKey: {{ $accessKey | b64enc }}
2018
secretKey: {{ $secretKey | b64enc }}
21-
endpoint: {{ $endpoint | b64enc }}
2219
privateBucket: {{ $privateBucket | b64enc }}
2320
publicBucket: {{ $publicBucket | b64enc }}
24-
region: {{ $region | b64enc }}
2521
{{- end }}

charts/self-hosted/templates/swanlab-cloud/_helpers.tpl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ Cut of 40 chars to comply with k8s name limit.
1414
SwanLab-Cloud Image
1515
*/}}
1616
{{- define "swanlab.cloud.image" -}}
17-
{{- $tag := default .Values.service.cloud.image.tag .Chart.AppVersion }}
18-
{{- printf "%s:v%s" .Values.service.cloud.image.repository $tag -}}
17+
{{- $defaultTag := printf "v%s" .Chart.AppVersion }}
18+
{{- $tag := default $defaultTag .Values.service.cloud.image.tag }}
19+
{{- printf "%s:%s" .Values.service.cloud.image.repository $tag -}}
1920
{{- end -}}
2021

2122
{{/*

charts/self-hosted/templates/swanlab-house/_helpers.tpl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ Cut of 40 chars to comply with k8s name limit.
1414
SwanLab-House Image
1515
*/}}
1616
{{- define "swanlab.house.image" -}}
17-
{{- $tag := default .Chart.AppVersion .Values.service.house.image.tag}}
18-
{{- printf "%s:v%s" .Values.service.house.image.repository $tag -}}
17+
{{- $defaultTag := printf "v%s" .Chart.AppVersion }}
18+
{{- $tag := default $defaultTag .Values.service.house.image.tag }}
19+
{{- printf "%s:%s" .Values.service.house.image.repository $tag -}}
1920
{{- end -}}
2021

2122
{{/*

charts/self-hosted/templates/swanlab-house/deployment.yaml

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,28 +147,39 @@ spec:
147147
secretKeyRef:
148148
name: {{ include "swanlab.clickhouse.secretName" . }}
149149
key: database
150-
- name: MINIO_ENDPOINT
150+
- name: SH_DISTRIBUTED_ENABLE
151+
value: "true"
152+
- name: SH_REDIS_URL
151153
valueFrom:
152154
secretKeyRef:
153-
name: {{ include "swanlab.s3.secretName" .}}
154-
key: endpoint
155-
- name: MINIO_SECRET_ID
155+
name: {{ include "swanlab.redis.secretName" . }}
156+
key: url
157+
# s3
158+
- name: SH_MINIO_ENDPOINT
159+
value: "{{ include "swanlab.s3.endpoint" . }}:{{ include "swanlab.s3.port" . }}"
160+
- name: SH_MINIO_USE_SSL
161+
value: {{ include "swanlab.s3.ssl" . | quote }}
162+
- name: SH_MINIO_REGION
163+
value: {{ include "swanlab.s3.region" . | quote }}
164+
- name: SH_MINIO_PATH_STYLE
165+
value: {{ include "swanlab.s3.pathStyle" . | quote }}
166+
167+
- name: SH_MINIO_SECRET_ID
156168
valueFrom:
157169
secretKeyRef:
158170
name: {{ include "swanlab.s3.secretName" .}}
159171
key: accessKey
160-
- name: MINIO_SECRET_KEY
172+
- name: SH_MINIO_SECRET_KEY
161173
valueFrom:
162174
secretKeyRef:
163175
name: {{ include "swanlab.s3.secretName" .}}
164176
key: secretKey
165-
- name: SH_DISTRIBUTED_ENABLE
166-
value: "true"
167-
- name: SH_REDIS_URL
177+
- name: SH_MINIO_PRIVATE_BUCKET
168178
valueFrom:
169179
secretKeyRef:
170-
name: {{ include "swanlab.redis.secretName" . }}
171-
key: url
180+
name: {{ include "swanlab.s3.secretName" .}}
181+
key: privateBucket
182+
172183
- name: logrotate
173184
image: {{ .Values.service.house.logImage.repository }}:{{ .Values.service.house.logImage.tag }}
174185
env:

charts/self-hosted/templates/swanlab-next/_helpers.tpl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ Cut of 40 chars to comply with k8s name limit.
1414
SwanLab-Next Image
1515
*/}}
1616
{{- define "swanlab.next.image" -}}
17-
{{- $tag := default .Chart.AppVersion .Values.service.next.image.tag}}
18-
{{- printf "%s:v%s" .Values.service.next.image.repository $tag -}}
17+
{{- $defaultTag := printf "v%s" .Chart.AppVersion }}
18+
{{- $tag := default $defaultTag .Values.service.next.image.tag}}
19+
{{- printf "%s:%s" .Values.service.next.image.repository $tag -}}
1920
{{- end -}}
2021

2122
{{/*

charts/self-hosted/templates/swanlab-server/_helpers.tpl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ Cut of 40 chars to comply with k8s name limit.
1414
SwanLab-ServerImage
1515
*/}}
1616
{{- define "swanlab.server.image" -}}
17-
{{- $tag := default .Chart.AppVersion .Values.service.server.image.tag }}
18-
{{- printf "%s:v%s" .Values.service.server.image.repository $tag -}}
17+
{{- $defaultTag := printf "v%s" .Chart.AppVersion }}
18+
{{- $tag := default $defaultTag .Values.service.server.image.tag }}
19+
{{- printf "%s:%s" .Values.service.server.image.repository $tag -}}
1920
{{- end -}}
2021

2122
{{/*

charts/self-hosted/templates/swanlab-server/deployment.yaml

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,43 @@ spec:
120120
secretKeyRef:
121121
name: {{include "swanlab.postgres.secretName" . }}
122122
key: replicaUrl
123+
- name: REDIS_URL
124+
valueFrom:
125+
secretKeyRef:
126+
name: {{include "swanlab.redis.secretName" . }}
127+
key: url
128+
- name: VERSION
129+
value: {{ .Chart.AppVersion | quote }}
130+
- name: SERVER_PREFIX
131+
value: "/api"
132+
- name: SS_HOUSE_URL
133+
value: "http://{{ include "swanlab.house.fullname" . }}:{{ include "swanlab.house.port" . }}/api/house"
134+
# s3
135+
- name: SS_STORAGE_TYPE
136+
value: {{ include "swanlab.s3.type" . | quote }}
137+
- name: SS_PUBLIC_STORAGE_ENDPOINT
138+
value: {{ include "swanlab.s3.endpoint" . | quote }}
139+
- name: SS_PUBLIC_STORAGE_REGION
140+
value: {{ include "swanlab.s3.region" . }}
141+
- name: SS_PUBLIC_STORAGE_PATH_STYLE
142+
value: {{ include "swanlab.s3.pathStyle" . | quote }}
143+
- name: SS_PUBLIC_STORAGE_PORT
144+
value: {{ include "swanlab.s3.port" . | quote }}
145+
- name: SS_PUBLIC_STORAGE_USE_SSL
146+
value: {{ include "swanlab.s3.ssl" . | quote }}
147+
- name: SS_PRIVATE_STORAGE_ENDPOINT
148+
value: {{ include "swanlab.s3.endpoint" . | quote }}
149+
- name: SS_PRIVATE_STORAGE_REGION
150+
value: {{ include "swanlab.s3.region" . | quote }}
151+
- name: SS_PRIVATE_STORAGE_PATH_STYLE
152+
value: {{ include "swanlab.s3.pathStyle" . | quote }}
153+
- name: SS_PRIVATE_STORAGE_PORT
154+
value: {{ include "swanlab.s3.port" . | quote }}
155+
- name: SS_PRIVATE_STORAGE_USE_SSL
156+
value: {{ include "swanlab.s3.ssl" . | quote }}
157+
- name: SS_AVATAR_DOMAIN
158+
value: {{ include "swanlab.s3.domain" . | quote }}
159+
123160
- name: ACCESS_KEY
124161
valueFrom:
125162
secretKeyRef:
@@ -130,15 +167,16 @@ spec:
130167
secretKeyRef:
131168
name: {{include "swanlab.s3.secretName" . }}
132169
key: secretKey
133-
- name: REDIS_URL
170+
- name: SS_PRIVATE_STORAGE_BUCKET
134171
valueFrom:
135172
secretKeyRef:
136-
name: {{include "swanlab.redis.secretName" . }}
137-
key: url
138-
- name: VERSION
139-
value: {{ .Chart.AppVersion | quote }}
140-
- name: SERVER_PREFIX
141-
value: /api
173+
name: {{include "swanlab.s3.secretName" . }}
174+
key: privateBucket
175+
- name: SS_PUBLIC_STORAGE_BUCKET
176+
valueFrom:
177+
secretKeyRef:
178+
name: {{include "swanlab.s3.secretName" . }}
179+
key: publicBucket
142180
{{- if .Values.service.server.resources }}
143181
resources:
144182
{{- toYaml .Values.service.server.resources | nindent 12 }}

0 commit comments

Comments
 (0)