-
Notifications
You must be signed in to change notification settings - Fork 0
/
volumeattachment.go
89 lines (78 loc) · 2.57 KB
/
volumeattachment.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
package sources
import (
"github.com/overmindtech/discovery"
"github.com/overmindtech/sdp-go"
v1 "k8s.io/api/storage/v1"
"k8s.io/client-go/kubernetes"
)
func volumeAttachmentExtractor(resource *v1.VolumeAttachment, scope string) ([]*sdp.LinkedItemQuery, error) {
queries := make([]*sdp.LinkedItemQuery, 0)
if resource.Spec.Source.PersistentVolumeName != nil {
// +overmind:link PersistentVolume
queries = append(queries, &sdp.LinkedItemQuery{
Query: &sdp.Query{
Type: "PersistentVolume",
Method: sdp.QueryMethod_GET,
Query: *resource.Spec.Source.PersistentVolumeName,
Scope: scope,
},
BlastPropagation: &sdp.BlastPropagation{
// Changes to the PV could affect the attachment and vice versa
In: true,
Out: true,
},
})
}
if resource.Spec.NodeName != "" {
// +overmind:link Node
queries = append(queries, &sdp.LinkedItemQuery{
Query: &sdp.Query{
Type: "Node",
Method: sdp.QueryMethod_GET,
Query: resource.Spec.NodeName,
Scope: scope,
},
BlastPropagation: &sdp.BlastPropagation{
// Changes to the node could affect the attachment and vice
// versa
In: true,
Out: true,
},
})
}
return queries, nil
}
//go:generate docgen ../docs-data
// +overmind:type VolumeAttachment
// +overmind:descriptiveType Volume Attachment
// +overmind:get Get a volume attachment by name
// +overmind:list List all volume attachments
// +overmind:search Search for a volume attachment using the ListOptions JSON format: https://github.com/overmindtech/k8s-source#search
// +overmind:group Kubernetes
func newVolumeAttachmentSource(cs *kubernetes.Clientset, cluster string, namespaces []string) discovery.Source {
return &KubeTypeSource[*v1.VolumeAttachment, *v1.VolumeAttachmentList]{
ClusterName: cluster,
Namespaces: namespaces,
TypeName: "VolumeAttachment",
ClusterInterfaceBuilder: func() ItemInterface[*v1.VolumeAttachment, *v1.VolumeAttachmentList] {
return cs.StorageV1().VolumeAttachments()
},
ListExtractor: func(list *v1.VolumeAttachmentList) ([]*v1.VolumeAttachment, error) {
extracted := make([]*v1.VolumeAttachment, len(list.Items))
for i := range list.Items {
extracted[i] = &list.Items[i]
}
return extracted, nil
},
LinkedItemQueryExtractor: volumeAttachmentExtractor,
HealthExtractor: func(resource *v1.VolumeAttachment) *sdp.Health {
if resource.Status.AttachError != nil || resource.Status.DetachError != nil {
return sdp.Health_HEALTH_ERROR.Enum()
}
return sdp.Health_HEALTH_OK.Enum()
},
}
}
func init() {
registerSourceLoader(newVolumeAttachmentSource)
}