Skip to content

Commit 57b0c8e

Browse files
authored
Merge pull request #2 from Leaseweb/upd_1_25_9
Update dependencies to Kubernetes 1.25, use Go 1.19 and Alpine 3.16, fix CSI spec violations
2 parents 1478647 + d925267 commit 57b0c8e

File tree

9 files changed

+241
-387
lines changed

9 files changed

+241
-387
lines changed

cmd/cloudstack-csi-driver/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM alpine:3.14.0
1+
FROM alpine:3.16
22

33
LABEL \
44
org.opencontainers.image.description="CloudStack CSI driver" \

cmd/cloudstack-csi-sc-syncer/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM alpine:3.14.0
1+
FROM alpine:3.16
22

33
LABEL \
44
org.opencontainers.image.description="CloudStack disk offering to Kubernetes storage class syncer" \

go.mod

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,71 @@
11
module github.com/leaseweb/cloudstack-csi-driver
22

3-
go 1.15
3+
go 1.19
44

55
require (
6-
github.com/apache/cloudstack-go/v2 v2.9.1-0.20210727090705-0ad6453e08b8
7-
github.com/container-storage-interface/spec v1.5.0
8-
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
9-
github.com/hashicorp/go-uuid v1.0.2
10-
github.com/kubernetes-csi/csi-test/v4 v4.2.0
11-
go.uber.org/zap v1.16.0
12-
golang.org/x/net v0.7.0 // indirect
13-
golang.org/x/text v0.7.0
14-
google.golang.org/genproto v0.0.0-20210726200206-e7812ac95cc0 // indirect
15-
google.golang.org/grpc v1.39.0
6+
github.com/apache/cloudstack-go/v2 v2.15.0
7+
github.com/container-storage-interface/spec v1.6.0
8+
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
9+
github.com/hashicorp/go-uuid v1.0.3
10+
github.com/kubernetes-csi/csi-test/v4 v4.4.0
11+
go.uber.org/zap v1.24.0
12+
golang.org/x/text v0.9.0
13+
google.golang.org/grpc v1.55.0
1614
gopkg.in/gcfg.v1 v1.2.3
15+
k8s.io/api v0.25.9
16+
k8s.io/apimachinery v0.25.9
17+
k8s.io/client-go v0.25.9
18+
k8s.io/mount-utils v0.25.9
19+
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2
20+
)
21+
22+
require (
23+
github.com/PuerkitoBio/purell v1.1.1 // indirect
24+
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
25+
github.com/davecgh/go-spew v1.1.1 // indirect
26+
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
27+
github.com/fsnotify/fsnotify v1.4.9 // indirect
28+
github.com/go-logr/logr v1.2.3 // indirect
29+
github.com/go-openapi/jsonpointer v0.19.5 // indirect
30+
github.com/go-openapi/jsonreference v0.19.5 // indirect
31+
github.com/go-openapi/swag v0.19.14 // indirect
32+
github.com/gogo/protobuf v1.3.2 // indirect
33+
github.com/golang/mock v1.6.0 // indirect
34+
github.com/golang/protobuf v1.5.3 // indirect
35+
github.com/google/gnostic v0.5.7-v3refs // indirect
36+
github.com/google/go-cmp v0.5.9 // indirect
37+
github.com/google/gofuzz v1.1.0 // indirect
38+
github.com/google/uuid v1.3.0 // indirect
39+
github.com/imdario/mergo v0.3.6 // indirect
40+
github.com/josharian/intern v1.0.0 // indirect
41+
github.com/json-iterator/go v1.1.12 // indirect
42+
github.com/mailru/easyjson v0.7.6 // indirect
43+
github.com/moby/sys/mountinfo v0.6.0 // indirect
44+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
45+
github.com/modern-go/reflect2 v1.0.2 // indirect
46+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
47+
github.com/nxadm/tail v1.4.8 // indirect
48+
github.com/onsi/ginkgo v1.16.5 // indirect
49+
github.com/onsi/gomega v1.27.4 // indirect
50+
github.com/spf13/pflag v1.0.5 // indirect
51+
go.uber.org/atomic v1.7.0 // indirect
52+
go.uber.org/multierr v1.6.0 // indirect
53+
golang.org/x/net v0.8.0 // indirect
54+
golang.org/x/oauth2 v0.6.0 // indirect
55+
golang.org/x/sys v0.6.0 // indirect
56+
golang.org/x/term v0.6.0 // indirect
57+
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
58+
google.golang.org/appengine v1.6.7 // indirect
59+
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect
60+
google.golang.org/protobuf v1.30.0 // indirect
61+
gopkg.in/inf.v0 v0.9.1 // indirect
62+
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
1763
gopkg.in/warnings.v0 v0.1.2 // indirect
18-
k8s.io/api v0.21.3
19-
k8s.io/apimachinery v0.21.3
20-
k8s.io/client-go v0.21.3
21-
k8s.io/mount-utils v0.21.3
22-
k8s.io/utils v0.0.0-20210111153108-fddb29f9d009
64+
gopkg.in/yaml.v2 v2.4.0 // indirect
65+
gopkg.in/yaml.v3 v3.0.1 // indirect
66+
k8s.io/klog/v2 v2.80.1 // indirect
67+
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // indirect
68+
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
69+
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
70+
sigs.k8s.io/yaml v1.2.0 // indirect
2371
)

go.sum

Lines changed: 143 additions & 345 deletions
Large diffs are not rendered by default.

pkg/cloud/cloud.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type Interface interface {
2121
CreateVolume(ctx context.Context, diskOfferingID, zoneID, name string, sizeInGB int64) (string, error)
2222
DeleteVolume(ctx context.Context, id string) error
2323
AttachVolume(ctx context.Context, volumeID, vmID string) (string, error)
24-
DetachVolume(ctx context.Context, volumeID string) error
24+
DetachVolume(ctx context.Context, volumeID string, vmID string) error
2525
}
2626

2727
// Volume represents a CloudStack volume.

pkg/cloud/fake/fake.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,6 @@ func (f *fakeConnector) AttachVolume(ctx context.Context, volumeID, vmID string)
100100
return "1", nil
101101
}
102102

103-
func (f *fakeConnector) DetachVolume(ctx context.Context, volumeID string) error { return nil }
103+
func (f *fakeConnector) DetachVolume(ctx context.Context, volumeID string, vmID string) error {
104+
return nil
105+
}

pkg/cloud/volumes.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,15 @@ func (c *client) AttachVolume(ctx context.Context, volumeID, vmID string) (strin
111111
return strconv.FormatInt(r.Deviceid, 10), nil
112112
}
113113

114-
func (c *client) DetachVolume(ctx context.Context, volumeID string) error {
114+
func (c *client) DetachVolume(ctx context.Context, volumeID string, vmID string) error {
115115
p := c.Volume.NewDetachVolumeParams()
116116
p.SetId(volumeID)
117+
if vmID != "" {
118+
p.SetVirtualmachineid(vmID)
119+
}
117120
ctxzap.Extract(ctx).Sugar().Infow("CloudStack API call", "command", "DetachVolume", "params", map[string]string{
118-
"id": volumeID,
121+
"id": volumeID,
122+
"virtualmachineid": vmID,
119123
})
120124
_, err := c.Volume.DetachVolume(p)
121125
return err

pkg/driver/controller.go

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"math/rand"
7+
"sync"
78

89
"github.com/container-storage-interface/spec/lib/go/csi"
910
"google.golang.org/grpc/codes"
@@ -24,12 +25,14 @@ var onlyVolumeCapAccessMode = csi.VolumeCapability_AccessMode{
2425
type controllerServer struct {
2526
csi.UnimplementedControllerServer
2627
connector cloud.Interface
28+
locks map[string]*sync.Mutex
2729
}
2830

2931
// NewControllerServer creates a new Controller gRPC server.
3032
func NewControllerServer(connector cloud.Interface) csi.ControllerServer {
3133
return &controllerServer{
3234
connector: connector,
35+
locks: make(map[string]*sync.Mutex),
3336
}
3437
}
3538

@@ -215,6 +218,15 @@ func (cs *controllerServer) ControllerPublishVolume(ctx context.Context, req *cs
215218
}
216219
nodeID := req.GetNodeId()
217220

221+
//Ensure only one node is processing at same time
222+
lock, ok := cs.locks[nodeID]
223+
if !ok {
224+
lock = &sync.Mutex{}
225+
cs.locks[nodeID] = lock
226+
}
227+
lock.Lock()
228+
defer lock.Unlock()
229+
218230
if req.GetReadonly() {
219231
return nil, status.Error(codes.InvalidArgument, "Readonly not possible")
220232
}
@@ -236,11 +248,11 @@ func (cs *controllerServer) ControllerPublishVolume(ctx context.Context, req *cs
236248
}
237249

238250
if vol.VirtualMachineID != "" && vol.VirtualMachineID != nodeID {
239-
return nil, status.Error(codes.AlreadyExists, "Volume already assigned")
251+
return nil, status.Error(codes.AlreadyExists, "Volume already assigned to another node")
240252
}
241253

242254
if _, err := cs.connector.GetVMByID(ctx, nodeID); err == cloud.ErrNotFound {
243-
return nil, status.Errorf(codes.NotFound, "VM %v not found", volumeID)
255+
return nil, status.Errorf(codes.NotFound, "VM %v not found", nodeID)
244256
} else if err != nil {
245257
// Error with CloudStack
246258
return nil, status.Errorf(codes.Internal, "Error %v", err)
@@ -273,39 +285,30 @@ func (cs *controllerServer) ControllerUnpublishVolume(ctx context.Context, req *
273285
return nil, status.Error(codes.InvalidArgument, "Volume ID missing in request")
274286
}
275287
volumeID := req.GetVolumeId()
276-
277-
if req.GetNodeId() == "" {
278-
return nil, status.Error(codes.InvalidArgument, "Node ID missing in request")
279-
}
280288
nodeID := req.GetNodeId()
281289

282290
// Check volume
283291
if vol, err := cs.connector.GetVolumeByID(ctx, volumeID); err == cloud.ErrNotFound {
284-
return nil, status.Errorf(codes.NotFound, "Volume %v not found", volumeID)
292+
// Volume does not exist in CloudStack. We can safely assume this volume is no longer attached
293+
// The spec requires us to return OK here
294+
return &csi.ControllerUnpublishVolumeResponse{}, nil
285295
} else if err != nil {
286296
// Error with CloudStack
287297
return nil, status.Errorf(codes.Internal, "Error %v", err)
288-
} else if vol.VirtualMachineID != nodeID {
289-
// Nothing to do
298+
} else if nodeID != "" && vol.VirtualMachineID != nodeID {
299+
// Volume is present but not attached to this particular nodeID
290300
return &csi.ControllerUnpublishVolumeResponse{}, nil
291301
}
292302

293303
// Check VM existence
294-
if _, err := cs.connector.GetVolumeByID(ctx, volumeID); err == cloud.ErrNotFound {
295-
return nil, status.Errorf(codes.NotFound, "Volume %v not found", volumeID)
296-
} else if err != nil {
297-
// Error with CloudStack
298-
return nil, status.Errorf(codes.Internal, "Error %v", err)
299-
}
300-
301304
if _, err := cs.connector.GetVMByID(ctx, nodeID); err == cloud.ErrNotFound {
302-
return nil, status.Errorf(codes.NotFound, "VM %v not found", volumeID)
305+
return nil, status.Errorf(codes.NotFound, "VM %v not found", nodeID)
303306
} else if err != nil {
304307
// Error with CloudStack
305308
return nil, status.Errorf(codes.Internal, "Error %v", err)
306309
}
307310

308-
err := cs.connector.DetachVolume(ctx, volumeID)
311+
err := cs.connector.DetachVolume(ctx, volumeID, nodeID)
309312
if err != nil {
310313
return nil, status.Errorf(codes.Internal, "Cannot detach volume %s: %s", volumeID, err.Error())
311314
}

pkg/driver/server.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"strings"
99

1010
"github.com/container-storage-interface/spec/lib/go/csi"
11-
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
1211
grpc_zap "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap"
1312
"google.golang.org/grpc"
1413
)
@@ -35,7 +34,7 @@ func (cs *cloudstackDriver) serve(ids csi.IdentityServer, ctrls csi.ControllerSe
3534

3635
// Log every request and payloads (request + response)
3736
opts := []grpc.ServerOption{
38-
grpc_middleware.WithUnaryServerChain(
37+
grpc.ChainUnaryInterceptor(
3938
grpc_zap.UnaryServerInterceptor(cs.logger),
4039
grpc_zap.PayloadUnaryServerInterceptor(cs.logger, func(context.Context, string, interface{}) bool { return true }),
4140
),

0 commit comments

Comments
 (0)