Skip to content

Commit 548d38f

Browse files
authored
add ctx to Set function (#2405)
1 parent 0428d70 commit 548d38f

19 files changed

+42
-44
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ services:
33
- docker
44
language: go
55
go:
6-
- 1.18.x
6+
- 1.19.x
77
install:
88
- go install github.com/vbatts/[email protected]
99
- curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl

api/client/volume/client.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,7 @@ func (v *volumeClient) Unmount(ctx context.Context, volumeID string, mountPath s
460460
}
461461

462462
// Update volume
463-
func (v *volumeClient) Set(volumeID string, locator *api.VolumeLocator,
464-
spec *api.VolumeSpec) error {
463+
func (v *volumeClient) Set(ctx context.Context, volumeID string, locator *api.VolumeLocator, spec *api.VolumeSpec) error {
465464
return v.doVolumeSet(correlation.TODO(),
466465
volumeID,
467466
&api.VolumeSetRequest{

api/server/middleware_auth.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func (a *authMiddleware) setWithAuth(w http.ResponseWriter, r *http.Request, nex
205205

206206
if req.Spec != nil && req.Spec.Size > 0 {
207207
isOpDone = true
208-
err = d.Set(volumeID, req.Locator, req.Spec)
208+
err = d.Set(ctx, volumeID, req.Locator, req.Spec)
209209
}
210210

211211
for err == nil && req.Action != nil {

api/server/sdk/volume_ops.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ func (s *VolumeServer) Update(
729729
maskUnModified(updatedSpec, req.GetSpec())
730730

731731
// Send to driver
732-
if err := s.driver(ctx).Set(req.GetVolumeId(), locator, updatedSpec); err != nil {
732+
if err := s.driver(ctx).Set(ctx, req.GetVolumeId(), locator, updatedSpec); err != nil {
733733
return nil, status.Errorf(codes.Internal, "Failed to update volume: %v", err)
734734
}
735735

api/server/sdk/volume_ops_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ func TestSdkVolumeUpdate(t *testing.T) {
647647
AnyTimes()
648648
s.MockDriver().
649649
EXPECT().
650-
Set(id, &api.VolumeLocator{VolumeLabels: newlabels}, &api.VolumeSpec{SnapshotInterval: math.MaxUint32}).
650+
Set(gomock.Any(), id, &api.VolumeLocator{VolumeLabels: newlabels}, &api.VolumeSpec{SnapshotInterval: math.MaxUint32}).
651651
Return(nil).
652652
Times(1)
653653

@@ -668,7 +668,7 @@ func TestSdkVolumeUpdate(t *testing.T) {
668668

669669
s.MockDriver().
670670
EXPECT().
671-
Set(id, nil, &api.VolumeSpec{Size: 1234, SnapshotInterval: math.MaxUint32}).
671+
Set(gomock.Any(), id, nil, &api.VolumeSpec{Size: 1234, SnapshotInterval: math.MaxUint32}).
672672
Return(nil).
673673
Times(1)
674674
_, err = c.Update(context.Background(), req)
@@ -687,7 +687,7 @@ func TestSdkVolumeUpdate(t *testing.T) {
687687

688688
s.MockDriver().
689689
EXPECT().
690-
Set(
690+
Set(gomock.Any(),
691691
id,
692692
&api.VolumeLocator{VolumeLabels: newlabels},
693693
&api.VolumeSpec{Size: 1234, SnapshotInterval: math.MaxUint32},
@@ -1156,7 +1156,7 @@ func TestSdkCloneOwnership(t *testing.T) {
11561156
Times(1),
11571157
mv.
11581158
EXPECT().
1159-
Set(id, nil, &api.VolumeSpec{
1159+
Set(gomock.Any(), id, nil, &api.VolumeSpec{
11601160
Size: 1234,
11611161
Ownership: &api.Ownership{
11621162
Owner: user2,
@@ -1283,7 +1283,7 @@ func TestSdkCloneOwnership(t *testing.T) {
12831283
Times(1),
12841284
mv.
12851285
EXPECT().
1286-
Set(id, nil, &api.VolumeSpec{
1286+
Set(gomock.Any(), id, nil, &api.VolumeSpec{
12871287
Size: 1234,
12881288
Ownership: &api.Ownership{
12891289
Owner: user2,
@@ -1803,7 +1803,7 @@ func TestSdkVolumeUpdatePolicyOwnership(t *testing.T) {
18031803
AnyTimes()
18041804
mv.
18051805
EXPECT().
1806-
Set(id, nil, volPolSpec).
1806+
Set(gomock.Any(), id, nil, volPolSpec).
18071807
Return(nil).
18081808
Times(1)
18091809

api/server/sdk/volume_snapshot_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
66
you may not use this file except in compliance with the License.
77
You may obtain a copy of the License at
88
9-
http://www.apache.org/licenses/LICENSE-2.0
9+
http://www.apache.org/licenses/LICENSE-2.0
1010
1111
Unless required by applicable law or agreed to in writing, software
1212
distributed under the License is distributed on an "AS IS" BASIS,
@@ -18,6 +18,7 @@ package sdk
1818

1919
import (
2020
"context"
21+
"github.com/golang/mock/gomock"
2122
"math"
2223
"testing"
2324

@@ -311,7 +312,7 @@ func TestSdkVolumeSnapshotScheduleUpdate(t *testing.T) {
311312
Times(1)
312313
s.MockDriver().
313314
EXPECT().
314-
Set(volid, nil, &api.VolumeSpec{
315+
Set(gomock.Any(), volid, nil, &api.VolumeSpec{
315316
SnapshotSchedule: "policy=mypolicy",
316317
SnapshotInterval: math.MaxUint32,
317318
}).
@@ -348,7 +349,7 @@ func TestSdkVolumeSnapshotScheduleUpdateDelete(t *testing.T) {
348349
AnyTimes()
349350
s.MockDriver().
350351
EXPECT().
351-
Set(volid, nil, &api.VolumeSpec{
352+
Set(gomock.Any(), volid, nil, &api.VolumeSpec{
352353
SnapshotSchedule: "",
353354
SnapshotInterval: math.MaxUint32,
354355
}).

api/server/volume_test.go

+10-12
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func TestVolumeNoAuth(t *testing.T) {
123123

124124
newspec := req.GetSpec()
125125
newspec.Size = newsize
126-
resp := driverclient.Set(id, req.GetLocator(), newspec)
126+
resp := driverclient.Set(context.TODO(), id, req.GetLocator(), newspec)
127127
assert.Nil(t, resp)
128128

129129
// INSPECT
@@ -793,7 +793,7 @@ func TestVolumeSetSuccess(t *testing.T) {
793793
Spec: &api.VolumeSpec{Size: newsize},
794794
}
795795

796-
res := driverclient.Set(id, req.GetLocator(), req2.GetSpec())
796+
res := driverclient.Set(context.TODO(), id, req.GetLocator(), req2.GetSpec())
797797
assert.Nil(t, res)
798798

799799
// Assert volume information is correct
@@ -808,13 +808,11 @@ func TestVolumeSetSuccess(t *testing.T) {
808808
assert.Equal(t, newsize, r.GetVolume().GetSpec().GetSize())
809809

810810
// Send HA request
811-
res = driverclient.Set(id,
812-
nil,
813-
&api.VolumeSpec{
814-
HaLevel: 2,
815-
ReplicaSet: &api.ReplicaSet{Nodes: []string{}},
816-
SnapshotInterval: math.MaxUint32,
817-
})
811+
res = driverclient.Set(context.TODO(), id, nil, &api.VolumeSpec{
812+
HaLevel: 2,
813+
ReplicaSet: &api.ReplicaSet{Nodes: []string{}},
814+
SnapshotInterval: math.MaxUint32,
815+
})
818816
assert.Nil(t, res, fmt.Sprintf("Error: %v", res))
819817

820818
// Assert volume information is correct
@@ -884,7 +882,7 @@ func TestVolumeSetFailed(t *testing.T) {
884882
Spec: &api.VolumeSpec{Size: size, HaLevel: halevel},
885883
}
886884
// Cannot get this to fail....
887-
err = driverclient.Set("doesnotexist", req2.GetLocator(), req2.GetSpec())
885+
err = driverclient.Set(context.TODO(), "doesnotexist", req2.GetLocator(), req2.GetSpec())
888886
// assert.NotNil(t, err)
889887

890888
// Assert volume information is correct
@@ -929,7 +927,7 @@ func TestMiddlewareVolumeSetSizeSuccess(t *testing.T) {
929927

930928
// Not setting mock secrets
931929

932-
err = driverclient.Set(id, nil, req.GetSpec())
930+
err = driverclient.Set(context.TODO(), id, nil, req.GetSpec())
933931
assert.NoError(t, err, "Unexpected error on Set")
934932

935933
// Assert volume information is correct
@@ -976,7 +974,7 @@ func TestMiddlewareVolumeSetFailure(t *testing.T) {
976974

977975
// Not setting mock secrets
978976

979-
err = driverclient.Set(id, &api.VolumeLocator{Name: "myvol"}, req.GetSpec())
977+
err = driverclient.Set(context.TODO(), id, &api.VolumeLocator{Name: "myvol"}, req.GetSpec())
980978
assert.Error(t, err, "Unexpected error on Set")
981979

982980
}

csi/controller_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1955,7 +1955,7 @@ func TestControllerCreateVolumeFromSnapshot(t *testing.T) {
19551955

19561956
s.MockDriver().
19571957
EXPECT().
1958-
Set(gomock.Any(), gomock.Any(), gomock.Any()).
1958+
Set(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
19591959
Return(nil).
19601960
Times(1),
19611961

@@ -2092,7 +2092,7 @@ func TestControllerCreateVolumeSnapshotThroughParameters(t *testing.T) {
20922092
Times(1),
20932093
s.MockDriver().
20942094
EXPECT().
2095-
Set(gomock.Any(), gomock.Any(), gomock.Any()).
2095+
Set(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
20962096
Return(nil).
20972097
Times(1),
20982098
// final inspect
@@ -2750,7 +2750,7 @@ func TestControllerExpandVolume(t *testing.T) {
27502750
AnyTimes(),
27512751
s.MockDriver().
27522752
EXPECT().
2753-
Set(gomock.Any(), gomock.Any(), &api.VolumeSpec{
2753+
Set(gomock.Any(), gomock.Any(), gomock.Any(), &api.VolumeSpec{
27542754
Size: 46 * units.GiB, // Round up from 45.5 to 46
27552755
SnapshotInterval: math.MaxUint32,
27562756
}).

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ require (
2525
github.com/libopenstorage/gossip v0.0.0-20220309192431-44c895e0923e
2626
github.com/libopenstorage/secrets v0.0.0-20200207034622-cdb443738c67
2727
github.com/libopenstorage/systemutils v0.0.0-20160208220149-44ac83be3ce1
28-
github.com/moby/sys/mount v0.2.0
2928
github.com/moby/sys/mountinfo v0.4.0
3029
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
3130
github.com/onsi/ginkgo v1.16.5
@@ -105,6 +104,7 @@ require (
105104
github.com/mitchellh/go-homedir v1.1.0 // indirect
106105
github.com/mitchellh/mapstructure v1.3.3 // indirect
107106
github.com/moby/locker v1.0.1 // indirect
107+
github.com/moby/sys/mount v0.2.0 // indirect
108108
github.com/moby/sys/symlink v0.1.0 // indirect
109109
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
110110
github.com/modern-go/reflect2 v1.0.2 // indirect

pkg/sanity/volume.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ var _ = Describe("Volume [Volume Tests]", func() {
617617
},
618618
}
619619

620-
err = volumedriver.Set(volumeID, set.GetLocator(), set.GetSpec())
620+
err = volumedriver.Set(context.TODO(), volumeID, set.GetLocator(), set.GetSpec())
621621
Expect(err).NotTo(HaveOccurred())
622622

623623
By("Inspecting the volume for new updates")
@@ -679,7 +679,7 @@ var _ = Describe("Volume [Volume Tests]", func() {
679679
},
680680
}
681681

682-
err = volumedriver.Set(volumeID, set.Locator, set.Spec)
682+
err = volumedriver.Set(context.TODO(), volumeID, set.Locator, set.Spec)
683683
Expect(err).NotTo(HaveOccurred())
684684

685685
By("Inspecting the volume for new updates")

volume/drivers/buse/buse.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ func (d *driver) SnapshotGroup(groupID string, labels map[string]string, volumeI
362362
return nil, volume.ErrNotSupported
363363
}
364364

365-
func (d *driver) Set(volumeID string, locator *api.VolumeLocator, spec *api.VolumeSpec) error {
365+
func (d *driver) Set(ctx context.Context, volumeID string, locator *api.VolumeLocator, spec *api.VolumeSpec) error {
366366
if spec != nil {
367367
return volume.ErrNotSupported
368368
}

volume/drivers/fake/fake.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ func (d *driver) CloudMigrateStatus(request *api.CloudMigrateStatusRequest) (*ap
336336
}, nil
337337
}
338338

339-
func (d *driver) Set(volumeID string, locator *api.VolumeLocator, spec *api.VolumeSpec) error {
339+
func (d *driver) Set(ctx context.Context, volumeID string, locator *api.VolumeLocator, spec *api.VolumeSpec) error {
340340
v, err := d.GetVol(volumeID)
341341
if err != nil {
342342
return err

volume/drivers/fake/fake_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ func TestFakeSet(t *testing.T) {
715715
assert.NotEmpty(t, volid)
716716

717717
// Set values
718-
err = d.Set(volid, &api.VolumeLocator{
718+
err = d.Set(context.TODO(), volid, &api.VolumeLocator{
719719
Name: "newname",
720720
VolumeLabels: map[string]string{
721721
"hello": "world",

volume/drivers/fuse/volume_driver.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func (v *volumeDriver) Unmount(ctx context.Context, volumeID string, mountpath s
180180
return v.UpdateVol(volume)
181181
}
182182

183-
func (v *volumeDriver) Set(volumeID string, locator *api.VolumeLocator, spec *api.VolumeSpec) error {
183+
func (v *volumeDriver) Set(ctx context.Context, volumeID string, locator *api.VolumeLocator, spec *api.VolumeSpec) error {
184184
return volume.ErrNotSupported
185185

186186
}

volume/drivers/mock/driver.mock.go

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

volume/drivers/nfs/nfs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ func (d *driver) Detach(ctx context.Context, volumeID string, options map[string
789789
return nil
790790
}
791791

792-
func (d *driver) Set(volumeID string, locator *api.VolumeLocator, spec *api.VolumeSpec) error {
792+
func (d *driver) Set(ctx context.Context, volumeID string, locator *api.VolumeLocator, spec *api.VolumeSpec) error {
793793
if spec != nil {
794794
return volume.ErrNotSupported
795795
}

volume/drivers/test/driver.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func set(t *testing.T, ctx *Context) {
149149
require.Equal(t, vols[0].Id, ctx.volID, "Expect volID %v actual %v", ctx.volID, vols[0].Id)
150150

151151
vols[0].Locator.VolumeLabels["UpdateTest"] = "Success"
152-
err = ctx.Set(ctx.volID, vols[0].Locator, nil)
152+
err = ctx.Set(correlation.TODO(), ctx.volID, vols[0].Locator, nil)
153153
if err != volume.ErrNotSupported {
154154
require.NoError(t, err, "Failed in Update")
155155
vols, err = ctx.Inspect(correlation.TODO(), []string{ctx.volID})

volume/drivers/vfs/vfs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func (d *driver) Unmount(ctx context.Context, volumeID string, mountpath string,
171171
return d.UpdateVol(v)
172172
}
173173

174-
func (d *driver) Set(volumeID string, locator *api.VolumeLocator, spec *api.VolumeSpec) error {
174+
func (d *driver) Set(ctx context.Context, volumeID string, locator *api.VolumeLocator, spec *api.VolumeSpec) error {
175175
if spec != nil {
176176
return volume.ErrNotSupported
177177
}

volume/volume.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ type ProtoDriver interface {
291291
Unmount(ctx context.Context, volumeID string, mountPath string, options map[string]string) error
292292
// Update not all fields of the spec are supported, ErrNotSupported will be thrown for unsupported
293293
// updates.
294-
Set(volumeID string, locator *api.VolumeLocator, spec *api.VolumeSpec) error
294+
Set(ctx context.Context, volumeID string, locator *api.VolumeLocator, spec *api.VolumeSpec) error
295295
// Status returns a set of key-value pairs which give low
296296
// level diagnostic status about this driver.
297297
Status() [][2]string

0 commit comments

Comments
 (0)