forked from portworx/torpedo
/
schedops.go
64 lines (56 loc) · 2.25 KB
/
schedops.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
package schedops
import (
"fmt"
"github.com/libopenstorage/openstorage/api"
"github.com/portworx/torpedo/drivers/node"
"github.com/portworx/torpedo/drivers/volume"
"github.com/portworx/torpedo/pkg/errors"
)
// Driver is the interface for portworx operations under various schedulers
type Driver interface {
// ValidateOnNode validates portworx on given node (from scheduler perspective)
ValidateOnNode(n node.Node) error
// ValidateAddLabels validates whether the labels for the volume are applied appropriately on the vol replica nodes
ValidateAddLabels(replicaNodes []api.Node, v *api.Volume) error
// ValidateRemoveLabels validates whether the volume labels have been removed
ValidateRemoveLabels(v *volume.Volume) error
// ValidateVolumeCleanup validates that volume dir does not exist and no data present inside it
ValidateVolumeCleanup(d node.Driver) error
// ValidateVolumeSetup checks if the given volume is setup correctly
ValidateVolumeSetup(v *volume.Volume) error
// ValidateSnapshot validates the snapshot volume
ValidateSnapshot(volumeParams map[string]string, parent *api.Volume) error
// GetVolumeName returns the volume name based on the volume object recevied
GetVolumeName(v *volume.Volume) string
// GetServiceEndpoint returns the hostname of portworx service if it is present
GetServiceEndpoint() (string, error)
// UpgradePortworx upgrades portworx to the given docker image and tag
UpgradePortworx(image, tag string) error
// IsPXReadyOnNode returns true if PX pod is up on that node, else returns false
IsPXReadyOnNode(n node.Node) bool
// IsPXEnabled returns true if portworx is enabled on given node
IsPXEnabled(n node.Node) (bool, error)
}
var (
schedOpsRegistry = make(map[string]Driver)
)
// Register registers the given portworx scheduler operator
func Register(name string, d Driver) error {
if _, ok := schedOpsRegistry[name]; !ok {
schedOpsRegistry[name] = d
} else {
return fmt.Errorf("portworx scheduler ops driver: %s is already registered", name)
}
return nil
}
// Get a driver to perform portworx operations for the given scheduler
func Get(name string) (Driver, error) {
d, ok := schedOpsRegistry[name]
if ok {
return d, nil
}
return nil, &errors.ErrNotFound{
ID: name,
Type: "Portworx Scheduler Operator",
}
}