forked from weaveworks/scope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
volumesnapshot.go
60 lines (51 loc) · 1.72 KB
/
volumesnapshot.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
package kubernetes
import (
snapshotv1 "github.com/openebs/k8s-snapshot-client/snapshot/pkg/apis/volumesnapshot/v1"
"github.com/weaveworks/scope/report"
)
// SnapshotPVName is the label key which provides PV name
const (
SnapshotPVName = "SnapshotMetadata-PVName"
)
// Capacity is the annotation key which provides the storage size
const (
Capacity = "capacity"
)
// VolumeSnapshot represent kubernetes VolumeSnapshot interface
type VolumeSnapshot interface {
Meta
GetNode(probeID string) report.Node
GetVolumeName() string
GetCapacity() string
}
// volumeSnapshot represents kubernetes volume snapshots
type volumeSnapshot struct {
*snapshotv1.VolumeSnapshot
Meta
}
// NewVolumeSnapshot returns new Volume Snapshot type
func NewVolumeSnapshot(p *snapshotv1.VolumeSnapshot) VolumeSnapshot {
return &volumeSnapshot{VolumeSnapshot: p, Meta: meta{p.ObjectMeta}}
}
// GetVolumeName returns the PVC name for volume snapshot
func (p *volumeSnapshot) GetVolumeName() string {
return p.Spec.PersistentVolumeClaimName
}
// GetCapacity returns the capacity of the source PVC stored in annotation
func (p *volumeSnapshot) GetCapacity() string {
capacity := p.GetAnnotations()[Capacity]
if capacity != "" {
return capacity
}
return ""
}
// GetNode returns VolumeSnapshot as Node
func (p *volumeSnapshot) GetNode(probeID string) report.Node {
return p.MetaNode(report.MakeVolumeSnapshotNodeID(p.UID())).WithLatests(map[string]string{
report.ControlProbeID: probeID,
NodeType: "Volume Snapshot",
VolumeClaim: p.GetVolumeName(),
SnapshotData: p.Spec.SnapshotDataName,
VolumeName: p.GetLabels()[SnapshotPVName],
}).WithLatestActiveControls(CloneVolumeSnapshot, DeleteVolumeSnapshot, Describe)
}