@@ -16,6 +16,7 @@ import (
1616 "os/exec"
1717 "reflect"
1818 "regexp"
19+ "strings"
1920 "time"
2021)
2122
@@ -54,8 +55,8 @@ type container struct {
5455 Command , Args []string
5556 Env , EnvFrom []json.RawMessage
5657 VolumeMounts []struct {
57- Name , MountPath , SubPath string
58- ReadOnly bool
58+ Name , MountPath , SubPath , SubPathExpr string
59+ ReadOnly bool
5960 }
6061}
6162type pod struct {
@@ -67,8 +68,12 @@ type pod struct {
6768 InitContainers []container
6869 Volumes []struct {
6970 Name string
70- ConfigMap * struct { Name string }
71- EmptyDir * struct { Medium , SizeLimit string }
71+ ConfigMap * struct {
72+ Name string
73+ Items []json.RawMessage
74+ Optional bool
75+ }
76+ EmptyDir * struct { Medium , SizeLimit string }
7277 }
7378 }
7479 Status struct {
@@ -259,7 +264,7 @@ func bindPod(b []byte) (binding, bool, bool, error) {
259264
260265func bindDatastoreMount (p pod , c container ) (string , bool ) {
261266 for _ , mount := range c .VolumeMounts {
262- if mount .MountPath != "/etc/stalwart/config.json" || mount .SubPath != "config.json" || ! mount .ReadOnly {
267+ if mount .MountPath != "/etc/stalwart/config.json" || mount .SubPath != "config.json" || mount . SubPathExpr != "" || ! mount .ReadOnly {
263268 continue
264269 }
265270 for _ , volume := range p .Spec .Volumes {
@@ -288,9 +293,9 @@ func bindStorageSelector(p pod) (string, bool) {
288293 continue
289294 }
290295 if init .Name != "select-mail-store" || init .Image != approvedRoutedImage || mount .MountPath != "/store-selection" ||
291- mount .SubPath != "" || len (init .Env ) != 0 || len (init .EnvFrom ) != 0 ||
296+ mount .SubPath != "" || mount . SubPathExpr != "" || len (init .Env ) != 0 || len (init .EnvFrom ) != 0 ||
292297 ! reflect .DeepEqual (init .Command , []string {"/usr/bin/sh" , "-c" }) || len (init .Args ) != 1 ||
293- hashBytes ([]byte (init .Args [0 ])) != approvedStorageSelectorSHA {
298+ hashBytes ([]byte (init .Args [0 ])) != approvedStorageSelectorSHA || ! bindStorageTemplate ( p , init ) {
294299 return "" , false
295300 }
296301 writers ++
@@ -314,6 +319,33 @@ func bindStorageSelector(p pod) (string, bool) {
314319 return selector , selector != ""
315320}
316321
322+ func bindStorageTemplate (p pod , init container ) bool {
323+ const path = "/etc/private-mail-datastore"
324+ matches := 0
325+ for _ , mount := range init .VolumeMounts {
326+ if strings .HasPrefix (mount .MountPath , path + "/" ) {
327+ return false
328+ }
329+ if mount .MountPath != path {
330+ continue
331+ }
332+ if mount .Name != "datastore" || ! mount .ReadOnly || mount .SubPath != "" || mount .SubPathExpr != "" {
333+ return false
334+ }
335+ matches ++
336+ }
337+ if matches != 1 {
338+ return false
339+ }
340+ for _ , volume := range p .Spec .Volumes {
341+ if volume .Name == "datastore" {
342+ source := volume .ConfigMap
343+ return source != nil && source .Name == "private-mail-datastore" && len (source .Items ) == 0 && ! source .Optional
344+ }
345+ }
346+ return false
347+ }
348+
317349// statusFor refuses duplicate identities, independent of Kubernetes list ordering.
318350func statusFor (p pod , name string ) (containerStatus , bool ) {
319351 var result containerStatus
0 commit comments