Skip to content

Commit 7c97578

Browse files
committed
Adopt Kubernetes standard logging patterns
1 parent bec107d commit 7c97578

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 {
@@ -165,7 +165,7 @@ func (d *nodeService) NodePublishVolume(ctx context.Context, req *csi.NodePublis
165165
}
166166
}
167167

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

179179
if mounted {
180-
klog.V(5).Infof("NodePublishVolume: Target dir %q is already mounted with a volume. Not mounting volume source %q", targetPath, source)
180+
klog.V(5).InfoS("NodePublishVolume: Target path is already mounted with a volume. Not mounting.", "targetPath", targetPath, "source", source)
181181
} else {
182-
klog.V(5).Infof("NodePublishVolume: Attempting to mount with volumeID(%v) source(%s) targetPath(%s) mountflags(%v)", volumeID, source, targetPath, mountOptions)
182+
klog.V(5).InfoS("NodePublishVolume: Attempting to mount", "volumeId", volumeID, "source", source, "targetPath", targetPath, "mountOptions", mountOptions)
183183
err = d.mounter.Mount(source, targetPath, "nfs", mountOptions)
184184
if err != nil {
185185
if os.IsPermission(err) {
@@ -190,14 +190,14 @@ func (d *nodeService) NodePublishVolume(ctx context.Context, req *csi.NodePublis
190190
}
191191
return nil, status.Error(codes.Internal, err.Error())
192192
}
193-
klog.V(5).Infof("NodePublishVolume: Successfully mounted at target path %s", targetPath)
193+
klog.V(5).InfoS("NodePublishVolume: Successfully mounted at", "targetPath", targetPath)
194194
}
195195
return &csi.NodePublishVolumeResponse{}, nil
196196
}
197197

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

202202
volumeID := req.GetVolumeId()
203203
if len(volumeID) == 0 {
@@ -212,11 +212,11 @@ func (d *nodeService) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu
212212
// Check if the target is mounted before unmounting
213213
notMnt, _ := d.mounter.IsLikelyNotMountPoint(targetPath)
214214
if notMnt {
215-
klog.V(5).Infof("NodeUnpublishVolume: Target path %s not mounted, skipping unmount", targetPath)
215+
klog.V(5).InfoS("NodeUnpublishVolume: Target path not mounted, skipping unmount", "targetPath", targetPath)
216216
return &csi.NodeUnpublishVolumeResponse{}, nil
217217
}
218218

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

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

258258
// NodeGetInfo Returns the id of the node on which the plugin is running
259259
func (d *nodeService) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error) {
260-
klog.V(4).Infof("NodeGetInfo: called with args %+v", req)
260+
klog.V(4).InfoS("NodeGetInfo: called with", "args", *req)
261261
return &csi.NodeGetInfoResponse{
262262
NodeId: d.metadata.GetInstanceID(),
263263
}, nil
@@ -279,7 +279,7 @@ func (d *nodeService) isMounted(source string, targetPath string) (bool, error)
279279
// If the error is related to a corrupted mount, we can unmount then re-mount the volume.
280280
_, pathErr := d.mounter.PathExists(targetPath)
281281
if pathErr != nil && d.mounter.IsCorruptedMnt(pathErr) {
282-
klog.V(4).Infof("NodePublishVolume: Target path %q is a corrupted mount. Trying to unmount.", targetPath)
282+
klog.V(4).InfoS("NodePublishVolume: Target path is a corrupted mount. Trying to unmount.", "targetPath", targetPath)
283283
if mntErr := d.mounter.Unmount(targetPath); mntErr != nil {
284284
return false, status.Errorf(codes.Internal, "NodePublishVolume: Unable to unmount the target %q : %v", targetPath, mntErr)
285285
}
@@ -296,12 +296,12 @@ func (d *nodeService) isMounted(source string, targetPath string) (bool, error)
296296
// and in others it is an error (in Linux, the target mount directory must
297297
// exist before mount is called on it)
298298
if err != nil && os.IsNotExist(err) {
299-
klog.V(5).Infof("[Debug] NodePublishVolume: Target path %q does not exist", targetPath)
299+
klog.V(5).InfoS("[Debug] NodePublishVolume: Target path does not exist", "targetPath", targetPath)
300300
return false, nil
301301
}
302302

303303
if !notMnt {
304-
klog.V(4).Infof("NodePublishVolume: Target path %q is already mounted", targetPath)
304+
klog.V(4).InfoS("NodePublishVolume: Target path is already mounted", "targetPath", targetPath)
305305
}
306306

307307
return !notMnt, nil

0 commit comments

Comments
 (0)