volume-statefulset.yaml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. {{ $volumes := deepCopy .Values.volumes | mergeOverwrite (dict "" .Values.volume) }}
  2. {{- range $vname, $volume := $volumes }}
  3. {{- $volumeName := trimSuffix "-" (printf "volume-%s" $vname) }}
  4. {{- $volume := mergeOverwrite (deepCopy $.Values.volume) (dict "enabled" true) $volume }}
  5. {{- if $volume.enabled }}
  6. ---
  7. apiVersion: apps/v1
  8. kind: StatefulSet
  9. metadata:
  10. name: {{ template "seaweedfs.name" $ }}-{{ $volumeName }}
  11. namespace: {{ $.Release.Namespace }}
  12. labels:
  13. app.kubernetes.io/name: {{ template "seaweedfs.name" $ }}
  14. helm.sh/chart: {{ $.Chart.Name }}-{{ $.Chart.Version | replace "+" "_" }}
  15. app.kubernetes.io/managed-by: {{ $.Release.Service }}
  16. app.kubernetes.io/instance: {{ $.Release.Name }}
  17. app.kubernetes.io/component: {{ $volumeName }}
  18. {{- if $volume.annotations }}
  19. annotations:
  20. {{- toYaml $volume.annotations | nindent 4 }}
  21. {{- end }}
  22. spec:
  23. serviceName: {{ template "seaweedfs.name" $ }}-{{ $volumeName }}
  24. replicas: {{ $volume.replicas }}
  25. podManagementPolicy: {{ $volume.podManagementPolicy }}
  26. selector:
  27. matchLabels:
  28. app.kubernetes.io/name: {{ template "seaweedfs.name" $ }}
  29. app.kubernetes.io/instance: {{ $.Release.Name }}
  30. app.kubernetes.io/component: {{ $volumeName }}
  31. template:
  32. metadata:
  33. labels:
  34. app.kubernetes.io/name: {{ template "seaweedfs.name" $ }}
  35. helm.sh/chart: {{ $.Chart.Name }}-{{ $.Chart.Version | replace "+" "_" }}
  36. app.kubernetes.io/instance: {{ $.Release.Name }}
  37. app.kubernetes.io/component: {{ $volumeName }}
  38. {{ with $.Values.podLabels }}
  39. {{- toYaml . | nindent 8 }}
  40. {{- end }}
  41. {{- with $volume.podLabels }}
  42. {{- toYaml . | nindent 8 }}
  43. {{- end }}
  44. annotations:
  45. {{ with $.Values.podAnnotations }}
  46. {{- toYaml . | nindent 8 }}
  47. {{- end }}
  48. {{- with $volume.podAnnotations }}
  49. {{- toYaml . | nindent 8 }}
  50. {{- end }}
  51. spec:
  52. {{- if $volume.affinity }}
  53. affinity:
  54. {{ tpl (printf "{{ $volumeName := \"%s\" }}%s" $volumeName $volume.affinity) $ | indent 8 | trim }}
  55. {{- end }}
  56. {{- if $volume.topologySpreadConstraints }}
  57. topologySpreadConstraints:
  58. {{ tpl (printf "{{ $volumeName := \"%s\" }}%s" $volumeName $volume.topologySpreadConstraints) $ | nindent 8 | trim }}
  59. {{- end }}
  60. restartPolicy: {{ default $.Values.global.restartPolicy $volume.restartPolicy }}
  61. {{- if $volume.tolerations }}
  62. tolerations:
  63. {{ tpl (printf "{{ $volumeName := \"%s\" }}%s" $volumeName $volume.tolerations) $ | indent 8 | trim }}
  64. {{- end }}
  65. {{- include "seaweedfs.imagePullSecrets" $ | nindent 6 }}
  66. terminationGracePeriodSeconds: 150
  67. {{- if $volume.priorityClassName }}
  68. priorityClassName: {{ $volume.priorityClassName | quote }}
  69. {{- end }}
  70. enableServiceLinks: false
  71. {{- if $.Values.global.createClusterRole }}
  72. serviceAccountName: {{ $volume.serviceAccountName | default $.Values.global.serviceAccountName | quote }} # for deleting statefulset pods after migration
  73. {{- end }}
  74. {{- $initContainers_exists := include "volume.initContainers_exists" $ -}}
  75. {{- if $initContainers_exists }}
  76. initContainers:
  77. {{- if $volume.idx }}
  78. - name: seaweedfs-vol-move-idx
  79. image: {{ template "volume.image" $ }}
  80. imagePullPolicy: {{ $.Values.global.imagePullPolicy | default "IfNotPresent" }}
  81. command: [ '/bin/sh', '-c' ]
  82. args: [ '{{range $dir := $volume.dataDirs }}if ls /{{$dir.name}}/*.idx >/dev/null 2>&1; then mv /{{$dir.name}}/*.idx /idx/ ; fi; {{end}}' ]
  83. volumeMounts:
  84. - name: idx
  85. mountPath: /idx
  86. {{- range $dir := $volume.dataDirs }}
  87. - name: {{ $dir.name }}
  88. mountPath: /{{ $dir.name }}
  89. {{- end }}
  90. {{- end }}
  91. {{- if $volume.initContainers }}
  92. {{ tpl (printf "{{ $volumeName := \"%s\" }}%s" $volumeName $volume.initContainers) $ | indent 8 | trim }}
  93. {{- end }}
  94. {{- end }}
  95. {{- if $volume.podSecurityContext.enabled }}
  96. securityContext: {{- omit $volume.podSecurityContext "enabled" | toYaml | nindent 8 }}
  97. {{- end }}
  98. containers:
  99. - name: seaweedfs
  100. image: {{ template "volume.image" $ }}
  101. imagePullPolicy: {{ default "IfNotPresent" $.Values.global.imagePullPolicy }}
  102. env:
  103. - name: POD_NAME
  104. valueFrom:
  105. fieldRef:
  106. fieldPath: metadata.name
  107. - name: NAMESPACE
  108. valueFrom:
  109. fieldRef:
  110. fieldPath: metadata.namespace
  111. - name: HOST_IP
  112. valueFrom:
  113. fieldRef:
  114. fieldPath: status.hostIP
  115. - name: SEAWEEDFS_FULLNAME
  116. value: "{{ template "seaweedfs.name" $ }}"
  117. {{- if $volume.extraEnvironmentVars }}
  118. {{- range $key, $value := $volume.extraEnvironmentVars }}
  119. - name: {{ $key }}
  120. {{- if kindIs "string" $value }}
  121. value: {{ $value | quote }}
  122. {{- else }}
  123. valueFrom:
  124. {{ toYaml $value | nindent 16 | trim }}
  125. {{- end -}}
  126. {{- end }}
  127. {{- end }}
  128. {{- if $.Values.global.extraEnvironmentVars }}
  129. {{- range $key, $value := $.Values.global.extraEnvironmentVars }}
  130. - name: {{ $key }}
  131. {{- if kindIs "string" $value }}
  132. value: {{ $value | quote }}
  133. {{- else }}
  134. valueFrom:
  135. {{ toYaml $value | nindent 16 | trim }}
  136. {{- end -}}
  137. {{- end }}
  138. {{- end }}
  139. command:
  140. - "/bin/sh"
  141. - "-ec"
  142. - |
  143. exec /usr/bin/weed \
  144. {{- if $volume.logs }}
  145. -logdir=/logs \
  146. {{- else }}
  147. -logtostderr=true \
  148. {{- end }}
  149. {{- if $volume.loggingOverrideLevel }}
  150. -v={{ $volume.loggingOverrideLevel }} \
  151. {{- else }}
  152. -v={{ $.Values.global.loggingLevel }} \
  153. {{- end }}
  154. volume \
  155. -port={{ $volume.port }} \
  156. {{- if $volume.metricsPort }}
  157. -metricsPort={{ $volume.metricsPort }} \
  158. {{- end }}
  159. {{- if $volume.metricsIp }}
  160. -metricsIp={{ $volume.metricsIp }} \
  161. {{- end }}
  162. -dir {{range $index, $dir := $volume.dataDirs }}{{if ne $index 0}},{{end}}/{{$dir.name}}{{end}} \
  163. {{- if $volume.idx }}
  164. -dir.idx=/idx \
  165. {{- end }}
  166. -max {{range $index, $dir := $volume.dataDirs }}{{if ne $index 0}},{{end}}
  167. {{- if eq ($dir.maxVolumes | toString) "0" }}0{{ else if not $dir.maxVolumes }}7{{ else }}{{$dir.maxVolumes}}{{ end }}
  168. {{- end }} \
  169. {{- if $volume.rack }}
  170. -rack={{ $volume.rack }} \
  171. {{- end }}
  172. {{- if $volume.dataCenter }}
  173. -dataCenter={{ $volume.dataCenter }} \
  174. {{- end }}
  175. -ip.bind={{ $volume.ipBind }} \
  176. -readMode={{ $volume.readMode }} \
  177. {{- if $volume.whiteList }}
  178. -whiteList={{ $volume.whiteList }} \
  179. {{- end }}
  180. {{- if $volume.imagesFixOrientation }}
  181. -images.fix.orientation \
  182. {{- end }}
  183. {{- if $volume.pulseSeconds }}
  184. -pulseSeconds={{ $volume.pulseSeconds }} \
  185. {{- end }}
  186. {{- if $volume.index }}
  187. -index={{ $volume.index }} \
  188. {{- end }}
  189. {{- if $volume.fileSizeLimitMB }}
  190. -fileSizeLimitMB={{ $volume.fileSizeLimitMB }} \
  191. {{- end }}
  192. -minFreeSpacePercent={{ $volume.minFreeSpacePercent }} \
  193. -ip=${POD_NAME}.${SEAWEEDFS_FULLNAME}-{{ $volumeName }}.{{ $.Release.Namespace }} \
  194. -compactionMBps={{ $volume.compactionMBps }} \
  195. -mserver={{ if $.Values.global.masterServer }}{{ $.Values.global.masterServer}}{{ else }}{{ 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 }}
  196. {{- range $volume.extraArgs }}
  197. {{ . }} \
  198. {{- end }}
  199. volumeMounts:
  200. {{- range $dir := $volume.dataDirs }}
  201. {{- if not ( eq $dir.type "custom" ) }}
  202. - name: {{ $dir.name }}
  203. mountPath: "/{{ $dir.name }}/"
  204. {{- end }}
  205. {{- end }}
  206. {{- if $volume.logs }}
  207. - name: logs
  208. mountPath: "/logs/"
  209. {{- end }}
  210. {{- if $volume.idx }}
  211. - name: idx
  212. mountPath: "/idx/"
  213. {{- end }}
  214. {{- if $.Values.global.enableSecurity }}
  215. - name: security-config
  216. readOnly: true
  217. mountPath: /etc/seaweedfs/security.toml
  218. subPath: security.toml
  219. - name: ca-cert
  220. readOnly: true
  221. mountPath: /usr/local/share/ca-certificates/ca/
  222. - name: master-cert
  223. readOnly: true
  224. mountPath: /usr/local/share/ca-certificates/master/
  225. - name: volume-cert
  226. readOnly: true
  227. mountPath: /usr/local/share/ca-certificates/volume/
  228. - name: filer-cert
  229. readOnly: true
  230. mountPath: /usr/local/share/ca-certificates/filer/
  231. - name: client-cert
  232. readOnly: true
  233. mountPath: /usr/local/share/ca-certificates/client/
  234. {{- end }}
  235. {{ tpl (printf "{{ $volumeName := \"%s\" }}%s" $volumeName $volume.extraVolumeMounts) $ | indent 12 | trim }}
  236. ports:
  237. - containerPort: {{ $volume.port }}
  238. name: swfs-vol
  239. {{- if $volume.metricsPort }}
  240. - containerPort: {{ $volume.metricsPort }}
  241. name: metrics
  242. {{- end }}
  243. - containerPort: {{ $volume.grpcPort }}
  244. name: swfs-vol-grpc
  245. {{- if $volume.readinessProbe.enabled }}
  246. readinessProbe:
  247. httpGet:
  248. path: {{ $volume.readinessProbe.httpGet.path }}
  249. port: {{ $volume.port }}
  250. scheme: {{ $volume.readinessProbe.scheme }}
  251. initialDelaySeconds: {{ $volume.readinessProbe.initialDelaySeconds }}
  252. periodSeconds: {{ $volume.readinessProbe.periodSeconds }}
  253. successThreshold: {{ $volume.readinessProbe.successThreshold }}
  254. failureThreshold: {{ $volume.readinessProbe.failureThreshold }}
  255. timeoutSeconds: {{ $volume.readinessProbe.timeoutSeconds }}
  256. {{- end }}
  257. {{- if $volume.livenessProbe.enabled }}
  258. livenessProbe:
  259. httpGet:
  260. path: {{ $volume.livenessProbe.httpGet.path }}
  261. port: {{ $volume.port }}
  262. scheme: {{ $volume.livenessProbe.scheme }}
  263. initialDelaySeconds: {{ $volume.livenessProbe.initialDelaySeconds }}
  264. periodSeconds: {{ $volume.livenessProbe.periodSeconds }}
  265. successThreshold: {{ $volume.livenessProbe.successThreshold }}
  266. failureThreshold: {{ $volume.livenessProbe.failureThreshold }}
  267. timeoutSeconds: {{ $volume.livenessProbe.timeoutSeconds }}
  268. {{- end }}
  269. {{- with $volume.resources }}
  270. resources:
  271. {{- toYaml . | nindent 12 }}
  272. {{- end }}
  273. {{- if $volume.containerSecurityContext.enabled }}
  274. securityContext: {{- omit $volume.containerSecurityContext "enabled" | toYaml | nindent 12 }}
  275. {{- end }}
  276. {{- if $volume.sidecars }}
  277. {{- include "common.tplvalues.render" (dict "value" (printf "{{ $volumeName := \"%s\" }}%s" $volumeName $volume.sidecars) "context" $) | nindent 8 }}
  278. {{- end }}
  279. volumes:
  280. {{- range $dir := $volume.dataDirs }}
  281. {{- if eq $dir.type "hostPath" }}
  282. - name: {{ $dir.name }}
  283. hostPath:
  284. path: {{ $dir.hostPathPrefix }}/object_store/
  285. type: DirectoryOrCreate
  286. {{- end }}
  287. {{- if eq $dir.type "existingClaim" }}
  288. - name: {{ $dir.name }}
  289. persistentVolumeClaim:
  290. claimName: {{ $dir.claimName }}
  291. {{- end }}
  292. {{- if eq $dir.type "emptyDir" }}
  293. - name: {{ $dir.name }}
  294. emptyDir: {}
  295. {{- end }}
  296. {{- end }}
  297. {{- if $volume.idx }}
  298. {{- if eq $volume.idx.type "hostPath" }}
  299. - name: idx
  300. hostPath:
  301. path: {{ $volume.idx.hostPathPrefix }}/seaweedfs-volume-idx/
  302. type: DirectoryOrCreate
  303. {{- end }}
  304. {{- if eq $volume.idx.type "existingClaim" }}
  305. - name: idx
  306. persistentVolumeClaim:
  307. claimName: {{ $volume.idx.claimName }}
  308. {{- end }}
  309. {{- if eq $volume.idx.type "emptyDir" }}
  310. - name: idx
  311. emptyDir: {}
  312. {{- end }}
  313. {{- end }}
  314. {{- if $volume.logs }}
  315. {{- if eq $volume.logs.type "hostPath" }}
  316. - name: logs
  317. hostPath:
  318. path: {{ $volume.logs.hostPathPrefix }}/logs/seaweedfs/volume
  319. type: DirectoryOrCreate
  320. {{- end }}
  321. {{- if eq $volume.logs.type "existingClaim" }}
  322. - name: logs
  323. persistentVolumeClaim:
  324. claimName: {{ $volume.logs.claimName }}
  325. {{- end }}
  326. {{- if eq $volume.logs.type "emptyDir" }}
  327. - name: logs
  328. emptyDir: {}
  329. {{- end }}
  330. {{- end }}
  331. {{- if $.Values.global.enableSecurity }}
  332. - name: security-config
  333. configMap:
  334. name: {{ template "seaweedfs.name" $ }}-security-config
  335. - name: ca-cert
  336. secret:
  337. secretName: {{ template "seaweedfs.name" $ }}-ca-cert
  338. - name: master-cert
  339. secret:
  340. secretName: {{ template "seaweedfs.name" $ }}-master-cert
  341. - name: volume-cert
  342. secret:
  343. secretName: {{ template "seaweedfs.name" $ }}-volume-cert
  344. - name: filer-cert
  345. secret:
  346. secretName: {{ template "seaweedfs.name" $ }}-filer-cert
  347. - name: client-cert
  348. secret:
  349. secretName: {{ template "seaweedfs.name" $ }}-client-cert
  350. {{- end }}
  351. {{- if $volume.extraVolumes }}
  352. {{ tpl $volume.extraVolumes $ | indent 8 | trim }}
  353. {{- end }}
  354. {{- if $volume.nodeSelector }}
  355. nodeSelector:
  356. {{ tpl (printf "{{ $volumeName := \"%s\" }}%s" $volumeName $volume.nodeSelector) $ | indent 8 | trim }}
  357. {{- end }}
  358. volumeClaimTemplates:
  359. {{- range $dir := $volume.dataDirs }}
  360. {{- if eq $dir.type "persistentVolumeClaim" }}
  361. - apiVersion: v1
  362. kind: PersistentVolumeClaim
  363. metadata:
  364. name: {{ $dir.name }}
  365. {{- with $dir.annotations }}
  366. annotations:
  367. {{- toYaml . | nindent 10 }}
  368. {{- end }}
  369. spec:
  370. accessModes: [ "ReadWriteOnce" ]
  371. storageClassName: {{ $dir.storageClass }}
  372. resources:
  373. requests:
  374. storage: {{ $dir.size }}
  375. {{- end }}
  376. {{- end }}
  377. {{- if and $volume.idx (eq $volume.idx.type "persistentVolumeClaim") }}
  378. - apiVersion: v1
  379. kind: PersistentVolumeClaim
  380. metadata:
  381. name: idx
  382. {{- with $volume.idx.annotations }}
  383. annotations:
  384. {{- toYaml . | nindent 10 }}
  385. {{- end }}
  386. spec:
  387. accessModes: [ "ReadWriteOnce" ]
  388. storageClassName: {{ $volume.idx.storageClass }}
  389. resources:
  390. requests:
  391. storage: {{ $volume.idx.size }}
  392. {{- end }}
  393. {{- if and $volume.logs (eq $volume.logs.type "persistentVolumeClaim") }}
  394. - apiVersion: v1
  395. kind: PersistentVolumeClaim
  396. metadata:
  397. name: logs
  398. {{- with $volume.logs.annotations }}
  399. annotations:
  400. {{- toYaml . | nindent 10 }}
  401. {{- end }}
  402. spec:
  403. accessModes: [ "ReadWriteOnce" ]
  404. storageClassName: {{ $volume.logs.storageClass }}
  405. resources:
  406. requests:
  407. storage: {{ $volume.logs.size }}
  408. {{- end }}
  409. {{- end }}
  410. {{- end }}