Files
helm-charts/samba/templates/samba.sfs.yaml
T
jklein b190b7e833 samba: restart the pod when smb.conf changes
smb.conf is rendered from samba.shares and mounted with subPath, so adding,
renaming or re-scoping a share rewrote the ConfigMap while the running smbd
kept its old share list: the pod template was unchanged, nothing restarted,
and the kubelet does not refresh subPath mounts. The share simply did not
exist for clients while the release looked healthy - the failure mode from #82.

The pod template now carries checksum/config over the rendered ConfigMap.

users.conf cannot be covered the same way: it comes from a 1Password-backed
Secret whose content Helm never sees, and the operator's auto-restart only
handles Deployments, not this StatefulSet. values.yaml now documents that
limitation and the manual rollout restart it requires.

Major bump: runtime behavior changes - a share change now costs a restart of
the samba pod, which drops open SMB sessions (share data lives on PVCs and is
unaffected).
2026-08-23 19:04:23 +02:00

108 lines
4.2 KiB
YAML

apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ .Release.Name }}-{{ .Chart.Name }}-sfs
labels:
app: {{ .Release.Name }}-{{ .Chart.Name }}-sfs
spec:
replicas: {{ include "samba.replicas" (dict "scaleDown" .Values.scaleDown "replicas" .Values.samba.replicas) }}
serviceName: {{ .Release.Name }}-{{ .Chart.Name }}-service
selector:
matchLabels:
app: {{ .Release.Name }}-{{ .Chart.Name }}-sfs
template:
metadata:
name: {{ .Release.Name }}-{{ .Chart.Name }}-sfs
labels:
app: {{ .Release.Name }}-{{ .Chart.Name }}-sfs
annotations:
# Hash of the rendered ConfigMap: a changed smb.conf (i.e. a changed
# samba.shares list) changes the pod template and thus restarts the
# pod. Without it a new or renamed share never reaches the running
# smbd - smb.conf is mounted with subPath (never refreshed by the
# kubelet) and is read once at start.
# users.conf is NOT covered: it comes from a 1Password-backed Secret
# whose content Helm never sees. See secrets.sambaUsersSecretRef in
# values.yaml.
checksum/config: {{ include (print $.Template.BasePath "/samba-config.configmap.yaml") . | sha256sum }}
spec:
containers:
- name: {{ .Release.Name }}-{{ .Chart.Name }}-sfs
image: "ghcr.io/dockur/samba:{{ .Chart.AppVersion }}"
imagePullPolicy: IfNotPresent
{{- with .Values.samba.env }}
env:
{{- range $value := . }}
{{- if $value.value }}
- name: {{ $value.name }}
value: {{ tpl $value.value $ | quote }}
{{- else if $value.valueFrom }}
{{- if $value.valueFrom.secretKeyRef }}
- name: {{ $value.name }}
valueFrom:
secretKeyRef:
name: {{ tpl $value.valueFrom.secretKeyRef.name $ | quote }}
key: {{ tpl $value.valueFrom.secretKeyRef.key $ | quote }}
{{- else if $value.valueFrom.configMapKeyRef }}
- name: {{ $value.name }}
valueFrom:
configMapKeyRef:
name: {{ tpl $value.valueFrom.configMapKeyRef.name $ | quote }}
key: {{ tpl $value.valueFrom.configMapKeyRef.key $ | quote }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
ports:
- containerPort: 445
protocol: TCP
- containerPort: 139
protocol: TCP
volumeMounts:
- name: smb-config
mountPath: "/etc/samba/smb.conf"
readOnly: true
subPath: smb.conf
- name: smb-users
mountPath: "/etc/samba/users.conf"
readOnly: true
subPath: users.conf
{{- range $index, $value := .Values.samba.shares }}
- name: "{{ $value.name }}"
mountPath: "/shares/{{ $value.name }}"
{{- end }}
livenessProbe:
{{- toYaml .Values.samba.livenessProbe | nindent 12 }}
readinessProbe:
{{- toYaml .Values.samba.readinessProbe | nindent 12 }}
startupProbe:
{{- toYaml .Values.samba.startupProbe | nindent 12 }}
resources:
{{- include "samba.resources" .Values.samba.resources | nindent 12 }}
securityContext:
{{- toYaml .Values.samba.securityContext.container | nindent 12 }}
restartPolicy: Always
automountServiceAccountToken: false
securityContext:
{{- toYaml .Values.samba.securityContext.pod | nindent 8 }}
volumes:
- name: smb-config
configMap:
name: {{ .Release.Name }}-{{ .Chart.Name }}-configmap
items:
- key: smb.conf
path: smb.conf
- name: smb-users
secret:
secretName: {{ .Release.Name }}-{{ .Chart.Name }}-users-secret
items:
- key: users.conf
path: users.conf
{{- range $index, $value := .Values.samba.shares }}
- name: "{{ $value.name }}"
persistentVolumeClaim:
claimName: "{{ $.Release.Name }}-{{ $value.name }}-volume-claim"
{{- end }}