From b3778ca9d7f5bdeb65805f4ff3c30e20dc2fde6a Mon Sep 17 00:00:00 2001 From: Jiaxun Song Date: Mon, 15 Jan 2024 23:35:10 +0000 Subject: [PATCH] improve csi mount logs --- pkg/csi_driver/node.go | 2 +- pkg/csi_mounter/csi_mounter.go | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pkg/csi_driver/node.go b/pkg/csi_driver/node.go index e6e378bd8..d9febc1bc 100644 --- a/pkg/csi_driver/node.go +++ b/pkg/csi_driver/node.go @@ -198,7 +198,7 @@ func (s *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublish // Put an exit file to notify the sidecar container to exit if (isOwnedByJob || podRestartPolicyIsNever) && sidecarShouldExit { - klog.V(4).Info("all the other containers terminated in the Pod, put the exit file.") + klog.V(4).Infof("[Pod %v/%v, UID %v] all the other containers terminated in the Pod, put the exit file.", pod.Namespace, pod.Name, pod.UID) exitFilePath := filepath.Dir(emptyDirBasePath) + "/exit" f, err := os.Create(exitFilePath) if err != nil { diff --git a/pkg/csi_mounter/csi_mounter.go b/pkg/csi_mounter/csi_mounter.go index b2284ec13..950c02d66 100644 --- a/pkg/csi_mounter/csi_mounter.go +++ b/pkg/csi_mounter/csi_mounter.go @@ -67,20 +67,23 @@ func (m *Mounter) Mount(source string, target string, fstype string, options []s return fmt.Errorf("failed to prepare emptyDir path: %w", err) } - klog.V(4).Info("opening the device /dev/fuse") + podID, volumeName, _ := util.ParsePodIDVolumeFromTargetpath(target) + logPrefix := fmt.Sprintf("[Pod %v, Volume %v, Bucket %v]", podID, volumeName, source) + + klog.V(4).Infof("%v opening the device /dev/fuse", logPrefix) fd, err := syscall.Open("/dev/fuse", syscall.O_RDWR, 0o644) if err != nil { return fmt.Errorf("failed to open the device /dev/fuse: %w", err) } csiMountOptions = append(csiMountOptions, fmt.Sprintf("fd=%v", fd)) - klog.V(4).Info("mounting the fuse filesystem") + klog.V(4).Infof("%v mounting the fuse filesystem", logPrefix) err = m.MountSensitiveWithoutSystemdWithMountFlags(source, target, fstype, csiMountOptions, nil, []string{"--internal-only"}) if err != nil { return fmt.Errorf("failed to mount the fuse filesystem: %w", err) } - klog.V(4).Info("passing the descriptor") + klog.V(4).Infof("%v passing the descriptor", logPrefix) // Need to change the current working directory to the temp volume base path, // because the socket absolute path is longer than 104 characters, // which will cause "bind: invalid argument" errors. @@ -93,7 +96,7 @@ func (m *Mounter) Mount(source string, target string, fstype string, options []s return fmt.Errorf("failed to change directory to %q: %w", emptyDirBasePath, err) } - klog.V(4).Info("creating a listener for the socket") + klog.V(4).Infof("%v creating a listener for the socket", logPrefix) l, err := net.Listen("unix", "./socket") if err != nil { return fmt.Errorf("failed to create the listener for the socket: %w", err) @@ -136,13 +139,10 @@ func (m *Mounter) Mount(source string, target string, fstype string, options []s } // Asynchronously waiting for the sidecar container to connect to the listener - go func(l net.Listener, bucketName, target string, msg []byte, fd int) { + go func(l net.Listener, logPrefix string, msg []byte, fd int) { defer syscall.Close(fd) defer l.Close() - podID, volumeName, _ := util.ParsePodIDVolumeFromTargetpath(target) - logPrefix := fmt.Sprintf("[Pod %v, Volume %v, Bucket %v]", podID, volumeName, bucketName) - klog.V(4).Infof("%v start to accept connections to the listener.", logPrefix) a, err := l.Accept() if err != nil { @@ -158,7 +158,7 @@ func (m *Mounter) Mount(source string, target string, fstype string, options []s } klog.V(4).Infof("%v exiting the goroutine.", logPrefix) - }(l, source, target, mcb, fd) + }(l, logPrefix, mcb, fd) return nil }