MCPcopy Index your code
hub / github.com/devspace-sh/devspace / persistPaths

Function persistPaths

pkg/devspace/services/podreplace/persist.go:19–120  ·  view source on GitHub ↗
(name string, devPod *latest.DevPod, podTemplate *corev1.PodTemplateSpec)

Source from the content-addressed store, hash-verified

17}
18
19func persistPaths(name string, devPod *latest.DevPod, podTemplate *corev1.PodTemplateSpec) error {
20 if devPod.PersistenceOptions != nil && devPod.PersistenceOptions.Name != "" {
21 name = devPod.PersistenceOptions.Name
22 }
23
24 paths := []containerPath{}
25 loader.EachDevContainer(devPod, func(devContainer *latest.DevContainer) bool {
26 for _, p := range devContainer.PersistPaths {
27 paths = append(paths, containerPath{
28 PersistentPath: p,
29 Container: devContainer.Container,
30 })
31 }
32 return true
33 })
34 if len(paths) == 0 {
35 return nil
36 }
37
38 for i, p := range paths {
39 if p.Path == "" {
40 continue
41 }
42
43 subPath := p.VolumePath
44 if subPath == "" {
45 subPath = fmt.Sprintf("path-%d", i)
46 }
47
48 if len(podTemplate.Spec.Containers) > 1 && p.Container == "" {
49 names := []string{}
50 for _, c := range podTemplate.Spec.Containers {
51 names = append(names, c.Name)
52 }
53
54 return fmt.Errorf("couldn't persist path %s as multiple containers were found %s, but no containerName was specified", p.Path, strings.Join(names, " "))
55 }
56
57 var container *corev1.Container
58 for i, con := range podTemplate.Spec.Containers {
59 if p.Container == "" || p.Container == con.Name {
60 podTemplate.Spec.Containers[i].VolumeMounts = append(podTemplate.Spec.Containers[i].VolumeMounts, corev1.VolumeMount{
61 Name: "devspace-persistence",
62 MountPath: p.Path,
63 SubPath: subPath,
64 ReadOnly: p.ReadOnly,
65 })
66
67 container = &con
68 break
69 }
70 }
71
72 if container == nil || p.SkipPopulate || p.ReadOnly || (devPod.PersistenceOptions != nil && devPod.PersistenceOptions.ReadOnly) {
73 continue
74 }
75
76 initContainer := corev1.Container{

Callers 1

buildDeploymentFunction · 0.85

Calls 2

EachDevContainerFunction · 0.92
ErrorfMethod · 0.45

Tested by

no test coverage detected