forked from portworx/torpedo
/
volume.go
124 lines (94 loc) · 4.08 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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package volume
import (
"fmt"
"github.com/portworx/torpedo/drivers/node"
"github.com/portworx/torpedo/pkg/errors"
)
// Volume is a generic struct encapsulating volumes in the cluster
type Volume struct {
ID string
Name string
Namespace string
}
// Snapshot is a generic struct encapsulating snapshots in the cluster
type Snapshot struct {
ID string
Name string
Namespace string
}
// Driver defines an external volume driver interface that must be implemented
// by any external storage provider that wants to qualify their product with
// Torpedo. The functions defined here are meant to be destructive and illustrative
// of failure scenarious that can happen with an external storage provider.
type Driver interface {
// Init initializes the volume driver under the given scheduler
Init(sched string, nodeDriver string) error
// String returns the string name of this driver.
String() string
// CleanupVolume forcefully unmounts/detaches and deletes a storage volume.
// This is only called by Torpedo during cleanup operations, it is not
// used during orchestration simulations.
CleanupVolume(name string) error
// ValidateCreateVolume validates whether a volume has been created properly.
// params are the custom volume options passed when creating the volume.
ValidateCreateVolume(name string, params map[string]string) error
// ValidateDeleteVolume validates whether a volume is cleanly removed from the volume driver
ValidateDeleteVolume(vol *Volume) error
// ValidateVolumeCleanup checks if the necessary cleanup has happened for the volumes by this driver
ValidateVolumeCleanup() error
// ValidateVolumeSetup validates if the given volume is setup correctly in the cluster
ValidateVolumeSetup(vol *Volume) error
// Stop must cause the volume driver to exit on a given node. If force==true, the volume driver should get killed ungracefully
StopDriver(nodes []node.Node, force bool) error
// Start must cause the volume driver to start on a given node.
StartDriver(n node.Node) error
// WaitDriverUpOnNode must wait till the volume driver becomes usable on a given node
WaitDriverUpOnNode(n node.Node) error
// WaitDriverDownOnNode must wait till the volume driver becomes unusable on a given node
WaitDriverDownOnNode(n node.Node) error
// GetNodeForVolume returns the node on which the volume is attached
GetNodeForVolume(vol *Volume) (*node.Node, error)
// ExtractVolumeInfo extracts the volume params from the given string
ExtractVolumeInfo(params string) (string, map[string]string, error)
// UpgradeDriver upgrades the volume driver to the given version
UpgradeDriver(version string) error
// RandomizeVolumeName randomizes the volume name from the given name
RandomizeVolumeName(name string) string
// RecoverDriver will recover a volume driver from a failure/storage down state.
// This could be used by a volume driver to recover itself from any underlying storage
// failure.
RecoverDriver(n node.Node) error
// GetStorageDevices returns the list of storage devices used by the given node.
GetStorageDevices(n node.Node) ([]string, error)
// GetVolumeReplicationFactor returns the current replication factor of the volume.
GetReplicationFactor(vol *Volume) (int64, error)
// SetReplicationFactor sets the volume's replication factor to the passed param rf.
SetReplicationFactor(vol *Volume, rf int64) error
// GetMaxReplicationFactor returns the max supported repl factor of a volume
GetMaxReplicationFactor() int64
// GetMinReplicationFactor returns the min supported repl factor of a volume
GetMinReplicationFactor() int64
}
var (
volDrivers = make(map[string]Driver)
)
// Register registers the given volume driver
func Register(name string, d Driver) error {
if _, ok := volDrivers[name]; !ok {
volDrivers[name] = d
} else {
return fmt.Errorf("volume driver: %s is already registered", name)
}
return nil
}
// Get an external storage provider to be used with Torpedo.
func Get(name string) (Driver, error) {
d, ok := volDrivers[name]
if ok {
return d, nil
}
return nil, &errors.ErrNotFound{
ID: name,
Type: "VolumeDriver",
}
}