/
volume.go
50 lines (43 loc) · 1.17 KB
/
volume.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
package controller
import (
"fmt"
"strings"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
)
var volumeCSIDriverFilter = []string{
"rook-ceph.cephfs.csi.ceph.com",
"rook-ceph.rbd.csi.ceph.com",
}
func deploymentHasClaim(deploy *appsv1.Deployment, claim *corev1.PersistentVolumeClaim) bool {
for _, volume := range deploy.Spec.Template.Spec.Volumes {
if spec := volume.PersistentVolumeClaim; spec != nil && spec.ClaimName == claim.Name {
return true
}
}
return false
}
func statefulSetHasClaim(sts *appsv1.StatefulSet, claim *corev1.PersistentVolumeClaim) bool {
for _, volume := range sts.Spec.Template.Spec.Volumes {
if spec := volume.PersistentVolumeClaim; spec != nil && spec.ClaimName == claim.Name {
return true
}
}
for _, template := range sts.Spec.VolumeClaimTemplates {
if strings.HasPrefix(claim.Name, stsClaimPrefix(sts.Name, template.Name)) {
return true
}
}
return false
}
func filterCSIDriver(name string) bool {
for _, driver := range volumeCSIDriverFilter {
if driver == name {
return true
}
}
return false
}
func stsClaimPrefix(stsName, claimName string) string {
return fmt.Sprintf("%s-%s-", claimName, stsName)
}