Skip to content

Commit c385680

Browse files
committed
feat(controller-sdk-go): volume support nfs
1 parent 6ad12c9 commit c385680

6 files changed

Lines changed: 136 additions & 42 deletions

File tree

api/volumes.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ type Volume struct {
2727
Name string `json:"name,omitempty"`
2828
//Volume's size
2929
Size string `json:"size,omitempty"`
30-
// mount application's path
30+
// Volume's mount path
3131
Path map[string]interface{} `json:"path,omitempty"`
32+
// Volume's type
33+
Type string `json:"type,omitempty"`
34+
// Volume's parameters
35+
Parameters map[string]interface{} `json:"parameters,omitempty"`
3236
}
3337

3438
type Volumes []Volume

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module github.com/drycc/controller-sdk-go
22

3-
go 1.20
3+
go 1.22
44

5-
require golang.org/x/net v0.17.0
5+
require golang.org/x/net v0.21.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
2-
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
1+
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
2+
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=

releases/releases.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func Get(c *drycc.Client, appID string, version int) (api.Release, error) {
4242
return api.Release{}, err
4343
}
4444

45-
return release, reqErr
45+
return release, nil
4646
}
4747

4848
// Rollback rolls back an app to a previous release. If version is -1, this rolls back to

volumes/volumes.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,23 @@ func List(c *drycc.Client, appID string, results int) (api.Volumes, int, error)
2323
return volumes, count, reqErr
2424
}
2525

26+
// Get an app's volume.
27+
func Get(c *drycc.Client, appID string, name string) (api.Volume, error) {
28+
u := fmt.Sprintf("/v2/apps/%s/volumes/%s/", appID, name)
29+
res, reqErr := c.Request("GET", u, nil)
30+
if reqErr != nil && !drycc.IsErrAPIMismatch(reqErr) {
31+
return api.Volume{}, reqErr
32+
}
33+
defer res.Body.Close()
34+
35+
volume := api.Volume{}
36+
if err := json.NewDecoder(res.Body).Decode(&volume); err != nil {
37+
return volume, err
38+
}
39+
40+
return volume, nil
41+
}
42+
2643
// Create create an app's Volume.
2744
func Create(c *drycc.Client, appID string, volume api.Volume) (api.Volume, error) {
2845
body, err := json.Marshal(volume)

volumes/volumes_test.go

Lines changed: 109 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const volumeCreateFixture string = `
2222
"name": "myvolume",
2323
"size": "500G",
2424
"path": {},
25+
"type": "csi",
26+
"parameters": {},
2527
"created": "2020-08-26T00:00:00UTC",
2628
"updated": "2020-08-26T00:00:00UTC"
2729
}
@@ -37,6 +39,8 @@ const volumeExpandFixture string = `
3739
"name": "myvolume",
3840
"size": "500G",
3941
"path": {},
42+
"type": "csi",
43+
"parameters": {},
4044
"created": "2020-08-26T00:00:00UTC",
4145
"updated": "2020-08-26T00:00:00UTC"
4246
}
@@ -55,13 +59,30 @@ const volumesFixture string = `
5559
"name": "myvolume",
5660
"size": "500G",
5761
"path": {},
62+
"type": "csi",
63+
"parameters": {},
5864
"created": "2020-08-26T00:00:00UTC",
5965
"updated": "2020-08-26T00:00:00UTC"
6066
}
6167
]
6268
}
6369
`
6470

71+
const volumeGetFixture string = `
72+
{
73+
"uuid": "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75",
74+
"owner": "test",
75+
"app": "example-go",
76+
"name": "myvolume",
77+
"size": "500G",
78+
"path": {},
79+
"type": "csi",
80+
"parameters": {},
81+
"created": "2020-08-26T00:00:00UTC",
82+
"updated": "2020-08-26T00:00:00UTC"
83+
}
84+
`
85+
6586
const volumeMountFixture string = `
6687
{
6788
"uuid": "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75",
@@ -73,6 +94,8 @@ const volumeMountFixture string = `
7394
"cmd": "/data/cmd1",
7495
"web": "/data/web1"
7596
},
97+
"type": "csi",
98+
"parameters": {},
7699
"created": "2020-08-26T00:00:00UTC",
77100
"updated": "2020-08-26T00:00:00UTC"
78101
}
@@ -86,6 +109,8 @@ const volumeUnmountFixture string = `
86109
"name": "myvolume",
87110
"size": "500G",
88111
"path": {},
112+
"type": "csi",
113+
"parameters": {},
89114
"created": "2020-08-26T00:00:00UTC",
90115
"updated": "2020-08-26T00:00:00UTC"
91116
}
@@ -121,6 +146,11 @@ func (f *fakeHTTPServer) ServeHTTP(res http.ResponseWriter, req *http.Request) {
121146
return
122147
}
123148

149+
if req.URL.Path == "/v2/apps/example-go/volumes/myvolume/" && req.Method == "GET" {
150+
res.Write([]byte(volumeGetFixture))
151+
return
152+
}
153+
124154
// Expand
125155
if req.URL.Path == "/v2/apps/example-go/volumes/myvolume/" && req.Method == "PATCH" {
126156
body, err := io.ReadAll(req.Body)
@@ -205,14 +235,16 @@ func TestVolumesCreate(t *testing.T) {
205235
t.Parallel()
206236

207237
expected := api.Volume{
208-
UUID: "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75",
209-
Owner: "test",
210-
App: "example-go",
211-
Name: "myvolume",
212-
Size: "500G",
213-
Path: map[string]interface{}{},
214-
Created: "2020-08-26T00:00:00UTC",
215-
Updated: "2020-08-26T00:00:00UTC",
238+
UUID: "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75",
239+
Owner: "test",
240+
App: "example-go",
241+
Name: "myvolume",
242+
Size: "500G",
243+
Path: map[string]interface{}{},
244+
Type: "csi",
245+
Parameters: map[string]interface{}{},
246+
Created: "2020-08-26T00:00:00UTC",
247+
Updated: "2020-08-26T00:00:00UTC",
216248
}
217249

218250
handler := fakeHTTPServer{}
@@ -242,14 +274,16 @@ func TestVolumesExpand(t *testing.T) {
242274
t.Parallel()
243275

244276
expected := api.Volume{
245-
UUID: "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75",
246-
Owner: "test",
247-
App: "example-go",
248-
Name: "myvolume",
249-
Size: "500G",
250-
Path: map[string]interface{}{},
251-
Created: "2020-08-26T00:00:00UTC",
252-
Updated: "2020-08-26T00:00:00UTC",
277+
UUID: "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75",
278+
Owner: "test",
279+
App: "example-go",
280+
Name: "myvolume",
281+
Size: "500G",
282+
Path: map[string]interface{}{},
283+
Type: "csi",
284+
Parameters: map[string]interface{}{},
285+
Created: "2020-08-26T00:00:00UTC",
286+
Updated: "2020-08-26T00:00:00UTC",
253287
}
254288

255289
handler := fakeHTTPServer{}
@@ -297,14 +331,16 @@ func TestVolumesList(t *testing.T) {
297331

298332
expected := api.Volumes{
299333
{
300-
UUID: "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75",
301-
App: "example-go",
302-
Owner: "test",
303-
Name: "myvolume",
304-
Path: map[string]interface{}{},
305-
Size: "500G",
306-
Created: "2020-08-26T00:00:00UTC",
307-
Updated: "2020-08-26T00:00:00UTC",
334+
UUID: "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75",
335+
App: "example-go",
336+
Owner: "test",
337+
Name: "myvolume",
338+
Path: map[string]interface{}{},
339+
Size: "500G",
340+
Type: "csi",
341+
Parameters: map[string]interface{}{},
342+
Created: "2020-08-26T00:00:00UTC",
343+
Updated: "2020-08-26T00:00:00UTC",
308344
},
309345
}
310346

@@ -328,6 +364,39 @@ func TestVolumesList(t *testing.T) {
328364
}
329365
}
330366

367+
func TestVolumeGet(t *testing.T) {
368+
expected := api.Volume{
369+
UUID: "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75",
370+
App: "example-go",
371+
Owner: "test",
372+
Name: "myvolume",
373+
Path: map[string]interface{}{},
374+
Size: "500G",
375+
Type: "csi",
376+
Parameters: map[string]interface{}{},
377+
Created: "2020-08-26T00:00:00UTC",
378+
Updated: "2020-08-26T00:00:00UTC",
379+
}
380+
handler := fakeHTTPServer{}
381+
server := httptest.NewServer(&handler)
382+
defer server.Close()
383+
384+
drycc, err := drycc.New(false, server.URL, "abc")
385+
if err != nil {
386+
t.Fatal(err)
387+
}
388+
389+
actual, err := Get(drycc, "example-go", "myvolume")
390+
391+
if err != nil {
392+
t.Fatal(err)
393+
}
394+
395+
if !reflect.DeepEqual(expected, actual) {
396+
t.Error(fmt.Errorf("Expected %v, Got %v", expected, actual))
397+
}
398+
}
399+
331400
func TestVolumeMount(t *testing.T) {
332401
t.Parallel()
333402

@@ -348,10 +417,12 @@ func TestVolumeMount(t *testing.T) {
348417
"cmd": "/data/cmd1",
349418
"web": "/data/web1",
350419
},
351-
Size: "500G",
352-
Created: "2020-08-26T00:00:00UTC",
353-
Updated: "2020-08-26T00:00:00UTC",
354-
UUID: "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75",
420+
Size: "500G",
421+
Type: "csi",
422+
Parameters: map[string]interface{}{},
423+
Created: "2020-08-26T00:00:00UTC",
424+
Updated: "2020-08-26T00:00:00UTC",
425+
UUID: "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75",
355426
}
356427

357428
volumeVars := api.Volume{
@@ -384,14 +455,16 @@ func TestVolumeUnmount(t *testing.T) {
384455
}
385456

386457
expected := api.Volume{
387-
Name: "myvolume",
388-
Owner: "test",
389-
App: "unmount-test",
390-
Path: map[string]interface{}{},
391-
Size: "500G",
392-
Created: "2020-08-26T00:00:00UTC",
393-
Updated: "2020-08-26T00:00:00UTC",
394-
UUID: "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75",
458+
Name: "myvolume",
459+
Owner: "test",
460+
App: "unmount-test",
461+
Path: map[string]interface{}{},
462+
Size: "500G",
463+
Type: "csi",
464+
Parameters: map[string]interface{}{},
465+
Created: "2020-08-26T00:00:00UTC",
466+
Updated: "2020-08-26T00:00:00UTC",
467+
UUID: "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75",
395468
}
396469

397470
volumeVars := api.Volume{

0 commit comments

Comments
 (0)