Skip to content

Commit cb8dfb0

Browse files
authored
Merge pull request #38 from hughdanliu/logging
Adopt Kubernetes standard logging patterns
2 parents b0e70a2 + 7c97578 commit cb8dfb0

File tree

3 files changed

+31
-30
lines changed

3 files changed

+31
-30
lines changed

pkg/cloud/cloud.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func (c *cloud) WaitForFileSystemAvailable(ctx context.Context, fileSystemId str
228228
if err != nil {
229229
return true, err
230230
}
231-
klog.V(2).Infof("WaitForFileSystemAvailable filesystem %q status is: %q", fileSystemId, *fs.Lifecycle)
231+
klog.V(2).InfoS("WaitForFileSystemAvailable", "filesystem", fileSystemId, "lifecycle", *fs.Lifecycle)
232232
switch *fs.Lifecycle {
233233
case fsx.FileSystemLifecycleAvailable:
234234
return true, nil
@@ -248,7 +248,7 @@ func (c *cloud) WaitForFileSystemResize(ctx context.Context, fileSystemId string
248248
if err != nil {
249249
return true, err
250250
}
251-
klog.V(2).Infof("WaitForFileSystemResize filesystem %q update status is: %q", fileSystemId, *updateAction.Status)
251+
klog.V(2).InfoS("WaitForFileSystemResize", "filesystem", fileSystemId, "update status", *updateAction.Status)
252252
switch *updateAction.Status {
253253
case fsx.StatusPending, fsx.StatusInProgress:
254254
return false, nil
@@ -328,7 +328,7 @@ func (c *cloud) WaitForVolumeAvailable(ctx context.Context, volumeId string) err
328328
if err != nil {
329329
return true, err
330330
}
331-
klog.V(2).Infof("WaitForVolumeAvailable volume %q status is: %q", volumeId, *v.Lifecycle)
331+
klog.V(2).InfoS("WaitForVolumeAvailable", "volume", volumeId, "lifecycle", *v.Lifecycle)
332332
switch *v.Lifecycle {
333333
case fsx.VolumeLifecycleAvailable:
334334
return true, nil
@@ -342,13 +342,14 @@ func (c *cloud) WaitForVolumeAvailable(ctx context.Context, volumeId string) err
342342
return err
343343
}
344344

345+
// WaitForVolumeResize TODO: Remove this function and its associated tests.
345346
func (c *cloud) WaitForVolumeResize(ctx context.Context, volumeId string, resizeGiB int64) error {
346347
err := wait.Poll(PollCheckInterval, PollCheckTimeout, func() (done bool, err error) {
347348
updateAction, err := c.getUpdateResizeVolumeAdministrativeAction(ctx, volumeId, resizeGiB)
348349
if err != nil {
349350
return true, err
350351
}
351-
klog.V(2).Infof("WaitForVolumeResize volume %q update status is: %q", volumeId, *updateAction.Status)
352+
klog.V(2).InfoS("WaitForVolumeResize", "volume", volumeId, "update status", *updateAction.Status)
352353
switch *updateAction.Status {
353354
case fsx.StatusPending, fsx.StatusInProgress:
354355
return false, nil
@@ -381,7 +382,7 @@ func (c *cloud) CreateSnapshot(ctx context.Context, parameters map[string]string
381382
if output == nil {
382383
return nil, fmt.Errorf("nil CreateSnapshotResponse")
383384
}
384-
klog.V(4).Infof("CreateSnapshotResponse: ", output.GoString())
385+
klog.V(4).InfoS("CreateSnapshotResponse", "response", output.GoString())
385386
return &Snapshot{
386387
SnapshotID: aws.StringValue(output.Snapshot.SnapshotId),
387388
SourceVolumeID: aws.StringValue(output.Snapshot.VolumeId),
@@ -432,7 +433,7 @@ func (c *cloud) WaitForSnapshotAvailable(ctx context.Context, snapshotId string)
432433
if err != nil {
433434
return true, err
434435
}
435-
klog.V(2).Infof("WaitForSnapshotAvailable: Snapshot %s status is %q", snapshotId, *snapshot.Lifecycle)
436+
klog.V(2).InfoS("WaitForSnapshotAvailable", "snapshot", snapshotId, "lifecycle", *snapshot.Lifecycle)
436437
switch *snapshot.Lifecycle {
437438
case fsx.SnapshotLifecycleAvailable:
438439
return true, nil

pkg/driver/controller.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func newControllerService(driverOptions *DriverOptions) controllerService {
126126
}
127127

128128
func (d *controllerService) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) {
129-
klog.V(4).Infof("CreateVolume: called with args %#v", req)
129+
klog.V(4).InfoS("CreateVolume: called with", "args", *req)
130130

131131
volName := req.GetName()
132132
if len(volName) == 0 {
@@ -200,7 +200,7 @@ func (d *controllerService) CreateVolume(ctx context.Context, req *csi.CreateVol
200200

201201
fs, err := d.cloud.CreateFileSystem(ctx, volumeParams)
202202
if err != nil {
203-
klog.V(4).Infof("CreateFileSystem error: ", err.Error())
203+
klog.V(4).InfoS("CreateFileSystem", "error", err.Error())
204204
switch {
205205
case errors.Is(err, cloud.ErrInvalidInput):
206206
return nil, status.Error(codes.InvalidArgument, err.Error())
@@ -272,7 +272,7 @@ func (d *controllerService) CreateVolume(ctx context.Context, req *csi.CreateVol
272272

273273
v, err := d.cloud.CreateVolume(ctx, volumeParams)
274274
if err != nil {
275-
klog.V(4).Infof("CreateVolume error: ", err.Error())
275+
klog.V(4).InfoS("CreateVolume", "error", err.Error())
276276
switch {
277277
case errors.Is(err, cloud.ErrInvalidInput):
278278
return nil, status.Error(codes.InvalidArgument, err.Error())
@@ -349,7 +349,7 @@ func (d *controllerService) DeleteVolume(ctx context.Context, req *csi.DeleteVol
349349

350350
if err != nil {
351351
if err == cloud.ErrNotFound {
352-
klog.V(4).Infof("DeleteVolume: volume not found, returning with success")
352+
klog.V(4).InfoS("DeleteVolume: volume not found, returning with success", "volumeId", volumeID)
353353
return &csi.DeleteVolumeResponse{}, nil
354354
}
355355
return nil, status.Errorf(codes.Internal, "Could not delete volume ID %q: %v", volumeID, err)
@@ -367,7 +367,7 @@ func (d *controllerService) ControllerUnpublishVolume(ctx context.Context, req *
367367
}
368368

369369
func (d *controllerService) ValidateVolumeCapabilities(ctx context.Context, req *csi.ValidateVolumeCapabilitiesRequest) (*csi.ValidateVolumeCapabilitiesResponse, error) {
370-
klog.V(4).Infof("ValidateVolumeCapabilities: called with args %#v", req)
370+
klog.V(4).InfoS("ValidateVolumeCapabilities: called with", "args", *req)
371371
var err error
372372

373373
volumeID := req.GetVolumeId()
@@ -441,7 +441,7 @@ func (d *controllerService) GetCapacity(ctx context.Context, req *csi.GetCapacit
441441
}
442442

443443
func (d *controllerService) ControllerGetCapabilities(ctx context.Context, req *csi.ControllerGetCapabilitiesRequest) (*csi.ControllerGetCapabilitiesResponse, error) {
444-
klog.V(4).Infof("ControllerGetCapabilities: called with args %#v", req)
444+
klog.V(4).InfoS("ControllerGetCapabilities: called with", "args", *req)
445445
var caps []*csi.ControllerServiceCapability
446446
for _, cap := range controllerCaps {
447447
c := &csi.ControllerServiceCapability{
@@ -457,7 +457,7 @@ func (d *controllerService) ControllerGetCapabilities(ctx context.Context, req *
457457
}
458458

459459
func (d *controllerService) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequest) (*csi.CreateSnapshotResponse, error) {
460-
klog.V(4).Infof("CreateSnapshot: called with args %#v", req)
460+
klog.V(4).InfoS("CreateSnapshot: called with", "args", *req)
461461

462462
if len(req.GetName()) == 0 {
463463
return nil, status.Error(codes.InvalidArgument, "Snapshot name not provided")
@@ -528,7 +528,7 @@ func (d *controllerService) CreateSnapshot(ctx context.Context, req *csi.CreateS
528528
}
529529

530530
func (d *controllerService) DeleteSnapshot(ctx context.Context, req *csi.DeleteSnapshotRequest) (*csi.DeleteSnapshotResponse, error) {
531-
klog.V(4).Infof("DeleteSnapshot: called with args %#v", req)
531+
klog.V(4).InfoS("DeleteSnapshot: called with", "args", *req)
532532
deleteParams := make(map[string]string)
533533
snapshotId := req.GetSnapshotId()
534534

@@ -547,7 +547,7 @@ func (d *controllerService) DeleteSnapshot(ctx context.Context, req *csi.DeleteS
547547

548548
if err := d.cloud.DeleteSnapshot(ctx, deleteParams); err != nil {
549549
if strings.Contains(err.Error(), "Unable to find snapshot") {
550-
klog.V(4).Infof("DeleteSnapshot: Snapshot %s not found, returning with success", snapshotId)
550+
klog.V(4).InfoS("DeleteSnapshot: Snapshot not found, returning with success", "snapshotId", snapshotId)
551551
return &csi.DeleteSnapshotResponse{}, nil
552552
}
553553
return nil, status.Errorf(codes.Internal, "DeleteSnapshot: Could not delete snapshot %s, received error %v", snapshotId, err)
@@ -561,7 +561,7 @@ func (d *controllerService) ListSnapshots(ctx context.Context, req *csi.ListSnap
561561
}
562562

563563
func (d *controllerService) ControllerExpandVolume(ctx context.Context, req *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) {
564-
klog.V(4).Infof("ControllerExpandVolume: called with args %+v", *req)
564+
klog.V(4).InfoS("ControllerExpandVolume: called with", "args", *req)
565565

566566
volumeID := req.GetVolumeId()
567567
if len(volumeID) == 0 {
@@ -597,7 +597,7 @@ func (d *controllerService) ControllerExpandVolume(ctx context.Context, req *csi
597597

598598
if newCapacity <= fs.StorageCapacity {
599599
// Current capacity is sufficient to satisfy the request
600-
klog.V(4).Infof("ControllerExpandVolume: current filesystem capacity of %d GiB matches or exceeds requested storage capacity of %d GiB, returning with success", fs.StorageCapacity, newCapacity)
600+
klog.V(4).InfoS("ControllerExpandVolume: current filesystem capacity matches or exceeds requested storage capacity, returning with success", "currentStorageCapacityGiB", fs.StorageCapacity, "requestedStorageCapacityGiB", newCapacity)
601601
return &csi.ControllerExpandVolumeResponse{
602602
CapacityBytes: util.GiBToBytes(fs.StorageCapacity),
603603
NodeExpansionRequired: false,

pkg/driver/node.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func (d *nodeService) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstag
9494

9595
// NodePublishVolume Mounts the PV at the target path.
9696
func (d *nodeService) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) {
97-
klog.V(4).Infof("NodePublishVolume: Called with args %+v", req)
97+
klog.V(4).InfoS("NodePublishVolume: Called with", "args", *req)
9898

9999
volumeID := req.GetVolumeId()
100100
if len(volumeID) == 0 {
@@ -173,7 +173,7 @@ func (d *nodeService) NodePublishVolume(ctx context.Context, req *csi.NodePublis
173173
}
174174
}
175175

176-
klog.V(5).Infof("NodePublishVolume: Creating dir %s", targetPath)
176+
klog.V(5).InfoS("NodePublishVolume: creating", "dir", targetPath)
177177
if err := d.mounter.MakeDir(targetPath); err != nil {
178178
return nil, status.Errorf(codes.Internal, "NodePublishVolume: Could not create target dir %q: %v", targetPath, err)
179179
}
@@ -185,9 +185,9 @@ func (d *nodeService) NodePublishVolume(ctx context.Context, req *csi.NodePublis
185185
}
186186

187187
if mounted {
188-
klog.V(5).Infof("NodePublishVolume: Target dir %q is already mounted with a volume. Not mounting volume source %q", targetPath, source)
188+
klog.V(5).InfoS("NodePublishVolume: Target path is already mounted with a volume. Not mounting.", "targetPath", targetPath, "source", source)
189189
} else {
190-
klog.V(5).Infof("NodePublishVolume: Attempting to mount with volumeID(%v) source(%s) targetPath(%s) mountflags(%v)", volumeID, source, targetPath, mountOptions)
190+
klog.V(5).InfoS("NodePublishVolume: Attempting to mount", "volumeId", volumeID, "source", source, "targetPath", targetPath, "mountOptions", mountOptions)
191191
err = d.mounter.Mount(source, targetPath, "nfs", mountOptions)
192192
if err != nil {
193193
if os.IsPermission(err) {
@@ -198,14 +198,14 @@ func (d *nodeService) NodePublishVolume(ctx context.Context, req *csi.NodePublis
198198
}
199199
return nil, status.Error(codes.Internal, err.Error())
200200
}
201-
klog.V(5).Infof("NodePublishVolume: Successfully mounted at target path %s", targetPath)
201+
klog.V(5).InfoS("NodePublishVolume: Successfully mounted at", "targetPath", targetPath)
202202
}
203203
return &csi.NodePublishVolumeResponse{}, nil
204204
}
205205

206206
// NodeUnpublishVolume Unmounts the volume from the target path
207207
func (d *nodeService) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error) {
208-
klog.V(4).Infof("NodeUnpublishVolume: Called with args %+v", req)
208+
klog.V(4).InfoS("NodeUnpublishVolume: called with", "args", *req)
209209

210210
volumeID := req.GetVolumeId()
211211
if len(volumeID) == 0 {
@@ -228,11 +228,11 @@ func (d *nodeService) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu
228228
// Check if the target is mounted before unmounting
229229
notMnt, _ := d.mounter.IsLikelyNotMountPoint(targetPath)
230230
if notMnt {
231-
klog.V(5).Infof("NodeUnpublishVolume: Target path %s not mounted, skipping unmount", targetPath)
231+
klog.V(5).InfoS("NodeUnpublishVolume: Target path not mounted, skipping unmount", "targetPath", targetPath)
232232
return &csi.NodeUnpublishVolumeResponse{}, nil
233233
}
234234

235-
klog.V(5).Infof("NodeUnpublishVolume: Unmounting %s", targetPath)
235+
klog.V(5).InfoS("NodeUnpublishVolume: Unmounting", "targetPath", targetPath)
236236
err := d.mounter.Unmount(targetPath)
237237
if err != nil {
238238
return nil, status.Errorf(codes.Internal, "NodeUnpublishVolume: Could not unmount %q: %v", targetPath, err)
@@ -256,7 +256,7 @@ func (d *nodeService) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandV
256256

257257
// NodeGetCapabilities Returns the capabilities of the Node plugin
258258
func (d *nodeService) NodeGetCapabilities(ctx context.Context, req *csi.NodeGetCapabilitiesRequest) (*csi.NodeGetCapabilitiesResponse, error) {
259-
klog.V(4).Infof("NodeGetCapabilities: Called with args %+v", req)
259+
klog.V(4).InfoS("NodeGetCapabilities: Called with", "args", req)
260260
var caps []*csi.NodeServiceCapability
261261
for _, cap := range nodeCaps {
262262
c := &csi.NodeServiceCapability{
@@ -273,7 +273,7 @@ func (d *nodeService) NodeGetCapabilities(ctx context.Context, req *csi.NodeGetC
273273

274274
// NodeGetInfo Returns the id of the node on which the plugin is running
275275
func (d *nodeService) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error) {
276-
klog.V(4).Infof("NodeGetInfo: called with args %+v", req)
276+
klog.V(4).InfoS("NodeGetInfo: called with", "args", *req)
277277
return &csi.NodeGetInfoResponse{
278278
NodeId: d.metadata.GetInstanceID(),
279279
}, nil
@@ -295,7 +295,7 @@ func (d *nodeService) isMounted(source string, targetPath string) (bool, error)
295295
// If the error is related to a corrupted mount, we can unmount then re-mount the volume.
296296
_, pathErr := d.mounter.PathExists(targetPath)
297297
if pathErr != nil && d.mounter.IsCorruptedMnt(pathErr) {
298-
klog.V(4).Infof("NodePublishVolume: Target path %q is a corrupted mount. Trying to unmount.", targetPath)
298+
klog.V(4).InfoS("NodePublishVolume: Target path is a corrupted mount. Trying to unmount.", "targetPath", targetPath)
299299
if mntErr := d.mounter.Unmount(targetPath); mntErr != nil {
300300
return false, status.Errorf(codes.Internal, "NodePublishVolume: Unable to unmount the target %q : %v", targetPath, mntErr)
301301
}
@@ -312,12 +312,12 @@ func (d *nodeService) isMounted(source string, targetPath string) (bool, error)
312312
// and in others it is an error (in Linux, the target mount directory must
313313
// exist before mount is called on it)
314314
if err != nil && os.IsNotExist(err) {
315-
klog.V(5).Infof("[Debug] NodePublishVolume: Target path %q does not exist", targetPath)
315+
klog.V(5).InfoS("[Debug] NodePublishVolume: Target path does not exist", "targetPath", targetPath)
316316
return false, nil
317317
}
318318

319319
if !notMnt {
320-
klog.V(4).Infof("NodePublishVolume: Target path %q is already mounted", targetPath)
320+
klog.V(4).InfoS("NodePublishVolume: Target path is already mounted", "targetPath", targetPath)
321321
}
322322

323323
return !notMnt, nil

0 commit comments

Comments
 (0)