-
Notifications
You must be signed in to change notification settings - Fork 12
/
init_container.go
54 lines (45 loc) · 1.38 KB
/
init_container.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package kubernetes
import (
"fmt"
"strings"
"github.com/loft-sh/devpod/pkg/driver"
corev1 "k8s.io/api/core/v1"
)
func (k *KubernetesDriver) getInitContainer(options *driver.RunOptions) ([]corev1.Container, error) {
commands := []string{}
// find the volume type mounts
volumeMounts := []corev1.VolumeMount{}
for idx, mount := range options.Mounts {
if mount.Type != "volume" {
continue
}
volumeMount := getVolumeMount(idx+1, mount)
copyFrom := volumeMount.MountPath
volumeMount.MountPath = "/" + volumeMount.SubPath
volumeMounts = append(volumeMounts, volumeMount)
commands = append(commands, fmt.Sprintf(`cp -a %s/. %s/ || true`, strings.TrimRight(copyFrom, "/"), strings.TrimRight(volumeMount.MountPath, "/")))
}
// check if there is at least one mount
if len(volumeMounts) == 0 {
return nil, nil
}
securityContext := &corev1.SecurityContext{
RunAsUser: &[]int64{0}[0],
RunAsGroup: &[]int64{0}[0],
RunAsNonRoot: &[]bool{false}[0],
}
if k.options.StrictSecurity {
securityContext = nil
}
return []corev1.Container{
{
Name: "devpod-init",
Image: options.Image,
Command: []string{"sh"},
Args: []string{"-c", strings.Join(commands, "\n") + "\n"},
Resources: parseResources(k.options.HelperResources, k.Log),
VolumeMounts: volumeMounts,
SecurityContext: securityContext,
},
}, nil
}