Skip to content

Commit f979be1

Browse files
committed
Update logger, readme
1 parent b986813 commit f979be1

File tree

5 files changed

+37
-57
lines changed

5 files changed

+37
-57
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
**Fork Notice:**
22

3-
This repo is a fork of the Leaseweb's maitained cloudstack-csi-driver, which is in-turn a fork of Apalia's cloudstack-csi-driver
3+
This repo is a fork of the [Leaseweb's] (https://github.com/leaseweb/cloudstack-csi-driver) maitained cloudstack-csi-driver, which is in-turn a fork of [Apalia's](https://github.com/apalia/cloudstack-csi-driver) cloudstack-csi-driver
44

55
# CloudStack CSI Driver
66

pkg/cloud/cloud.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type Interface interface {
2525
ExpandVolume(ctx context.Context, volumeID string, newSizeInGB int64) error
2626

2727
CreateVolumeFromSnapshot(ctx context.Context, zoneID, name, domainID, projectID, snapshotID string, sizeInGB int64) (*Volume, error)
28-
GetSnapshotByID(ctx context.Context, snapshotID ...string) (*Snapshot, error)
28+
GetSnapshotByID(ctx context.Context, snapshotID string) (*Snapshot, error)
2929
CreateSnapshot(ctx context.Context, volumeID string) (*Snapshot, error)
3030
DeleteSnapshot(ctx context.Context, snapshotID string) error
3131
}

pkg/cloud/snapshots.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ import (
99
"k8s.io/klog/v2"
1010
)
1111

12-
func (c *client) GetSnapshotByID(ctx context.Context, snapshotID ...string) (*Snapshot, error) {
12+
func (c *client) GetSnapshotByID(ctx context.Context, snapshotID string) (*Snapshot, error) {
1313
logger := klog.FromContext(ctx)
1414
p := c.Snapshot.NewListSnapshotsParams()
15-
if snapshotID != nil {
16-
p.SetId(snapshotID[0])
15+
if snapshotID != "" {
16+
p.SetId(snapshotID)
1717
}
1818
if c.projectID != "" {
1919
p.SetProjectid(c.projectID)
2020
}
2121
logger.V(2).Info("CloudStack API call", "command", "ListSnapshots", "params", map[string]string{
22-
"id": snapshotID[0],
22+
"id": snapshotID,
2323
"projectid": c.projectID,
2424
})
2525
l, err := c.Snapshot.ListSnapshots(p)

pkg/driver/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ func determineSize(req *csi.CreateVolumeRequest) (int64, error) {
290290

291291
func (cs *controllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest) (*csi.DeleteVolumeResponse, error) {
292292
logger := klog.FromContext(ctx)
293-
logger.Info("DeleteVolume: called", "args", *req)
293+
logger.V(4).Info("DeleteVolume: called", "args", *req)
294294

295295
if req.GetVolumeId() == "" {
296296
return nil, status.Error(codes.InvalidArgument, "Volume ID missing in request")

pkg/mount/mount.go

Lines changed: 30 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func (m *mounter) GetBlockSizeBytes(devicePath string) (int64, error) {
7979
}
8080

8181
func (m *mounter) GetDevicePath(ctx context.Context, volumeID string) (string, error) {
82+
logger := klog.FromContext(ctx)
8283
backoff := wait.Backoff{
8384
Duration: 2 * time.Second,
8485
Factor: 1.5,
@@ -87,13 +88,13 @@ func (m *mounter) GetDevicePath(ctx context.Context, volumeID string) (string, e
8788

8889
var devicePath string
8990
err := wait.ExponentialBackoffWithContext(ctx, backoff, func(context.Context) (bool, error) {
90-
path, err := m.getDevicePathBySerialID(volumeID)
91+
path, err := m.getDevicePathBySerialID(ctx, volumeID)
9192
if err != nil {
9293
return false, err
9394
}
9495
if path != "" {
9596
devicePath = path
96-
97+
logger.V(4).Info("Device path found", "volumeID", volumeID, "devicePath", path)
9798
return true, nil
9899
}
99100
m.probeVolume(ctx)
@@ -110,20 +111,22 @@ func (m *mounter) GetDevicePath(ctx context.Context, volumeID string) (string, e
110111
return devicePath, nil
111112
}
112113

113-
func (m *mounter) getDevicePathBySerialID(volumeID string) (string, error) {
114+
func (m *mounter) getDevicePathBySerialID(ctx context.Context, volumeID string) (string, error) {
115+
logger := klog.FromContext(ctx)
116+
114117
// First try XenServer device paths
115-
xenDevicePath, err := m.getDevicePathForXenServer(volumeID)
118+
xenDevicePath, err := m.getDevicePathForXenServer(ctx, volumeID)
116119
if err != nil {
117-
fmt.Printf("Failed to get XenServer device path: %v\n", err)
120+
logger.V(4).Info("Failed to get XenServer device path", "volumeID", volumeID, "error", err)
118121
}
119122
if xenDevicePath != "" {
120123
return xenDevicePath, nil
121124
}
122125

123126
// Try VMware device paths
124-
vmwareDevicePath, err := m.getDevicePathForVMware(volumeID)
127+
vmwareDevicePath, err := m.getDevicePathForVMware(ctx, volumeID)
125128
if err != nil {
126-
fmt.Printf("Failed to get VMware device path: %v\n", err)
129+
logger.V(4).Info("Failed to get VMware device path", "volumeID", volumeID, "error", err)
127130
}
128131
if vmwareDevicePath != "" {
129132
return vmwareDevicePath, nil
@@ -146,16 +149,18 @@ func (m *mounter) getDevicePathBySerialID(volumeID string) (string, error) {
146149
return "", nil
147150
}
148151

149-
func (m *mounter) getDevicePathForXenServer(volumeID string) (string, error) {
152+
func (m *mounter) getDevicePathForXenServer(ctx context.Context, volumeID string) (string, error) {
153+
logger := klog.FromContext(ctx)
154+
150155
for i := 'b'; i <= 'z'; i++ {
151156
devicePath := fmt.Sprintf("/dev/xvd%c", i)
152-
fmt.Printf("Checking XenServer device path: %s\n", devicePath)
157+
logger.V(5).Info("Checking XenServer device path", "devicePath", devicePath, "volumeID", volumeID)
153158

154159
if _, err := os.Stat(devicePath); err == nil {
155160
isBlock, err := m.IsBlockDevice(devicePath)
156161
if err == nil && isBlock {
157-
if m.verifyXenServerDevice(devicePath, volumeID) {
158-
fmt.Printf("Found and verified XenServer device: %s\n", devicePath)
162+
if m.verifyDevice(ctx, devicePath, volumeID) {
163+
logger.V(4).Info("Found and verified XenServer device", "devicePath", devicePath, "volumeID", volumeID)
159164
return devicePath, nil
160165
}
161166
}
@@ -164,46 +169,19 @@ func (m *mounter) getDevicePathForXenServer(volumeID string) (string, error) {
164169
return "", fmt.Errorf("device not found for volume %s", volumeID)
165170
}
166171

167-
func (m *mounter) verifyXenServerDevice(devicePath string, volumeID string) bool {
168-
size, err := m.GetBlockSizeBytes(devicePath)
169-
if err != nil {
170-
fmt.Printf("Failed to get device size: %v\n", err)
171-
return false
172-
}
173-
fmt.Printf("Device size: %d bytes\n", size)
174-
175-
mounted, err := m.isDeviceMounted(devicePath)
176-
if err != nil {
177-
fmt.Printf("Failed to check if device is mounted: %v\n", err)
178-
return false
179-
}
180-
if mounted {
181-
fmt.Printf("Device is already mounted: %s\n", devicePath)
182-
return false
183-
}
184-
185-
props, err := m.getDeviceProperties(devicePath)
186-
if err != nil {
187-
fmt.Printf("Failed to get device properties: %v\n", err)
188-
return false
189-
}
190-
fmt.Printf("Device properties: %v\n", props)
191-
192-
return true
193-
}
172+
func (m *mounter) getDevicePathForVMware(ctx context.Context, volumeID string) (string, error) {
173+
logger := klog.FromContext(ctx)
194174

195-
func (m *mounter) getDevicePathForVMware(volumeID string) (string, error) {
196175
// Loop through /dev/sdb to /dev/sdz (/dev/sda -> the root disk)
197176
for i := 'b'; i <= 'z'; i++ {
198177
devicePath := fmt.Sprintf("/dev/sd%c", i)
199-
fmt.Printf("Checking VMware device path: %s\n", devicePath)
178+
logger.V(5).Info("Checking VMware device path", "devicePath", devicePath, "volumeID", volumeID)
200179

201180
if _, err := os.Stat(devicePath); err == nil {
202181
isBlock, err := m.IsBlockDevice(devicePath)
203182
if err == nil && isBlock {
204-
// Use the same verification as for XenServer
205-
if m.verifyVMwareDevice(devicePath, volumeID) {
206-
fmt.Printf("Found and verified VMware device: %s\n", devicePath)
183+
if m.verifyDevice(ctx, devicePath, volumeID) {
184+
logger.V(4).Info("Found and verified VMware device", "devicePath", devicePath, "volumeID", volumeID)
207185
return devicePath, nil
208186
}
209187
}
@@ -212,30 +190,32 @@ func (m *mounter) getDevicePathForVMware(volumeID string) (string, error) {
212190
return "", fmt.Errorf("device not found for volume %s", volumeID)
213191
}
214192

215-
func (m *mounter) verifyVMwareDevice(devicePath string, volumeID string) bool {
193+
func (m *mounter) verifyDevice(ctx context.Context, devicePath string, volumeID string) bool {
194+
logger := klog.FromContext(ctx)
195+
216196
size, err := m.GetBlockSizeBytes(devicePath)
217197
if err != nil {
218-
fmt.Printf("Failed to get device size: %v\n", err)
198+
logger.V(4).Info("Failed to get device size", "devicePath", devicePath, "volumeID", volumeID, "error", err)
219199
return false
220200
}
221-
fmt.Printf("Device size: %d bytes\n", size)
201+
logger.V(5).Info("Device size retrieved", "devicePath", devicePath, "volumeID", volumeID, "sizeBytes", size)
222202

223203
mounted, err := m.isDeviceMounted(devicePath)
224204
if err != nil {
225-
fmt.Printf("Failed to check if device is mounted: %v\n", err)
205+
logger.V(4).Info("Failed to check if device is mounted", "devicePath", devicePath, "volumeID", volumeID, "error", err)
226206
return false
227207
}
228208
if mounted {
229-
fmt.Printf("Device is already mounted: %s\n", devicePath)
209+
logger.V(4).Info("Device is already mounted", "devicePath", devicePath, "volumeID", volumeID)
230210
return false
231211
}
232212

233213
props, err := m.getDeviceProperties(devicePath)
234214
if err != nil {
235-
fmt.Printf("Failed to get device properties: %v\n", err)
215+
logger.V(4).Info("Failed to get device properties", "devicePath", devicePath, "volumeID", volumeID, "error", err)
236216
return false
237217
}
238-
fmt.Printf("Device properties: %v\n", props)
218+
logger.V(5).Info("Device properties retrieved", "devicePath", devicePath, "volumeID", volumeID, "properties", props)
239219

240220
return true
241221
}

0 commit comments

Comments
 (0)