/
short_circuit.go
71 lines (60 loc) · 1.83 KB
/
short_circuit.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
package worker
import (
alluxiov1alpha1 "github.com/zncdata-labs/alluxio-operator/api/v1alpha1"
corev1 "k8s.io/api/core/v1"
k8sResource "k8s.io/apimachinery/pkg/api/resource"
)
func VolumeSourceFromShortCircuit(shortCircuit alluxiov1alpha1.ShortCircuitSpec, roleGroupName string) corev1.VolumeSource {
switch shortCircuit.VolumeType {
case "hostPath":
return HostPathVolumeSource(shortCircuit.HosePath)
case "persistentVolumeClaim":
return PvcVolumeSource(createPvcName(shortCircuit.PvcName, roleGroupName))
default:
panic("Unknown volume type")
}
}
func MakeShortCircuitVolumes(instance *alluxiov1alpha1.AlluxioCluster, roleGroupName string) []corev1.Volume {
shortCircuit := instance.Spec.ClusterConfig.GetShortCircuit()
var volumes []corev1.Volume
volume := corev1.Volume{
Name: "alluxio-domain",
VolumeSource: VolumeSourceFromShortCircuit(shortCircuit, roleGroupName),
}
volumes = append(volumes, volume)
return volumes
}
func MakeShortCircuitVolumeMounts() []corev1.VolumeMount {
var mounts []corev1.VolumeMount
mount := corev1.VolumeMount{
Name: "alluxio-domain",
MountPath: "/opt/domain",
}
mounts = append(mounts, mount)
return mounts
}
func EmptyDirVolumeSource(quota string) corev1.VolumeSource {
sizeLimit := k8sResource.MustParse(quota)
return corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{
Medium: "Memory",
SizeLimit: &sizeLimit,
},
}
}
func HostPathVolumeSource(path string) corev1.VolumeSource {
hostPathType := corev1.HostPathType("DirectoryOrCreate")
return corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
Path: path,
Type: &hostPathType,
},
}
}
func PvcVolumeSource(claimName string) corev1.VolumeSource {
return corev1.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: claimName,
},
}
}