Skip to content

Commit 6862328

Browse files
authored
Merge pull request #476 from andyzhangx/driver-options
chore: refine driver parameter setting
2 parents 5cb9aee + a9543bc commit 6862328

File tree

4 files changed

+69
-19
lines changed

4 files changed

+69
-19
lines changed

pkg/blob/blob.go

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ var (
101101
retriableErrors = []string{accountNotProvisioned, tooManyRequests, shareNotFound, shareBeingDeleted, clientThrottled}
102102
)
103103

104+
// DriverOptions defines driver parameters specified in driver deployment
105+
type DriverOptions struct {
106+
NodeID string
107+
DriverName string
108+
BlobfuseProxyEndpoint string
109+
EnableBlobfuseProxy bool
110+
BlobfuseProxyConnTimout int
111+
EnableBlobMockMount bool
112+
}
113+
104114
// Driver implements all interfaces of CSI drivers
105115
type Driver struct {
106116
csicommon.CSIDriver
@@ -121,19 +131,20 @@ type Driver struct {
121131

122132
// NewDriver Creates a NewCSIDriver object. Assumes vendor version is equal to driver version &
123133
// does not support optional driver plugin info manifest field. Refer to CSI spec for more details.
124-
func NewDriver(nodeID, driverName, blobfuseProxyEndpoint string, enableBlobfuseProxy bool, blobfuseProxyConnTimout int, enableBlobMockMount bool) *Driver {
125-
driver := Driver{}
126-
driver.Name = driverName
127-
driver.Version = driverVersion
128-
driver.NodeID = nodeID
129-
driver.volLockMap = util.NewLockMap()
130-
driver.subnetLockMap = util.NewLockMap()
131-
driver.volumeLocks = newVolumeLocks()
132-
driver.blobfuseProxyEndpoint = blobfuseProxyEndpoint
133-
driver.enableBlobfuseProxy = enableBlobfuseProxy
134-
driver.blobfuseProxyConnTimout = blobfuseProxyConnTimout
135-
driver.enableBlobMockMount = enableBlobMockMount
136-
return &driver
134+
func NewDriver(options *DriverOptions) *Driver {
135+
d := Driver{
136+
volLockMap: util.NewLockMap(),
137+
subnetLockMap: util.NewLockMap(),
138+
volumeLocks: newVolumeLocks(),
139+
blobfuseProxyEndpoint: options.BlobfuseProxyEndpoint,
140+
enableBlobfuseProxy: options.EnableBlobfuseProxy,
141+
blobfuseProxyConnTimout: options.BlobfuseProxyConnTimout,
142+
enableBlobMockMount: options.EnableBlobMockMount,
143+
}
144+
d.Name = options.DriverName
145+
d.Version = driverVersion
146+
d.NodeID = options.NodeID
147+
return &d
137148
}
138149

139150
// Run driver initialization

pkg/blob/blob_test.go

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,44 @@ const (
4545
)
4646

4747
func NewFakeDriver() *Driver {
48-
driver := NewDriver(fakeNodeID, DefaultDriverName, "", false, 5, false)
48+
driverOptions := DriverOptions{
49+
NodeID: fakeNodeID,
50+
DriverName: DefaultDriverName,
51+
BlobfuseProxyEndpoint: "",
52+
EnableBlobfuseProxy: false,
53+
BlobfuseProxyConnTimout: 5,
54+
EnableBlobMockMount: false,
55+
}
56+
driver := NewDriver(&driverOptions)
4957
driver.Name = fakeDriverName
5058
driver.Version = vendorVersion
5159
driver.subnetLockMap = util.NewLockMap()
5260
return driver
5361
}
5462

5563
func TestNewFakeDriver(t *testing.T) {
56-
d := NewDriver(fakeNodeID, DefaultDriverName, "", false, 5, false)
64+
driverOptions := DriverOptions{
65+
NodeID: fakeNodeID,
66+
DriverName: DefaultDriverName,
67+
BlobfuseProxyEndpoint: "",
68+
EnableBlobfuseProxy: false,
69+
BlobfuseProxyConnTimout: 5,
70+
EnableBlobMockMount: false,
71+
}
72+
d := NewDriver(&driverOptions)
5773
assert.NotNil(t, d)
5874
}
5975

6076
func TestNewDriver(t *testing.T) {
61-
driver := NewDriver(fakeNodeID, DefaultDriverName, "", false, 5, false)
77+
driverOptions := DriverOptions{
78+
NodeID: fakeNodeID,
79+
DriverName: DefaultDriverName,
80+
BlobfuseProxyEndpoint: "",
81+
EnableBlobfuseProxy: false,
82+
BlobfuseProxyConnTimout: 5,
83+
EnableBlobMockMount: false,
84+
}
85+
driver := NewDriver(&driverOptions)
6286
fakedriver := NewFakeDriver()
6387
fakedriver.Name = DefaultDriverName
6488
fakedriver.Version = driverVersion

pkg/blobplugin/main.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,15 @@ func main() {
6666
}
6767

6868
func handle() {
69-
driver := blob.NewDriver(*nodeID, *driverName, *blobfuseProxyEndpoint, *enableBlobfuseProxy, *blobfuseProxyConnTimout, *enableBlobMockMount)
69+
driverOptions := blob.DriverOptions{
70+
NodeID: *nodeID,
71+
DriverName: *driverName,
72+
BlobfuseProxyEndpoint: *blobfuseProxyEndpoint,
73+
EnableBlobfuseProxy: *enableBlobfuseProxy,
74+
BlobfuseProxyConnTimout: *blobfuseProxyConnTimout,
75+
EnableBlobMockMount: *enableBlobMockMount,
76+
}
77+
driver := blob.NewDriver(&driverOptions)
7078
if driver == nil {
7179
klog.Fatalln("Failed to initialize Azure Blob Storage CSI driver")
7280
}

test/e2e/suite_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,17 @@ var _ = ginkgo.BeforeSuite(func() {
107107
}
108108
execTestCmd([]testCmd{e2eBootstrap, createMetricsSVC})
109109

110-
nodeid := os.Getenv("nodeid")
111110
kubeconfig := os.Getenv(kubeconfigEnvVar)
112111
_, useBlobfuseProxy := os.LookupEnv("ENABLE_BLOBFUSE_PROXY")
113-
blobDriver = blob.NewDriver(nodeid, blob.DefaultDriverName, "", useBlobfuseProxy, 5, false)
112+
driverOptions := blob.DriverOptions{
113+
NodeID: os.Getenv("nodeid"),
114+
DriverName: blob.DefaultDriverName,
115+
BlobfuseProxyEndpoint: "",
116+
EnableBlobfuseProxy: useBlobfuseProxy,
117+
BlobfuseProxyConnTimout: 5,
118+
EnableBlobMockMount: false,
119+
}
120+
blobDriver = blob.NewDriver(&driverOptions)
114121
go func() {
115122
os.Setenv("AZURE_CREDENTIAL_FILE", credentials.TempAzureCredentialFilePath)
116123
blobDriver.Run(fmt.Sprintf("unix:///tmp/csi-%s.sock", uuid.NewUUID().String()), kubeconfig, false)

0 commit comments

Comments
 (0)