-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.go
107 lines (97 loc) · 2.3 KB
/
helpers.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package kubevolumes
import (
v1 "k8s.io/api/core/v1"
)
func NewVolumeMount(name, path string, readOnly bool) v1.VolumeMount {
return v1.VolumeMount{
Name: name,
MountPath: path,
ReadOnly: readOnly,
}
}
func NewVolumeSubPathMount(name, path string, subPath string, readOnly bool) v1.VolumeMount {
return v1.VolumeMount{
Name: name,
MountPath: path,
SubPath: subPath,
ReadOnly: readOnly,
}
}
func NewVolumeFromSecret(name, secretName string) v1.Volume {
return NewVolumeFromSecretOptional(name, secretName, false)
}
func NewVolumeFromSecretOptional(name, secretName string, optional bool) v1.Volume {
return v1.Volume{
Name: name,
VolumeSource: v1.VolumeSource{
Secret: &v1.SecretVolumeSource{
SecretName: secretName,
Optional: &optional,
},
},
}
}
func NewProjectedVolumeFromSecrets(name string, secretNames ...string) v1.Volume {
sources := make([]v1.VolumeProjection, 0, len(secretNames))
for _, secretName := range secretNames {
sources = append(sources, v1.VolumeProjection{
Secret: &v1.SecretProjection{
LocalObjectReference: v1.LocalObjectReference{
Name: secretName,
},
},
})
}
var defaultMode int32 = 0600
return v1.Volume{
Name: name,
VolumeSource: v1.VolumeSource{
Projected: &v1.ProjectedVolumeSource{
Sources: sources,
DefaultMode: &defaultMode,
},
},
}
}
func NewVolumeFromConfigMap(name, configName string) v1.Volume {
return v1.Volume{
Name: name,
VolumeSource: v1.VolumeSource{
ConfigMap: &v1.ConfigMapVolumeSource{
LocalObjectReference: v1.LocalObjectReference{
Name: configName,
},
},
},
}
}
func NewHostPathVolume(name, hostPath string, mountType v1.HostPathType) v1.Volume {
return v1.Volume{
Name: name,
VolumeSource: v1.VolumeSource{
HostPath: &v1.HostPathVolumeSource{
Path: hostPath,
Type: &mountType,
},
},
}
}
func NewEmptyDirVolume(name string) v1.Volume {
return v1.Volume{
Name: name,
VolumeSource: v1.VolumeSource{
EmptyDir: &v1.EmptyDirVolumeSource{},
},
}
}
func NewPersistentVolumeClaimVolume(name, claimName string, readOnly bool) v1.Volume {
return v1.Volume{
Name: name,
VolumeSource: v1.VolumeSource{
PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{
ClaimName: claimName,
ReadOnly: readOnly,
},
},
}
}