From 35e5340bf183152815668e404c65b716f4fc7876 Mon Sep 17 00:00:00 2001 From: Jacob Wolf Date: Thu, 25 May 2023 18:35:17 +0000 Subject: [PATCH] Update log functions --- pkg/cloud/cloud.go | 4 ++-- pkg/driver/controller.go | 18 +++++++++--------- pkg/driver/driver.go | 6 +++--- pkg/driver/internal/inflight.go | 2 +- pkg/driver/node.go | 26 +++++++++++++------------- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/pkg/cloud/cloud.go b/pkg/cloud/cloud.go index d07ea393..00afb8ee 100644 --- a/pkg/cloud/cloud.go +++ b/pkg/cloud/cloud.go @@ -338,7 +338,7 @@ func (c *cloud) WaitForFileSystemAvailable(ctx context.Context, fileSystemId str if err != nil { return true, err } - klog.V(2).Infof("WaitForFileSystemAvailable filesystem %q status is: %q", fileSystemId, *fs.Lifecycle) + klog.V(2).InfoS("WaitForFileSystemAvailable", "filesystem", fileSystemId, "status", *fs.Lifecycle) switch *fs.Lifecycle { case "AVAILABLE": return true, nil @@ -361,7 +361,7 @@ func (c *cloud) WaitForFileSystemResize(ctx context.Context, fileSystemId string return true, err } - klog.V(2).Infof("WaitForFileSystemResize filesystem %q update status is: %q", fileSystemId, *updateAction.Status) + klog.V(2).InfoS("WaitForFileSystemResize", "filesystem", fileSystemId, "update status", *updateAction.Status) switch *updateAction.Status { case "PENDING", "IN_PROGRESS": // The resizing workflow has not completed diff --git a/pkg/driver/controller.go b/pkg/driver/controller.go index 9792a1b1..24d1b4ce 100644 --- a/pkg/driver/controller.go +++ b/pkg/driver/controller.go @@ -106,7 +106,7 @@ func newControllerService(driverOptions *DriverOptions) controllerService { } } func (d *controllerService) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) { - klog.V(4).Infof("CreateVolume: called with args %#v", req) + klog.V(4).InfoS("CreateVolume: called", "args", *req) volName := req.GetName() if len(volName) == 0 { return nil, status.Error(codes.InvalidArgument, "Volume name not provided") @@ -237,7 +237,7 @@ func (d *controllerService) CreateVolume(ctx context.Context, req *csi.CreateVol } func (d *controllerService) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest) (*csi.DeleteVolumeResponse, error) { - klog.V(4).Infof("DeleteVolume: called with args: %#v", req) + klog.V(4).InfoS("DeleteVolume: called", "args", *req) volumeID := req.GetVolumeId() if len(volumeID) == 0 { return nil, status.Error(codes.InvalidArgument, "Volume ID not provided") @@ -252,7 +252,7 @@ func (d *controllerService) DeleteVolume(ctx context.Context, req *csi.DeleteVol if err := d.cloud.DeleteFileSystem(ctx, volumeID); err != nil { if err == cloud.ErrNotFound { - klog.V(4).Infof("DeleteVolume: volume not found, returning with success") + klog.V(4).InfoS("DeleteVolume: volume not found, returning with success") return &csi.DeleteVolumeResponse{}, nil } return nil, status.Errorf(codes.Internal, "Could not delete volume ID %q: %v", volumeID, err) @@ -269,7 +269,7 @@ func (d *controllerService) ControllerUnpublishVolume(ctx context.Context, req * } func (d *controllerService) ControllerGetCapabilities(ctx context.Context, req *csi.ControllerGetCapabilitiesRequest) (*csi.ControllerGetCapabilitiesResponse, error) { - klog.V(4).Infof("ControllerGetCapabilities: called with args %#v", req) + klog.V(4).InfoS("ControllerGetCapabilities: called", "args", *req) var caps []*csi.ControllerServiceCapability for _, cap := range controllerCaps { c := &csi.ControllerServiceCapability{ @@ -285,17 +285,17 @@ func (d *controllerService) ControllerGetCapabilities(ctx context.Context, req * } func (d *controllerService) GetCapacity(ctx context.Context, req *csi.GetCapacityRequest) (*csi.GetCapacityResponse, error) { - klog.V(4).Infof("GetCapacity: called with args %#v", req) + klog.V(4).InfoS("GetCapacity: called", "args", *req) return nil, status.Error(codes.Unimplemented, "") } func (d *controllerService) ListVolumes(ctx context.Context, req *csi.ListVolumesRequest) (*csi.ListVolumesResponse, error) { - klog.V(4).Infof("ListVolumes: called with args %#v", req) + klog.V(4).InfoS("ListVolumes: called", "args", *req) return nil, status.Error(codes.Unimplemented, "") } func (d *controllerService) ValidateVolumeCapabilities(ctx context.Context, req *csi.ValidateVolumeCapabilitiesRequest) (*csi.ValidateVolumeCapabilitiesResponse, error) { - klog.V(4).Infof("ValidateVolumeCapabilities: called with args %#v", req) + klog.V(4).InfoS("ValidateVolumeCapabilities: called", "args", *req) volumeID := req.GetVolumeId() if len(volumeID) == 0 { return nil, status.Error(codes.InvalidArgument, "Volume ID not provided") @@ -361,7 +361,7 @@ func (d *controllerService) ListSnapshots(ctx context.Context, req *csi.ListSnap } func (d *controllerService) ControllerExpandVolume(ctx context.Context, req *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) { - klog.V(4).Infof("ControllerExpandVolume: called with args %+v", *req) + klog.V(4).InfoS("ControllerExpandVolume: called", "args", *req) volumeID := req.GetVolumeId() if len(volumeID) == 0 { return nil, status.Error(codes.InvalidArgument, "Volume ID not provided") @@ -389,7 +389,7 @@ func (d *controllerService) ControllerExpandVolume(ctx context.Context, req *csi } if newSizeGiB <= fs.CapacityGiB { // Current capacity is sufficient to satisfy the request - klog.V(4).Infof("ControllerExpandVolume: current filesystem capacity of %d GiB matches or exceeds requested storage capacity of %d GiB, returning with success", fs.CapacityGiB, newSizeGiB) + klog.V(4).InfoS("ControllerExpandVolume: current filesystem capacity matches or exceeds requested storage capacity, returning with success", "current capacity", fs.CapacityGiB, "requested capacity", newSizeGiB) return &csi.ControllerExpandVolumeResponse{ CapacityBytes: util.GiBToBytes(fs.CapacityGiB), NodeExpansionRequired: false, diff --git a/pkg/driver/driver.go b/pkg/driver/driver.go index ab7acfb5..46368d86 100644 --- a/pkg/driver/driver.go +++ b/pkg/driver/driver.go @@ -100,7 +100,7 @@ func (d *Driver) Run() error { logErr := func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { resp, err := handler(ctx, req) if err != nil { - klog.Errorf("GRPC error: %v", err) + klog.ErrorS(err, "GRPC error") } return resp, err } @@ -123,12 +123,12 @@ func (d *Driver) Run() error { return fmt.Errorf("unknown mode: %s", d.options.mode) } - klog.Infof("Listening for connections on address: %#v", listener.Addr()) + klog.V(4).InfoS("Listening for connections", "address", listener.Addr()) return d.srv.Serve(listener) } func (d *Driver) Stop() { - klog.Infof("Stopping server") + klog.InfoS("Stopping server") d.srv.Stop() } diff --git a/pkg/driver/internal/inflight.go b/pkg/driver/internal/inflight.go index 8727f876..017ece18 100644 --- a/pkg/driver/internal/inflight.go +++ b/pkg/driver/internal/inflight.go @@ -70,5 +70,5 @@ func (db *InFlight) Delete(key string) { defer db.mux.Unlock() delete(db.inFlight, key) - klog.V(4).InfoS("Node Service: volume operation finished", "key", key) + klog.V(4).InfoS("Volume operation finished", "key", key) } diff --git a/pkg/driver/node.go b/pkg/driver/node.go index 9f8acbe1..c098097b 100644 --- a/pkg/driver/node.go +++ b/pkg/driver/node.go @@ -82,7 +82,7 @@ func (d *nodeService) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstag } func (d *nodeService) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) { - klog.V(4).Infof("NodePublishVolume: called with args %+v", req) + klog.V(4).InfoS("NodePublishVolume: called with", "args", *req) volumeID := req.GetVolumeId() if len(volumeID) == 0 { @@ -137,7 +137,7 @@ func (d *nodeService) NodePublishVolume(ctx context.Context, req *csi.NodePublis } } } - klog.V(5).Infof("NodePublishVolume: creating dir %s", target) + klog.V(5).InfoS("NodePublishVolume: creating", "dir", target) if err := d.mounter.MakeDir(target); err != nil { return nil, status.Errorf(codes.Internal, "Could not create dir %q: %v", target, err) } @@ -148,19 +148,19 @@ func (d *nodeService) NodePublishVolume(ctx context.Context, req *csi.NodePublis return nil, status.Errorf(codes.Internal, "Could not check if %q is mounted: %v", target, err) } if !mounted { - klog.V(5).Infof("NodePublishVolume: mounting %s at %s with options %v", source, target, mountOptions) + klog.V(4).InfoS("NodePublishVolume: mounting", "source", source, "target", target, "mountOptions", mountOptions) if err := d.mounter.Mount(source, target, "lustre", mountOptions); err != nil { os.Remove(target) return nil, status.Errorf(codes.Internal, "Could not mount %q at %q: %v", source, target, err) } - klog.V(5).Infof("NodePublishVolume: %s was mounted", target) + klog.V(5).InfoS("NodePublishVolume: was mounted", "target", target) } return &csi.NodePublishVolumeResponse{}, nil } func (d *nodeService) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error) { - klog.V(4).Infof("NodeUnpublishVolume: called with args %+v", req) + klog.V(4).InfoS("NodeUnpublishVolume: called", "args", *req) volumeID := req.GetVolumeId() if len(volumeID) == 0 { @@ -174,11 +174,11 @@ func (d *nodeService) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu // Check if the target is mounted before unmounting notMnt, _ := d.mounter.IsLikelyNotMountPoint(target) if notMnt { - klog.V(5).Infof("NodeUnpublishVolume: target path %s not mounted, skipping unmount", target) + klog.V(5).InfoS("NodeUnpublishVolume: target path not mounted, skipping unmount", "target", target) return &csi.NodeUnpublishVolumeResponse{}, nil } - klog.V(5).Infof("NodeUnpublishVolume: unmounting %s", target) + klog.V(5).InfoS("NodeUnpublishVolume: unmounting", "target", target) err := d.mounter.Unmount(target) if err != nil { return nil, status.Errorf(codes.Internal, "Could not unmount %q: %v", target, err) @@ -196,7 +196,7 @@ func (d *nodeService) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandV } func (d *nodeService) NodeGetCapabilities(ctx context.Context, req *csi.NodeGetCapabilitiesRequest) (*csi.NodeGetCapabilitiesResponse, error) { - klog.V(4).Infof("NodeGetCapabilities: called with args %+v", req) + klog.V(4).InfoS("NodeGetCapabilities: called", "args", *req) var caps []*csi.NodeServiceCapability for _, cap := range nodeCaps { c := &csi.NodeServiceCapability{ @@ -212,7 +212,7 @@ func (d *nodeService) NodeGetCapabilities(ctx context.Context, req *csi.NodeGetC } func (d *nodeService) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error) { - klog.V(4).Infof("NodeGetInfo: called with args %+v", req) + klog.V(4).InfoS("NodeGetInfo: called", "args", *req) return &csi.NodeGetInfoResponse{ NodeId: d.metadata.GetInstanceID(), @@ -228,13 +228,13 @@ func (d *nodeService) isMounted(source string, target string) (bool, error) { 2. false, nil when the path is already mounted with a device. 3. true, nil when the path is not mounted with any device. */ - klog.V(4).Infoln(target) + klog.V(4).InfoS(target) notMnt, err := d.mounter.IsLikelyNotMountPoint(target) if err != nil && !os.IsNotExist(err) { //Checking if the path exists and error is related to Corrupted Mount, in that case, the system could unmount and mount. _, pathErr := d.mounter.PathExists(target) if pathErr != nil && d.mounter.IsCorruptedMnt(pathErr) { - klog.V(4).Infof("NodePublishVolume: Target path %q is a corrupted mount. Trying to unmount.", target) + klog.V(4).InfoS("NodePublishVolume: Target path is a corrupted mount. Trying to unmount.", "target", target) if mntErr := d.mounter.Unmount(target); mntErr != nil { return false, status.Errorf(codes.Internal, "Unable to unmount the target %q : %v", target, mntErr) } @@ -251,12 +251,12 @@ func (d *nodeService) isMounted(source string, target string) (bool, error) { // and in others it is an error (in Linux, the target mount directory must // exist before mount is called on it) if err != nil && os.IsNotExist(err) { - klog.V(5).Infof("[Debug] NodePublishVolume: Target path %q does not exist", target) + klog.V(5).InfoS("[Debug] NodePublishVolume: Target path does not exist", "target", target) return false, nil } if !notMnt { - klog.V(4).Infof("NodePublishVolume: Target path %q is already mounted", target) + klog.V(4).InfoS("NodePublishVolume: Target path is already mounted", "target", target) } return !notMnt, nil