Skip to content

Commit b19f77d

Browse files
committed
api, config, db, storage, volsupervisor: Driver options as map[string]interface{}
Signed-off-by: Yuva Shankar <yuva.shankar29@gmail.com>
1 parent 64ca32a commit b19f77d

20 files changed

Lines changed: 335 additions & 106 deletions

api/impl/docker/docker_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/contiv/volplugin/api"
1515
"github.com/contiv/volplugin/config"
16+
"github.com/contiv/volplugin/storage"
1617

1718
. "gopkg.in/check.v1"
1819
)
@@ -70,7 +71,7 @@ func (s *dockerSuite) TestBasic(c *C) {
7071
err := s.client.PublishPolicy("policy1", &config.Policy{
7172
Name: "policy1",
7273
Backend: "ceph",
73-
DriverOptions: map[string]string{"pool": "rbd"},
74+
DriverOptions: storage.DriverParams{"pool": "rbd"},
7475
CreateOptions: config.CreateOptions{
7576
Size: "10MB",
7677
},

config/policy.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/contiv/errored"
77
"github.com/contiv/volplugin/errors"
8+
"github.com/contiv/volplugin/storage"
89
"github.com/coreos/etcd/client"
910
"golang.org/x/net/context"
1011
)
@@ -18,14 +19,14 @@ var defaultDrivers = map[string]*BackendDrivers{
1819
// Policy is the configuration of the policy. It includes default
1920
// information for items such as pool and volume configuration.
2021
type Policy struct {
21-
Name string `json:"name"`
22-
Unlocked bool `json:"unlocked,omitempty" merge:"unlocked"`
23-
CreateOptions CreateOptions `json:"create"`
24-
RuntimeOptions RuntimeOptions `json:"runtime"`
25-
DriverOptions map[string]string `json:"driver"`
26-
FileSystems map[string]string `json:"filesystems"`
27-
Backends *BackendDrivers `json:"backends,omitempty"`
28-
Backend string `json:"backend,omitempty"`
22+
Name string `json:"name"`
23+
Unlocked bool `json:"unlocked,omitempty" merge:"unlocked"`
24+
CreateOptions CreateOptions `json:"create"`
25+
RuntimeOptions RuntimeOptions `json:"runtime"`
26+
DriverOptions storage.DriverParams `json:"driver"`
27+
FileSystems map[string]string `json:"filesystems"`
28+
Backends *BackendDrivers `json:"backends,omitempty"`
29+
Backend string `json:"backend,omitempty"`
2930
}
3031

3132
// BackendDrivers is a struct containing all the drivers used under this policy

config/policy_test.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package config
22

3-
import . "gopkg.in/check.v1"
3+
import (
4+
"github.com/contiv/volplugin/storage"
5+
. "gopkg.in/check.v1"
6+
)
47

58
var testPolicies = map[string]*Policy{
69
"basic": {
@@ -10,7 +13,7 @@ var testPolicies = map[string]*Policy{
1013
Mount: "ceph",
1114
Snapshot: "ceph",
1215
},
13-
DriverOptions: map[string]string{"pool": "rbd"},
16+
DriverOptions: storage.DriverParams{"pool": "rbd"},
1417
CreateOptions: CreateOptions{
1518
Size: "10MB",
1619
FileSystem: defaultFilesystem,
@@ -31,7 +34,7 @@ var testPolicies = map[string]*Policy{
3134
Mount: "ceph",
3235
Snapshot: "ceph",
3336
},
34-
DriverOptions: map[string]string{"pool": "rbd"},
37+
DriverOptions: storage.DriverParams{"pool": "rbd"},
3538
CreateOptions: CreateOptions{
3639
Size: "20MB",
3740
FileSystem: defaultFilesystem,
@@ -45,7 +48,7 @@ var testPolicies = map[string]*Policy{
4548
Mount: "ceph",
4649
Snapshot: "ceph",
4750
},
48-
DriverOptions: map[string]string{"pool": "rbd"},
51+
DriverOptions: storage.DriverParams{"pool": "rbd"},
4952
CreateOptions: CreateOptions{
5053
Size: "0",
5154
FileSystem: defaultFilesystem,
@@ -59,7 +62,7 @@ var testPolicies = map[string]*Policy{
5962
Mount: "ceph",
6063
Snapshot: "ceph",
6164
},
62-
DriverOptions: map[string]string{"pool": "rbd"},
65+
DriverOptions: storage.DriverParams{"pool": "rbd"},
6366
CreateOptions: CreateOptions{
6467
Size: "20MB",
6568
FileSystem: defaultFilesystem,
@@ -73,7 +76,7 @@ var testPolicies = map[string]*Policy{
7376
Mount: "ceph",
7477
Snapshot: "ceph",
7578
},
76-
DriverOptions: map[string]string{"pool": "rbd"},
79+
DriverOptions: storage.DriverParams{"pool": "rbd"},
7780
CreateOptions: CreateOptions{
7881
Size: "not a number",
7982
FileSystem: defaultFilesystem,
@@ -87,7 +90,7 @@ var testPolicies = map[string]*Policy{
8790
Mount: "ceph",
8891
Snapshot: "ceph",
8992
},
90-
DriverOptions: map[string]string{"pool": "rbd"},
93+
DriverOptions: storage.DriverParams{"pool": "rbd"},
9194
CreateOptions: CreateOptions{
9295
Size: "10MB",
9396
FileSystem: defaultFilesystem,
@@ -106,7 +109,7 @@ var testPolicies = map[string]*Policy{
106109
Mount: "ceph",
107110
},
108111
Name: "blanksize",
109-
DriverOptions: map[string]string{"pool": "rbd"},
112+
DriverOptions: storage.DriverParams{"pool": "rbd"},
110113
CreateOptions: CreateOptions{
111114
FileSystem: defaultFilesystem,
112115
},
@@ -119,7 +122,7 @@ var testPolicies = map[string]*Policy{
119122
Mount: "ceph",
120123
},
121124
Name: "blanksize",
122-
DriverOptions: map[string]string{"pool": "rbd"},
125+
DriverOptions: storage.DriverParams{"pool": "rbd"},
123126
CreateOptions: CreateOptions{
124127
FileSystem: defaultFilesystem,
125128
},
@@ -128,7 +131,7 @@ var testPolicies = map[string]*Policy{
128131
},
129132
"nobackend": {
130133
Name: "nobackend",
131-
DriverOptions: map[string]string{"pool": "rbd"},
134+
DriverOptions: storage.DriverParams{"pool": "rbd"},
132135
CreateOptions: CreateOptions{
133136
Size: "10MB",
134137
FileSystem: defaultFilesystem,

config/validation_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
package config
22

3-
import . "gopkg.in/check.v1"
3+
import (
4+
"github.com/contiv/volplugin/storage"
5+
. "gopkg.in/check.v1"
6+
)
47

58
var (
69
defaultBackends = &BackendDrivers{CRUD: "ceph", Mount: "ceph", Snapshot: "ceph"}
710
VolumeConfigs = map[string]map[string]*Volume{
811
"valid": {
912
"basic": {
10-
DriverOptions: map[string]string{"pool": "rbd"},
13+
DriverOptions: storage.DriverParams{"pool": "rbd"},
1114
CreateOptions: CreateOptions{Size: "10MB"},
1215
RuntimeOptions: RuntimeOptions{UseSnapshots: false},
1316
VolumeName: "basicvolume",
1417
PolicyName: "basicpolicy",
1518
Backends: defaultBackends,
1619
},
1720
"basicwithruntime": {
18-
DriverOptions: map[string]string{"pool": "rbd"},
21+
DriverOptions: storage.DriverParams{"pool": "rbd"},
1922
CreateOptions: CreateOptions{Size: "10MB"},
2023
RuntimeOptions: RuntimeOptions{UseSnapshots: true, Snapshot: SnapshotConfig{Frequency: "10m", Keep: 10}},
2124
VolumeName: "basicvolume",

config/volume.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ import (
2222
// Volume is the configuration of the policy. It includes pool and
2323
// snapshot information.
2424
type Volume struct {
25-
PolicyName string `json:"policy"`
26-
VolumeName string `json:"name"`
27-
Unlocked bool `json:"unlocked,omitempty" merge:"unlocked"`
28-
DriverOptions map[string]string `json:"driver"`
29-
MountSource string `json:"mount" merge:"mount"`
30-
CreateOptions CreateOptions `json:"create"`
31-
RuntimeOptions RuntimeOptions `json:"runtime"`
32-
Backends *BackendDrivers `json:"backends,omitempty"`
25+
PolicyName string `json:"policy"`
26+
VolumeName string `json:"name"`
27+
Unlocked bool `json:"unlocked,omitempty" merge:"unlocked"`
28+
DriverOptions storage.DriverParams `json:"driver"`
29+
MountSource string `json:"mount" merge:"mount"`
30+
CreateOptions CreateOptions `json:"create"`
31+
RuntimeOptions RuntimeOptions `json:"runtime"`
32+
Backends *BackendDrivers `json:"backends,omitempty"`
3333
}
3434

3535
// CreateOptions are the set of options used by apiserver during the volume
@@ -102,7 +102,7 @@ func (c *Client) CreateVolume(rc *VolumeRequest) (*Volume, error) {
102102
}
103103

104104
if resp.DriverOptions == nil {
105-
resp.DriverOptions = map[string]string{}
105+
resp.DriverOptions = storage.DriverParams{}
106106
}
107107

108108
if err := resp.Validate(); err != nil {

config/volume_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (s *configSuite) TestVolumeValidate(c *C) {
4545
c.Assert(vc.Validate(), NotNil)
4646

4747
vc = &Volume{
48-
DriverOptions: map[string]string{"pool": "rbd"},
48+
DriverOptions: storage.DriverParams{"pool": "rbd"},
4949
CreateOptions: CreateOptions{Size: "10MB"},
5050
RuntimeOptions: RuntimeOptions{UseSnapshots: false},
5151
VolumeName: "",
@@ -55,7 +55,7 @@ func (s *configSuite) TestVolumeValidate(c *C) {
5555
c.Assert(vc.Validate(), NotNil)
5656

5757
vc = &Volume{
58-
DriverOptions: map[string]string{"pool": "rbd"},
58+
DriverOptions: storage.DriverParams{"pool": "rbd"},
5959
CreateOptions: CreateOptions{Size: "10MB"},
6060
RuntimeOptions: RuntimeOptions{UseSnapshots: false},
6161
VolumeName: "foo",
@@ -70,7 +70,7 @@ func (s *configSuite) TestVolumeValidate(c *C) {
7070
Snapshot: "ceph",
7171
CRUD: "ceph",
7272
},
73-
DriverOptions: map[string]string{"pool": "rbd"},
73+
DriverOptions: storage.DriverParams{"pool": "rbd"},
7474
CreateOptions: CreateOptions{Size: "10MB"},
7575
RuntimeOptions: RuntimeOptions{UseSnapshots: false},
7676
VolumeName: "foo",
@@ -229,7 +229,7 @@ func (s *configSuite) TestToDriverOptions(c *C) {
229229
Volume: storage.Volume{
230230
Name: "policy1/test",
231231
Size: 0xa,
232-
Params: storage.Params{"pool": "rbd"},
232+
Params: storage.DriverParams{"pool": "rbd"},
233233
},
234234
FSOptions: storage.FSOptions{
235235
Type: "ext4",

db/structs.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@ package db
22

33
import (
44
"time"
5+
6+
"github.com/contiv/volplugin/storage"
57
)
68

79
// Policy is the configuration of the policy. It includes default
810
// information for items such as pool and volume configuration.
911
type Policy struct {
10-
Name string `json:"name"`
11-
Unlocked bool `json:"unlocked,omitempty" merge:"unlocked"`
12-
CreateOptions CreateOptions `json:"create"`
13-
RuntimeOptions *RuntimeOptions `json:"runtime"`
14-
DriverOptions map[string]string `json:"driver"`
15-
FileSystems map[string]string `json:"filesystems"`
16-
Backends *BackendDrivers `json:"backends,omitempty"`
17-
Backend string `json:"backend,omitempty"`
12+
Name string `json:"name"`
13+
Unlocked bool `json:"unlocked,omitempty" merge:"unlocked"`
14+
CreateOptions CreateOptions `json:"create"`
15+
RuntimeOptions *RuntimeOptions `json:"runtime"`
16+
DriverOptions storage.DriverParams `json:"driver"`
17+
FileSystems map[string]string `json:"filesystems"`
18+
Backends *BackendDrivers `json:"backends,omitempty"`
19+
Backend string `json:"backend,omitempty"`
1820
}
1921

2022
// BackendDrivers is a struct containing all the drivers used under this policy
@@ -61,14 +63,14 @@ type UseSnapshot struct {
6163
// Volume is the configuration of the policy. It includes pool and
6264
// snapshot information.
6365
type Volume struct {
64-
PolicyName string `json:"policy"`
65-
VolumeName string `json:"name"`
66-
Unlocked bool `json:"unlocked,omitempty" merge:"unlocked"`
67-
DriverOptions map[string]string `json:"driver"`
68-
MountSource string `json:"mount" merge:"mount"`
69-
CreateOptions CreateOptions `json:"create"`
70-
RuntimeOptions *RuntimeOptions `json:"runtime"`
71-
Backends *BackendDrivers `json:"backends,omitempty"`
66+
PolicyName string `json:"policy"`
67+
VolumeName string `json:"name"`
68+
Unlocked bool `json:"unlocked,omitempty" merge:"unlocked"`
69+
DriverOptions storage.DriverParams `json:"driver"`
70+
MountSource string `json:"mount" merge:"mount"`
71+
CreateOptions CreateOptions `json:"create"`
72+
RuntimeOptions *RuntimeOptions `json:"runtime"`
73+
Backends *BackendDrivers `json:"backends,omitempty"`
7274
}
7375

7476
// CreateOptions are the set of options used by apiserver during the volume

db/test/policy_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package test
22

33
import (
44
"github.com/contiv/volplugin/db"
5+
"github.com/contiv/volplugin/storage"
56
. "gopkg.in/check.v1"
67
)
78

@@ -13,7 +14,7 @@ var testPolicies = map[string]*db.Policy{
1314
Mount: "ceph",
1415
Snapshot: "ceph",
1516
},
16-
DriverOptions: map[string]string{"pool": "rbd"},
17+
DriverOptions: storage.DriverParams{"pool": "rbd"},
1718
CreateOptions: db.CreateOptions{
1819
Size: "10MB",
1920
FileSystem: db.DefaultFilesystem,
@@ -34,7 +35,7 @@ var testPolicies = map[string]*db.Policy{
3435
Mount: "ceph",
3536
Snapshot: "ceph",
3637
},
37-
DriverOptions: map[string]string{"pool": "rbd"},
38+
DriverOptions: storage.DriverParams{"pool": "rbd"},
3839
CreateOptions: db.CreateOptions{
3940
Size: "20MB",
4041
FileSystem: db.DefaultFilesystem,
@@ -49,7 +50,7 @@ var testPolicies = map[string]*db.Policy{
4950
Mount: "ceph",
5051
Snapshot: "ceph",
5152
},
52-
DriverOptions: map[string]string{"pool": "rbd"},
53+
DriverOptions: storage.DriverParams{"pool": "rbd"},
5354
CreateOptions: db.CreateOptions{
5455
Size: "0",
5556
FileSystem: db.DefaultFilesystem,
@@ -63,7 +64,7 @@ var testPolicies = map[string]*db.Policy{
6364
Mount: "ceph",
6465
Snapshot: "ceph",
6566
},
66-
DriverOptions: map[string]string{"pool": "rbd"},
67+
DriverOptions: storage.DriverParams{"pool": "rbd"},
6768
CreateOptions: db.CreateOptions{
6869
Size: "not a number",
6970
FileSystem: db.DefaultFilesystem,
@@ -77,7 +78,7 @@ var testPolicies = map[string]*db.Policy{
7778
Mount: "ceph",
7879
Snapshot: "ceph",
7980
},
80-
DriverOptions: map[string]string{"pool": "rbd"},
81+
DriverOptions: storage.DriverParams{"pool": "rbd"},
8182
CreateOptions: db.CreateOptions{
8283
Size: "10MB",
8384
FileSystem: db.DefaultFilesystem,
@@ -96,7 +97,7 @@ var testPolicies = map[string]*db.Policy{
9697
Mount: "ceph",
9798
},
9899
Name: "blanksize",
99-
DriverOptions: map[string]string{"pool": "rbd"},
100+
DriverOptions: storage.DriverParams{"pool": "rbd"},
100101
CreateOptions: db.CreateOptions{
101102
FileSystem: db.DefaultFilesystem,
102103
},
@@ -109,7 +110,7 @@ var testPolicies = map[string]*db.Policy{
109110
Mount: "ceph",
110111
},
111112
Name: "blanksize",
112-
DriverOptions: map[string]string{"pool": "rbd"},
113+
DriverOptions: storage.DriverParams{"pool": "rbd"},
113114
CreateOptions: db.CreateOptions{
114115
FileSystem: db.DefaultFilesystem,
115116
},
@@ -118,7 +119,7 @@ var testPolicies = map[string]*db.Policy{
118119
},
119120
"nobackend": {
120121
Name: "nobackend",
121-
DriverOptions: map[string]string{"pool": "rbd"},
122+
DriverOptions: storage.DriverParams{"pool": "rbd"},
122123
CreateOptions: db.CreateOptions{
123124
Size: "10MB",
124125
FileSystem: db.DefaultFilesystem,

0 commit comments

Comments
 (0)