From cb77ff5d8739b5ab78b7395c41ec61b39bde392d Mon Sep 17 00:00:00 2001 From: Humble Chirammal Date: Mon, 4 Feb 2019 18:35:07 +0530 Subject: [PATCH] Migrate rbd package to klog from glog Signed-off-by: Humble Chirammal --- pkg/rbd/controllerserver.go | 52 ++++++++++++++++++------------------- pkg/rbd/nodeserver.go | 28 ++++++++++---------- pkg/rbd/rbd.go | 10 +++---- pkg/rbd/rbd_attach.go | 44 +++++++++++++++---------------- pkg/rbd/rbd_util.go | 30 ++++++++++----------- 5 files changed, 82 insertions(+), 82 deletions(-) diff --git a/pkg/rbd/controllerserver.go b/pkg/rbd/controllerserver.go index 04db9a1bc..844423a26 100644 --- a/pkg/rbd/controllerserver.go +++ b/pkg/rbd/controllerserver.go @@ -24,7 +24,6 @@ import ( "github.com/ceph/ceph-csi/pkg/util" "github.com/container-storage-interface/spec/lib/go/csi" - "github.com/golang/glog" "github.com/golang/protobuf/ptypes" "github.com/golang/protobuf/ptypes/timestamp" "github.com/kubernetes-csi/drivers/pkg/csi-common" @@ -33,6 +32,7 @@ import ( "golang.org/x/net/context" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + "k8s.io/klog" ) const ( @@ -68,13 +68,13 @@ func (cs *ControllerServer) LoadExDataFromMetadataStore() error { return nil }) - glog.Infof("Loaded %d volumes and %d snapshots from metadata store", len(rbdVolumes), len(rbdSnapshots)) + klog.Infof("Loaded %d volumes and %d snapshots from metadata store", len(rbdVolumes), len(rbdSnapshots)) return nil } func (cs *ControllerServer) validateVolumeReq(req *csi.CreateVolumeRequest) error { if err := cs.Driver.ValidateControllerServiceRequest(csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME); err != nil { - glog.V(3).Infof("invalid create volume req: %v", req) + klog.V(3).Infof("invalid create volume req: %v", req) return err } // Check sanity of request Name, Volume Capabilities @@ -123,7 +123,7 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol volumeNameMutex.LockKey(req.GetName()) defer func() { if err := volumeNameMutex.UnlockKey(req.GetName()); err != nil { - glog.Warningf("failed to unlock mutex volume:%s %v", req.GetName(), err) + klog.Warningf("failed to unlock mutex volume:%s %v", req.GetName(), err) } }() @@ -160,9 +160,9 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol return nil, err } if createErr := cs.MetadataStore.Create(rbdVol.VolID, rbdVol); createErr != nil { - glog.Warningf("failed to store volume metadata with error: %v", err) + klog.Warningf("failed to store volume metadata with error: %v", err) if err = deleteRBDImage(rbdVol, rbdVol.AdminID, req.GetSecrets()); err != nil { - glog.V(3).Infof("failed to delete rbd image: %s/%s with error: %v", rbdVol.Pool, rbdVol.VolName, err) + klog.V(3).Infof("failed to delete rbd image: %s/%s with error: %v", rbdVol.Pool, rbdVol.VolName, err) return nil, err } return nil, createErr @@ -191,11 +191,11 @@ func (cs *ControllerServer) checkRBDStatus(rbdVol *rbdVolume, req *csi.CreateVol } else { err = createRBDImage(rbdVol, volSizeGB, rbdVol.AdminID, req.GetSecrets()) if err != nil { - glog.Warningf("failed to create volume: %v", err) + klog.Warningf("failed to create volume: %v", err) return err } - glog.V(4).Infof("create volume %s", rbdVol.VolName) + klog.V(4).Infof("create volume %s", rbdVol.VolName) } } return nil @@ -220,7 +220,7 @@ func (cs *ControllerServer) checkSnapshot(req *csi.CreateVolumeRequest, rbdVol * if err != nil { return err } - glog.V(4).Infof("create volume %s from snapshot %s", req.GetName(), rbdSnap.SnapName) + klog.V(4).Infof("create volume %s from snapshot %s", req.GetName(), rbdSnap.SnapName) return nil } @@ -228,7 +228,7 @@ func (cs *ControllerServer) checkSnapshot(req *csi.CreateVolumeRequest, rbdVol * // from store func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest) (*csi.DeleteVolumeResponse, error) { if err := cs.Driver.ValidateControllerServiceRequest(csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME); err != nil { - glog.Warningf("invalid delete volume req: %v", req) + klog.Warningf("invalid delete volume req: %v", req) return nil, err } // For now the image get unconditionally deleted, but here retention policy can be checked @@ -237,7 +237,7 @@ func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol defer func() { if err := volumeIDMutex.UnlockKey(volumeID); err != nil { - glog.Warningf("failed to unlock mutex volume:%s %v", volumeID, err) + klog.Warningf("failed to unlock mutex volume:%s %v", volumeID, err) } }() @@ -251,10 +251,10 @@ func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol volName := rbdVol.VolName // Deleting rbd image - glog.V(4).Infof("deleting volume %s", volName) + klog.V(4).Infof("deleting volume %s", volName) if err := deleteRBDImage(rbdVol, rbdVol.AdminID, req.GetSecrets()); err != nil { // TODO: can we detect "already deleted" situations here and proceed? - glog.V(3).Infof("failed to delete rbd image: %s/%s with error: %v", rbdVol.Pool, volName, err) + klog.V(3).Infof("failed to delete rbd image: %s/%s with error: %v", rbdVol.Pool, volName, err) return nil, err } @@ -302,7 +302,7 @@ func (cs *ControllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS defer func() { if err := snapshotNameMutex.UnlockKey(req.GetName()); err != nil { - glog.Warningf("failed to unlock mutex snapshot:%s %v", req.GetName(), err) + klog.Warningf("failed to unlock mutex snapshot:%s %v", req.GetName(), err) } }() @@ -377,14 +377,14 @@ func (cs *ControllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS func (cs *ControllerServer) storeSnapMetadata(rbdSnap *rbdSnapshot, secret map[string]string) error { errCreate := cs.MetadataStore.Create(rbdSnap.SnapID, rbdSnap) if errCreate != nil { - glog.Warningf("rbd: failed to store snapInfo with error: %v", errCreate) + klog.Warningf("rbd: failed to store snapInfo with error: %v", errCreate) // Unprotect snapshot err := unprotectSnapshot(rbdSnap, rbdSnap.AdminID, secret) if err != nil { return status.Errorf(codes.Unknown, "This Snapshot should be removed but failed to unprotect snapshot: %s/%s with error: %v", rbdSnap.Pool, rbdSnap.SnapName, err) } // Deleting snapshot - glog.V(4).Infof("deleting Snaphot %s", rbdSnap.SnapName) + klog.V(4).Infof("deleting Snaphot %s", rbdSnap.SnapName) if err = deleteSnapshot(rbdSnap, rbdSnap.AdminID, secret); err != nil { return status.Errorf(codes.Unknown, "This Snapshot should be removed but failed to delete snapshot: %s/%s with error: %v", rbdSnap.Pool, rbdSnap.SnapName, err) } @@ -394,7 +394,7 @@ func (cs *ControllerServer) storeSnapMetadata(rbdSnap *rbdSnapshot, secret map[s func (cs *ControllerServer) validateSnapshotReq(req *csi.CreateSnapshotRequest) error { if err := cs.Driver.ValidateControllerServiceRequest(csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT); err != nil { - glog.Warningf("invalid create snapshot req: %v", req) + klog.Warningf("invalid create snapshot req: %v", req) return err } @@ -415,21 +415,21 @@ func (cs *ControllerServer) doSnapshot(rbdSnap *rbdSnapshot, secret map[string]s if exitErr, ok := err.(*exec.ExitError); ok { if status, ok := exitErr.Sys().(syscall.WaitStatus); ok { if status.ExitStatus() == int(syscall.EEXIST) { - glog.Warningf("Snapshot with the same name: %s, we return this.", rbdSnap.SnapName) + klog.Warningf("Snapshot with the same name: %s, we return this.", rbdSnap.SnapName) } else { - glog.Warningf("failed to create snapshot: %v", err) + klog.Warningf("failed to create snapshot: %v", err) return err } } else { - glog.Warningf("failed to create snapshot: %v", err) + klog.Warningf("failed to create snapshot: %v", err) return err } } else { - glog.Warningf("failed to create snapshot: %v", err) + klog.Warningf("failed to create snapshot: %v", err) return err } } else { - glog.V(4).Infof("create snapshot %s", rbdSnap.SnapName) + klog.V(4).Infof("create snapshot %s", rbdSnap.SnapName) err = protectSnapshot(rbdSnap, rbdSnap.AdminID, secret) if err != nil { @@ -447,7 +447,7 @@ func (cs *ControllerServer) doSnapshot(rbdSnap *rbdSnapshot, secret map[string]s //snapshot metadata from store func (cs *ControllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteSnapshotRequest) (*csi.DeleteSnapshotResponse, error) { if err := cs.Driver.ValidateControllerServiceRequest(csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT); err != nil { - glog.Warningf("invalid delete snapshot req: %v", req) + klog.Warningf("invalid delete snapshot req: %v", req) return nil, err } @@ -459,7 +459,7 @@ func (cs *ControllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteS defer func() { if err := snapshotIDMutex.UnlockKey(snapshotID); err != nil { - glog.Warningf("failed to unlock mutex snapshot:%s %v", snapshotID, err) + klog.Warningf("failed to unlock mutex snapshot:%s %v", snapshotID, err) } }() @@ -475,7 +475,7 @@ func (cs *ControllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteS } // Deleting snapshot - glog.V(4).Infof("deleting Snaphot %s", rbdSnap.SnapName) + klog.V(4).Infof("deleting Snaphot %s", rbdSnap.SnapName) if err := deleteSnapshot(rbdSnap, rbdSnap.AdminID, req.GetSecrets()); err != nil { return nil, status.Errorf(codes.FailedPrecondition, "failed to delete snapshot: %s/%s with error: %v", rbdSnap.Pool, rbdSnap.SnapName, err) } @@ -492,7 +492,7 @@ func (cs *ControllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteS // ListSnapshots lists the snapshots in the store func (cs *ControllerServer) ListSnapshots(ctx context.Context, req *csi.ListSnapshotsRequest) (*csi.ListSnapshotsResponse, error) { if err := cs.Driver.ValidateControllerServiceRequest(csi.ControllerServiceCapability_RPC_LIST_SNAPSHOTS); err != nil { - glog.Warningf("invalid list snapshot req: %v", req) + klog.Warningf("invalid list snapshot req: %v", req) return nil, err } diff --git a/pkg/rbd/nodeserver.go b/pkg/rbd/nodeserver.go index 5db7c53d4..d1eb374c1 100644 --- a/pkg/rbd/nodeserver.go +++ b/pkg/rbd/nodeserver.go @@ -23,8 +23,8 @@ import ( "regexp" "strings" - "github.com/golang/glog" "golang.org/x/net/context" + "k8s.io/klog" "github.com/container-storage-interface/spec/lib/go/csi" "google.golang.org/grpc/codes" @@ -63,7 +63,7 @@ func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis defer func() { if err := targetPathMutex.UnlockKey(targetPath); err != nil { - glog.Warningf("failed to unlock mutex targetpath:%s %v", targetPath, err) + klog.Warningf("failed to unlock mutex targetpath:%s %v", targetPath, err) } }() @@ -92,7 +92,7 @@ func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis if err != nil { return nil, err } - glog.V(4).Infof("rbd image: %s/%s was successfully mapped at %s\n", req.GetVolumeId(), volOptions.Pool, devicePath) + klog.V(4).Infof("rbd image: %s/%s was successfully mapped at %s\n", req.GetVolumeId(), volOptions.Pool, devicePath) // Publish Path err = ns.mountVolume(req, devicePath) @@ -130,7 +130,7 @@ func (ns *NodeServer) mountVolume(req *csi.NodePublishVolumeRequest, devicePath isBlock := req.GetVolumeCapability().GetBlock() != nil targetPath := req.GetTargetPath() - glog.V(4).Infof("target %v\nisBlock %v\nfstype %v\ndevice %v\nreadonly %v\nattributes %v\n mountflags %v\n", + klog.V(4).Infof("target %v\nisBlock %v\nfstype %v\ndevice %v\nreadonly %v\nattributes %v\n mountflags %v\n", targetPath, isBlock, fsType, devicePath, readOnly, attrib, mountFlags) diskMounter := &mount.SafeFormatAndMount{Interface: ns.mounter, Exec: mount.NewOsExec()} @@ -162,11 +162,11 @@ func (ns *NodeServer) createTargetPath(targetPath string, isBlock bool) (bool, e // #nosec targetPathFile, e := os.OpenFile(targetPath, os.O_CREATE|os.O_RDWR, 0750) if e != nil { - glog.V(4).Infof("Failed to create targetPath:%s with error: %v", targetPath, err) + klog.V(4).Infof("Failed to create targetPath:%s with error: %v", targetPath, err) return notMnt, status.Error(codes.Internal, e.Error()) } if err = targetPathFile.Close(); err != nil { - glog.V(4).Infof("Failed to close targetPath:%s with error: %v", targetPath, err) + klog.V(4).Infof("Failed to close targetPath:%s with error: %v", targetPath, err) return notMnt, status.Error(codes.Internal, err.Error()) } } else { @@ -191,7 +191,7 @@ func (ns *NodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu defer func() { if err := targetPathMutex.UnlockKey(targetPath); err != nil { - glog.Warningf("failed to unlock mutex targetpath:%s %v", targetPath, err) + klog.Warningf("failed to unlock mutex targetpath:%s %v", targetPath, err) } }() @@ -199,7 +199,7 @@ func (ns *NodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu if err != nil { if os.IsNotExist(err) { // targetPath has already been deleted - glog.V(4).Infof("targetPath: %s has already been deleted", targetPath) + klog.V(4).Infof("targetPath: %s has already been deleted", targetPath) return &csi.NodeUnpublishVolumeResponse{}, nil } return nil, status.Error(codes.NotFound, err.Error()) @@ -230,7 +230,7 @@ func (ns *NodeServer) unmount(targetPath, devicePath string, cnt int) error { if err != nil { return status.Error(codes.Internal, err.Error()) } - glog.V(4).Infof("NodeUnpublishVolume: devicePath: %s, (original)cnt: %d\n", devicePath, cnt) + klog.V(4).Infof("NodeUnpublishVolume: devicePath: %s, (original)cnt: %d\n", devicePath, cnt) // cnt for GetDeviceNameFromMount is broken for bind mouted device, // it counts total number of mounted "devtmpfs", instead of counting this device. // So, forcibly setting cnt to 1 here. @@ -238,12 +238,12 @@ func (ns *NodeServer) unmount(targetPath, devicePath string, cnt int) error { cnt = 1 } - glog.V(4).Infof("NodeUnpublishVolume: targetPath: %s, devicePath: %s\n", targetPath, devicePath) + klog.V(4).Infof("NodeUnpublishVolume: targetPath: %s, devicePath: %s\n", targetPath, devicePath) // Unmounting the image err = ns.mounter.Unmount(targetPath) if err != nil { - glog.V(3).Infof("failed to unmount targetPath: %s with error: %v", targetPath, err) + klog.V(3).Infof("failed to unmount targetPath: %s with error: %v", targetPath, err) return status.Error(codes.Internal, err.Error()) } @@ -255,13 +255,13 @@ func (ns *NodeServer) unmount(targetPath, devicePath string, cnt int) error { // Unmapping rbd device if err = detachRBDDevice(devicePath); err != nil { - glog.V(3).Infof("failed to unmap rbd device: %s with error: %v", devicePath, err) + klog.V(3).Infof("failed to unmap rbd device: %s with error: %v", devicePath, err) return err } // Remove targetPath if err = os.RemoveAll(targetPath); err != nil { - glog.V(3).Infof("failed to remove targetPath: %s with error: %v", targetPath, err) + klog.V(3).Infof("failed to remove targetPath: %s with error: %v", targetPath, err) } return err } @@ -270,7 +270,7 @@ func resolveBindMountedBlockDevice(mountPath string) (string, error) { cmd := exec.Command("findmnt", "-n", "-o", "SOURCE", "--first-only", "--target", mountPath) out, err := cmd.CombinedOutput() if err != nil { - glog.V(2).Infof("Failed findmnt command for path %s: %s %v", mountPath, out, err) + klog.V(2).Infof("Failed findmnt command for path %s: %s %v", mountPath, out, err) return "", err } return parseFindMntResolveSource(string(out)) diff --git a/pkg/rbd/rbd.go b/pkg/rbd/rbd.go index ba83b325f..8740e8c26 100644 --- a/pkg/rbd/rbd.go +++ b/pkg/rbd/rbd.go @@ -17,7 +17,7 @@ limitations under the License. package rbd import ( - "github.com/golang/glog" + "k8s.io/klog" "github.com/ceph/ceph-csi/pkg/util" "github.com/container-storage-interface/spec/lib/go/csi" @@ -88,12 +88,12 @@ func NewNodeServer(d *csicommon.CSIDriver, containerized bool) (*NodeServer, err // rbd CSI driver which can serve multiple parallel requests func (r *Driver) Run(driverName, nodeID, endpoint string, containerized bool, cachePersister util.CachePersister) { var err error - glog.Infof("Driver: %v version: %v", driverName, version) + klog.Infof("Driver: %v version: %v", driverName, version) // Initialize default library driver r.cd = csicommon.NewCSIDriver(driverName, version, nodeID) if r.cd == nil { - glog.Fatalln("Failed to initialize CSI Driver.") + klog.Fatalln("Failed to initialize CSI Driver.") } r.cd.AddControllerServiceCapabilities([]csi.ControllerServiceCapability_RPC_Type{ csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME, @@ -108,13 +108,13 @@ func (r *Driver) Run(driverName, nodeID, endpoint string, containerized bool, ca r.ids = NewIdentityServer(r.cd) r.ns, err = NewNodeServer(r.cd, containerized) if err != nil { - glog.Fatalf("failed to start node server, err %v\n", err) + klog.Fatalf("failed to start node server, err %v\n", err) } r.cs = NewControllerServer(r.cd, cachePersister) if err = r.cs.LoadExDataFromMetadataStore(); err != nil { - glog.Fatalf("failed to load metadata from store, err %v\n", err) + klog.Fatalf("failed to load metadata from store, err %v\n", err) } s := csicommon.NewNonBlockingGRPCServer() diff --git a/pkg/rbd/rbd_attach.go b/pkg/rbd/rbd_attach.go index b593d0820..354554d12 100644 --- a/pkg/rbd/rbd_attach.go +++ b/pkg/rbd/rbd_attach.go @@ -25,8 +25,8 @@ import ( "strings" "time" - "github.com/golang/glog" "k8s.io/apimachinery/pkg/util/wait" + "k8s.io/klog" ) const ( @@ -64,22 +64,22 @@ func getRbdDevFromImageAndPool(pool string, image string) (string, bool) { // #nosec poolBytes, err := ioutil.ReadFile(poolFile) if err != nil { - glog.V(4).Infof("error reading %s: %v", poolFile, err) + klog.V(4).Infof("error reading %s: %v", poolFile, err) continue } if strings.TrimSpace(string(poolBytes)) != pool { - glog.V(4).Infof("device %s is not %q: %q", name, pool, string(poolBytes)) + klog.V(4).Infof("device %s is not %q: %q", name, pool, string(poolBytes)) continue } imgFile := path.Join(sysPath, name, "name") // #nosec imgBytes, err := ioutil.ReadFile(imgFile) if err != nil { - glog.V(4).Infof("error reading %s: %v", imgFile, err) + klog.V(4).Infof("error reading %s: %v", imgFile, err) continue } if strings.TrimSpace(string(imgBytes)) != image { - glog.V(4).Infof("device %s is not %q: %q", name, image, string(imgBytes)) + klog.V(4).Infof("device %s is not %q: %q", name, image, string(imgBytes)) continue } // Found a match, check if device exists. @@ -102,7 +102,7 @@ func getMaxNbds() (int, error) { return 0, fmt.Errorf("rbd-nbd: failed to retrieve max_nbds from %s err: %q", maxNbdsPath, err) } - glog.V(4).Infof("found nbds max parameters file at %s", maxNbdsPath) + klog.V(4).Infof("found nbds max parameters file at %s", maxNbdsPath) maxNbdBytes, err := ioutil.ReadFile(maxNbdsPath) if err != nil { @@ -114,7 +114,7 @@ func getMaxNbds() (int, error) { return 0, fmt.Errorf("rbd-nbd: failed to read max_nbds err: %q", err) } - glog.V(4).Infof("rbd-nbd: max_nbds: %d", maxNbds) + klog.V(4).Infof("rbd-nbd: max_nbds: %d", maxNbds) return maxNbds, nil } @@ -131,7 +131,7 @@ func getNbdDevFromImageAndPool(pool string, image string) (string, bool) { maxNbds, maxNbdsErr := getMaxNbds() if maxNbdsErr != nil { - glog.V(4).Infof("error reading nbds_max %v", maxNbdsErr) + klog.V(4).Infof("error reading nbds_max %v", maxNbdsErr) return "", false } @@ -150,20 +150,20 @@ func getnbdDevicePath(nbdPath, imgPath string, count int) (string, error) { _, err := os.Lstat(nbdPath) if err != nil { - glog.V(4).Infof("error reading nbd info directory %s: %v", nbdPath, err) + klog.V(4).Infof("error reading nbd info directory %s: %v", nbdPath, err) return "", err } // #nosec pidBytes, err := ioutil.ReadFile(path.Join(nbdPath, "pid")) if err != nil { - glog.V(5).Infof("did not find valid pid file in dir %s: %v", nbdPath, err) + klog.V(5).Infof("did not find valid pid file in dir %s: %v", nbdPath, err) return "", err } cmdlineFileName := path.Join(hostRootFS, "/proc", strings.TrimSpace(string(pidBytes)), "cmdline") // #nosec rawCmdline, err := ioutil.ReadFile(cmdlineFileName) if err != nil { - glog.V(4).Infof("failed to read cmdline file %s: %v", cmdlineFileName, err) + klog.V(4).Infof("failed to read cmdline file %s: %v", cmdlineFileName, err) return "", err } cmdlineArgs := strings.FieldsFunc(string(rawCmdline), func(r rune) bool { @@ -173,18 +173,18 @@ func getnbdDevicePath(nbdPath, imgPath string, count int) (string, error) { // Only accepted pattern of cmdline is from execRbdMap: // rbd-nbd map pool/image ... if len(cmdlineArgs) < 3 || cmdlineArgs[0] != rbdTonbd || cmdlineArgs[1] != "map" { - glog.V(4).Infof("nbd device %s is not used by rbd", nbdPath) + klog.V(4).Infof("nbd device %s is not used by rbd", nbdPath) return "", err } if cmdlineArgs[2] != imgPath { - glog.V(4).Infof("rbd-nbd device %s did not match expected image path: %s with path found: %s", + klog.V(4).Infof("rbd-nbd device %s did not match expected image path: %s with path found: %s", nbdPath, imgPath, cmdlineArgs[2]) return "", err } devicePath := path.Join("/dev", "nbd"+strconv.Itoa(count)) if _, err := os.Lstat(devicePath); err != nil { - glog.Warningf("Stat device %s for imgpath %s failed %v", devicePath, imgPath, err) + klog.Warningf("Stat device %s for imgpath %s failed %v", devicePath, imgPath, err) return "", err } return devicePath, nil @@ -213,14 +213,14 @@ func waitForPath(pool, image string, maxRetries int, useNbdDriver bool) (string, func checkRbdNbdTools() bool { _, err := execCommand("modprobe", []string{"nbd"}) if err != nil { - glog.V(3).Infof("rbd-nbd: nbd modprobe failed with error %v", err) + klog.V(3).Infof("rbd-nbd: nbd modprobe failed with error %v", err) return false } if _, err := execCommand(rbdTonbd, []string{"--version"}); err != nil { - glog.V(3).Infof("rbd-nbd: running rbd-nbd --version failed with error %v", err) + klog.V(3).Infof("rbd-nbd: running rbd-nbd --version failed with error %v", err) return false } - glog.V(3).Infof("rbd-nbd tools were found.") + klog.V(3).Infof("rbd-nbd tools were found.") return true } @@ -243,13 +243,13 @@ func attachRBDImage(volOptions *rbdVolume, userID string, credentials map[string defer func() { if err = attachdetachMutex.UnlockKey(imagePath); err != nil { - glog.Warningf("failed to unlock mutex imagepath:%s %v", imagePath, err) + klog.Warningf("failed to unlock mutex imagepath:%s %v", imagePath, err) } }() _, err = execCommand("modprobe", []string{moduleName}) if err != nil { - glog.Warningf("rbd: failed to load rbd kernel module:%v", err) + klog.Warningf("rbd: failed to load rbd kernel module:%v", err) return "", err } @@ -278,7 +278,7 @@ func createPath(volOpt *rbdVolume, userID string, creds map[string]string) (stri return "", err } - glog.V(5).Infof("rbd: map mon %s", mon) + klog.V(5).Infof("rbd: map mon %s", mon) key, err := getRBDKey(userID, creds) if err != nil { return "", err @@ -294,7 +294,7 @@ func createPath(volOpt *rbdVolume, userID string, creds map[string]string) (stri output, err := execCommand(cmdName, []string{ "map", imagePath, "--id", userID, "-m", mon, "--key=" + key}) if err != nil { - glog.Warningf("rbd: map error %v, rbd output: %s", err, string(output)) + klog.Warningf("rbd: map error %v, rbd output: %s", err, string(output)) return "", fmt.Errorf("rbd: map failed %v, rbd output: %s", err, string(output)) } devicePath, found := waitForPath(volOpt.Pool, image, 10, useNBD) @@ -327,7 +327,7 @@ func detachRBDDevice(devicePath string) error { var err error var output []byte - glog.V(3).Infof("rbd: unmap device %s", devicePath) + klog.V(3).Infof("rbd: unmap device %s", devicePath) cmdName := rbd if strings.HasPrefix(devicePath, "/dev/nbd") { diff --git a/pkg/rbd/rbd_util.go b/pkg/rbd/rbd_util.go index 84d053a41..b3a190ef2 100644 --- a/pkg/rbd/rbd_util.go +++ b/pkg/rbd/rbd_util.go @@ -22,9 +22,9 @@ import ( "strings" "time" - "github.com/golang/glog" "github.com/pkg/errors" "k8s.io/apimachinery/pkg/util/sets" + "k8s.io/klog" "k8s.io/kubernetes/pkg/util/keymutex" ) @@ -127,9 +127,9 @@ func createRBDImage(pOpts *rbdVolume, volSz int, adminID string, credentials map return err } if pOpts.ImageFormat == rbdImageFormat2 { - glog.V(4).Infof("rbd: create %s size %s format %s (features: %s) using mon %s, pool %s id %s key %s", image, volSzGB, pOpts.ImageFormat, pOpts.ImageFeatures, mon, pOpts.Pool, adminID, key) + klog.V(4).Infof("rbd: create %s size %s format %s (features: %s) using mon %s, pool %s id %s key %s", image, volSzGB, pOpts.ImageFormat, pOpts.ImageFeatures, mon, pOpts.Pool, adminID, key) } else { - glog.V(4).Infof("rbd: create %s size %s format %s using mon %s, pool %s id %s key %s", image, volSzGB, pOpts.ImageFormat, mon, pOpts.Pool, adminID, key) + klog.V(4).Infof("rbd: create %s size %s format %s using mon %s, pool %s id %s key %s", image, volSzGB, pOpts.ImageFormat, mon, pOpts.Pool, adminID, key) } args := []string{"create", image, "--size", volSzGB, "--pool", pOpts.Pool, "--id", adminID, "-m", mon, "--key=" + key, "--image-format", pOpts.ImageFormat} if pOpts.ImageFormat == rbdImageFormat2 { @@ -163,14 +163,14 @@ func rbdStatus(pOpts *rbdVolume, userID string, credentials map[string]string) ( return false, "", err } - glog.V(4).Infof("rbd: status %s using mon %s, pool %s id %s key %s", image, mon, pOpts.Pool, userID, key) + klog.V(4).Infof("rbd: status %s using mon %s, pool %s id %s key %s", image, mon, pOpts.Pool, userID, key) args := []string{"status", image, "--pool", pOpts.Pool, "-m", mon, "--id", userID, "--key=" + key} cmd, err = execCommand("rbd", args) output = string(cmd) if err, ok := err.(*exec.Error); ok { if err.Err == exec.ErrNotFound { - glog.Errorf("rbd cmd not found") + klog.Errorf("rbd cmd not found") // fail fast if command not found return false, output, err } @@ -182,10 +182,10 @@ func rbdStatus(pOpts *rbdVolume, userID string, credentials map[string]string) ( } if strings.Contains(output, imageWatcherStr) { - glog.V(4).Infof("rbd: watchers on %s: %s", image, output) + klog.V(4).Infof("rbd: watchers on %s: %s", image, output) return true, output, nil } - glog.Warningf("rbd: no watchers on %s", image) + klog.Warningf("rbd: no watchers on %s", image) return false, output, nil } @@ -198,7 +198,7 @@ func deleteRBDImage(pOpts *rbdVolume, adminID string, credentials map[string]str return err } if found { - glog.Info("rbd is still being used ", image) + klog.Info("rbd is still being used ", image) return fmt.Errorf("rbd %s is still being used", image) } key, err := getRBDKey(adminID, credentials) @@ -210,13 +210,13 @@ func deleteRBDImage(pOpts *rbdVolume, adminID string, credentials map[string]str return err } - glog.V(4).Infof("rbd: rm %s using mon %s, pool %s id %s key %s", image, mon, pOpts.Pool, adminID, key) + klog.V(4).Infof("rbd: rm %s using mon %s, pool %s id %s key %s", image, mon, pOpts.Pool, adminID, key) args := []string{"rm", image, "--pool", pOpts.Pool, "--id", adminID, "-m", mon, "--key=" + key} output, err = execCommand("rbd", args) if err == nil { return nil } - glog.Errorf("failed to delete rbd image: %v, command output: %s", err, string(output)) + klog.Errorf("failed to delete rbd image: %v, command output: %s", err, string(output)) return err } @@ -371,7 +371,7 @@ func protectSnapshot(pOpts *rbdSnapshot, adminID string, credentials map[string] return err } - glog.V(4).Infof("rbd: snap protect %s using mon %s, pool %s id %s key %s", image, mon, pOpts.Pool, adminID, key) + klog.V(4).Infof("rbd: snap protect %s using mon %s, pool %s id %s key %s", image, mon, pOpts.Pool, adminID, key) args := []string{"snap", "protect", "--pool", pOpts.Pool, "--snap", snapID, image, "--id", adminID, "-m", mon, "--key=" + key} output, err = execCommand("rbd", args) @@ -398,7 +398,7 @@ func createSnapshot(pOpts *rbdSnapshot, adminID string, credentials map[string]s if err != nil { return err } - glog.V(4).Infof("rbd: snap create %s using mon %s, pool %s id %s key %s", image, mon, pOpts.Pool, adminID, key) + klog.V(4).Infof("rbd: snap create %s using mon %s, pool %s id %s key %s", image, mon, pOpts.Pool, adminID, key) args := []string{"snap", "create", "--pool", pOpts.Pool, "--snap", snapID, image, "--id", adminID, "-m", mon, "--key=" + key} output, err = execCommand("rbd", args) @@ -425,7 +425,7 @@ func unprotectSnapshot(pOpts *rbdSnapshot, adminID string, credentials map[strin if err != nil { return err } - glog.V(4).Infof("rbd: snap unprotect %s using mon %s, pool %s id %s key %s", image, mon, pOpts.Pool, adminID, key) + klog.V(4).Infof("rbd: snap unprotect %s using mon %s, pool %s id %s key %s", image, mon, pOpts.Pool, adminID, key) args := []string{"snap", "unprotect", "--pool", pOpts.Pool, "--snap", snapID, image, "--id", adminID, "-m", mon, "--key=" + key} output, err = execCommand("rbd", args) @@ -452,7 +452,7 @@ func deleteSnapshot(pOpts *rbdSnapshot, adminID string, credentials map[string]s if err != nil { return err } - glog.V(4).Infof("rbd: snap rm %s using mon %s, pool %s id %s key %s", image, mon, pOpts.Pool, adminID, key) + klog.V(4).Infof("rbd: snap rm %s using mon %s, pool %s id %s key %s", image, mon, pOpts.Pool, adminID, key) args := []string{"snap", "rm", "--pool", pOpts.Pool, "--snap", snapID, image, "--id", adminID, "-m", mon, "--key=" + key} output, err = execCommand("rbd", args) @@ -479,7 +479,7 @@ func restoreSnapshot(pVolOpts *rbdVolume, pSnapOpts *rbdSnapshot, adminID string if err != nil { return err } - glog.V(4).Infof("rbd: clone %s using mon %s, pool %s id %s key %s", image, mon, pVolOpts.Pool, adminID, key) + klog.V(4).Infof("rbd: clone %s using mon %s, pool %s id %s key %s", image, mon, pVolOpts.Pool, adminID, key) args := []string{"clone", pSnapOpts.Pool + "/" + pSnapOpts.VolName + "@" + snapID, pVolOpts.Pool + "/" + image, "--id", adminID, "-m", mon, "--key=" + key} output, err = execCommand("rbd", args)