@@ -27,11 +27,33 @@ spec:
27
27
checksum/config-prompt-templates : {{ include (print $.Template.BasePath "/configmap-prompt-templates.yaml") . | sha256sum }}
28
28
{{- end }}
29
29
spec :
30
- {{- with .Values.deployment.imagePullSecrets }}
30
+ {{- with .Values.deployment.imagePullSecrets }}
31
31
imagePullSecrets :
32
32
{{- toYaml . | nindent 8 }}
33
- {{- end }}
33
+ {{- end }}
34
34
initContainers :
35
+ # Additional initContainers from values.yaml
36
+ {{- range .Values.initContainers }}
37
+ - name : {{ .name }}
38
+ image : {{ .image }}
39
+ imagePullPolicy : {{ .imagePullPolicy }}
40
+ command : {{ .command }}
41
+ args : {{ .args | default list }}
42
+ env :
43
+ {{- toYaml .env | nindent 12 }}
44
+ resources :
45
+ {{- toYaml .resources | nindent 12 }}
46
+ volumeMounts :
47
+ {{- toYaml .volumeMounts | nindent 12 }}
48
+ {{- range $key, $pvc := .Values.persistence }}
49
+ {{- if $pvc.enabled }}
50
+ - name : {{ $key }}
51
+ mountPath : {{ $pvc.globalMount | default (print "/" $key) }}
52
+ {{- end }}
53
+ {{- end }}
54
+ securityContext :
55
+ {{- toYaml .securityContext | nindent 12 }}
56
+ {{- end }}
35
57
{{- if .Values.promptTemplates }}
36
58
- name : prompt-templates
37
59
image : {{ .Values.deployment.prompt_templates.image }}
43
65
volumeMounts :
44
66
- mountPath : /prompt-templates
45
67
name : prompt-templates
46
- - mountPath : /models
47
- name : models
68
+ {{- range $key, $pvc := .Values.persistence }}
69
+ {{- if $pvc.enabled }}
70
+ - name : {{ $key }}
71
+ mountPath : {{ $pvc.globalMount | default (print "/" $key) }}
72
+ {{- end }}
73
+ {{- end }}
48
74
{{- end }}
49
75
- name : download-model
50
76
image : {{ .Values.deployment.download_model.image }}
@@ -55,74 +81,119 @@ spec:
55
81
MODEL_DIR={{ .Values.deployment.modelsPath }}
56
82
FORCE_DOWNLOAD={{ .Values.models.forceDownload }}
57
83
URLS="{{ $urls }}"
84
+ LOCK_DIR=/tmp/model-download-locks
58
85
59
86
mkdir -p "$MODEL_DIR"
87
+ mkdir -p "$LOCK_DIR"
88
+ mkdir -p "/tmp/generated/images"
89
+ mkdir -p "/tmp/generated/audio"
90
+ rm -rf "/models/lost+found"
91
+
60
92
61
- # Split urls on commas
62
93
echo "$URLS" | awk -F, '{for (i=1; i<=NF; i++) print $i}' | while read -r line; do
63
94
url=$(echo "$line" | awk '{print $1}')
64
95
auth=$(echo "$line" | awk '{print $2}')
96
+ full_filename=$(basename "$url" .bin)
97
+ short_filename=$(echo "$full_filename" | cut -c1-20)
98
+ hash=$(echo "$full_filename" | sha256sum | cut -c1-12)
99
+ filename="${short_filename}_${hash}"
100
+ lockfile="$LOCK_DIR/$filename.lock"
65
101
66
- if [ -n "$url" ]; then
67
- filename=$(basename "$url" .bin)
68
-
69
- if [ "$FORCE_DOWNLOAD" = false ] && [ -f "$MODEL_DIR/$filename" ]; then
70
- echo "File $filename already exists. Skipping download."
71
- continue
72
- fi
102
+ if [ -e "$MODEL_DIR/$filename" ]; then
103
+ echo "File $filename already exists. Skipping download."
104
+ continue
105
+ fi
73
106
74
- rm -f "$MODEL_DIR/$filename"
107
+ if [ -e "$lockfile" ]; then
108
+ echo "Another pod is downloading $filename. Waiting for download to complete."
109
+ while [ -e "$lockfile" ]; do sleep 1; done
110
+ continue
111
+ fi
75
112
76
- echo "Downloading $filename "
113
+ touch "$lockfile "
77
114
78
- if [ -n "$auth" ]; then
79
- wget --header "Authorization: Basic $auth" "$url" -O "$MODEL_DIR/$filename"
80
- else
81
- wget "$url" -O "$MODEL_DIR/$filename"
82
- fi
115
+ echo "Downloading $filename"
116
+ if [ -n "$auth" ]; then
117
+ wget --header "Authorization: Basic $auth" "$url" -O "$MODEL_DIR/$filename"
118
+ else
119
+ wget "$url" -O "$MODEL_DIR/$filename"
120
+ fi
83
121
84
- if [ "$?" -ne 0 ]; then
85
- echo "Download failed."
86
- else
87
- echo "Download completed."
88
- fi
122
+ if [ "$?" -ne 0 ]; then
123
+ echo "Download failed."
124
+ rm -f "$lockfile"
125
+ exit 1
126
+ else
127
+ echo "Download completed."
128
+ rm -f "$lockfile"
89
129
fi
90
130
done
91
131
volumeMounts :
92
- - mountPath : {{ .Values.deployment.modelsPath }}
93
- name : models
132
+ {{- range $key, $pvc := .Values.persistence }}
133
+ {{- if $pvc.enabled }}
134
+ - name : {{ $key }}
135
+ mountPath : {{ $pvc.globalMount | default (print "/" $key) }}
136
+ {{- end }}
137
+ {{- end }}
94
138
containers :
139
+ # Sidecar containers from values.yaml
140
+ {{- range .Values.sidecarContainers }}
141
+ - name : {{ .name }}
142
+ image : {{ .image }}
143
+ imagePullPolicy : {{ .imagePullPolicy }}
144
+ command : {{ .command }}
145
+ args : {{ .args | default list }}
146
+ env :
147
+ {{- toYaml .env | nindent 12 }}
148
+ ports :
149
+ {{- toYaml .ports | nindent 12 }}
150
+ resources :
151
+ {{- toYaml .resources | nindent 12 }}
152
+ volumeMounts :
153
+ {{- toYaml .volumeMounts | nindent 12 }}
154
+ {{- range $key, $pvc := .Values.persistence }}
155
+ {{- if $pvc.enabled }}
156
+ - name : {{ $key }}
157
+ mountPath : {{ $pvc.globalMount | default (print "/" $key) }}
158
+ {{- end }}
159
+ {{- end }}
160
+ livenessProbe :
161
+ {{- toYaml .livenessProbe | nindent 12 }}
162
+ readinessProbe :
163
+ {{- toYaml .readinessProbe | nindent 12 }}
164
+ securityContext :
165
+ {{- toYaml .securityContext | nindent 12 }}
166
+ {{- end }}
95
167
- name : {{ template "local-ai.fullname" . }}
96
- image : {{ .Values.deployment.image }}
168
+ image : " {{ .Values.deployment.image.repository }}:{{ .Values.deployment.image.tag }} "
97
169
imagePullPolicy : {{ .Values.deployment.pullPolicy }}
98
170
resources :
99
171
{{- toYaml .Values.resources | nindent 12 }}
100
172
env :
101
- {{- range $key, $value := .Values.deployment.env }}
102
- - name : {{ $key | upper }}
103
- value : {{ quote $value }}
104
- {{- end }}
105
- - name : MODELS_PATH
106
- value : {{ .Values.deployment.modelsPath }}
173
+ {{- range $key, $value := .Values.deployment.env }}
174
+ - name : {{ $key | upper }}
175
+ value : {{ quote $value }}
176
+ {{- end }}
177
+ - name : MODELS_PATH
178
+ value : {{ .Values.deployment.modelsPath }}
107
179
volumeMounts :
108
- - mountPath : {{ .Values.deployment.modelsPath }}
109
- name : models
180
+ {{- range $key, $pvc := .Values.persistence }}
181
+ {{- if $pvc.enabled }}
182
+ - name : {{ $key }}
183
+ mountPath : {{ $pvc.globalMount | default (print "/" $key) }}
184
+ {{- end }}
185
+ {{- end }}
110
186
volumes :
111
- {{- if .Values.models.persistence.pvc.enabled }}
112
- - name : models
113
- persistentVolumeClaim :
114
- claimName : {{ template "local-ai.fullname" . }}
115
- {{- else if .Values.models.persistence.hostPath.enabled }}
116
- - name : models
117
- hostPath :
118
- path : {{ .Values.models.persistence.hostPath.path }}
119
- {{- else }}
120
- - name : models
121
- emptyDir : {}
122
- {{- end }}
123
- - name : prompt-templates
124
- configMap :
125
- name : {{ template "local-ai.fullname" . }}-prompt-templates
187
+ {{- range $key, $pvc := .Values.persistence }}
188
+ {{- if $pvc.enabled }}
189
+ - name : {{ $key }}
190
+ persistentVolumeClaim :
191
+ claimName : {{ printf "%s-%s" (include "local-ai.fullname" $) $key }}
192
+ {{- end }}
193
+ {{- end }}
194
+ - name : prompt-templates
195
+ configMap :
196
+ name : {{ template "local-ai.fullname" . }}-prompt-templates
126
197
{{- with .Values.nodeSelector }}
127
198
nodeSelector :
128
199
{{- toYaml . | nindent 8 }}
0 commit comments