Skip to content

Commit

Permalink
Merge pull request #35 from huffmanca/switch-to-klog
Browse files Browse the repository at this point in the history
Switch to klog
  • Loading branch information
k8s-ci-robot authored Dec 2, 2020
2 parents 461e51c + c08bf2c commit a61477f
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 1,572 deletions.
3 changes: 3 additions & 0 deletions cmd/iscsiplugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os"

"github.com/spf13/cobra"
"k8s.io/klog/v2"

"github.com/kubernetes-csi/csi-driver-iscsi/pkg/iscsi"
)
Expand All @@ -47,6 +48,8 @@ func main() {
},
}

klog.InitFlags(nil)

cmd.Flags().AddGoFlagSet(flag.CommandLine)

cmd.PersistentFlags().StringVar(&nodeID, "nodeid", "", "node id")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ go 1.13

require (
github.com/container-storage-interface/spec v1.2.0
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/kubernetes-csi/csi-lib-iscsi v0.0.0-20190415173011-c545557492f4
github.com/kubernetes-csi/csi-lib-utils v0.2.0
github.com/onsi/gomega v1.8.1 // indirect
github.com/spf13/cobra v1.0.0
golang.org/x/net v0.0.0-20200707034311-ab3426394381
google.golang.org/grpc v1.27.0
k8s.io/klog/v2 v2.2.0
k8s.io/kubernetes v1.19.4
k8s.io/utils v0.0.0-20200729134348-d5654de09c73
)
Expand Down
4 changes: 2 additions & 2 deletions pkg/iscsi/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ package iscsi

import (
"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/golang/glog"
"golang.org/x/net/context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"k8s.io/klog/v2"
)

type ControllerServer struct {
Expand Down Expand Up @@ -59,7 +59,7 @@ func (cs *ControllerServer) GetCapacity(ctx context.Context, req *csi.GetCapacit
// ControllerGetCapabilities implements the default GRPC callout.
// Default supports all capabilities
func (cs *ControllerServer) ControllerGetCapabilities(ctx context.Context, req *csi.ControllerGetCapabilitiesRequest) (*csi.ControllerGetCapabilitiesResponse, error) {
glog.V(5).Infof("Using default ControllerGetCapabilities")
klog.V(5).Infof("Using default ControllerGetCapabilities")

return &csi.ControllerGetCapabilitiesResponse{
Capabilities: cs.Driver.cscap,
Expand Down
8 changes: 4 additions & 4 deletions pkg/iscsi/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package iscsi

import (
"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/golang/glog"
"k8s.io/klog/v2"
)

type driver struct {
Expand All @@ -43,7 +43,7 @@ var (
)

func NewDriver(nodeID, endpoint string) *driver {
glog.Infof("Driver: %v version: %v", driverName, version)
klog.Infof("Driver: %v version: %v", driverName, version)

d := &driver{
name: driverName,
Expand Down Expand Up @@ -81,7 +81,7 @@ func (d *driver) Run() {
func (d *driver) AddVolumeCapabilityAccessModes(vc []csi.VolumeCapability_AccessMode_Mode) []*csi.VolumeCapability_AccessMode {
var vca []*csi.VolumeCapability_AccessMode
for _, c := range vc {
glog.Infof("Enabling volume access mode: %v", c.String())
klog.Infof("Enabling volume access mode: %v", c.String())
vca = append(vca, &csi.VolumeCapability_AccessMode{Mode: c})
}
d.cap = vca
Expand All @@ -92,7 +92,7 @@ func (d *driver) AddControllerServiceCapabilities(cl []csi.ControllerServiceCapa
var csc []*csi.ControllerServiceCapability

for _, c := range cl {
glog.Infof("Enabling controller service capability: %v", c.String())
klog.Infof("Enabling controller service capability: %v", c.String())
csc = append(csc, NewControllerServiceCapability(c))
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/iscsi/identityserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ package iscsi

import (
"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/golang/glog"
"golang.org/x/net/context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"k8s.io/klog/v2"
)

type IdentityServer struct {
Driver *driver
}

func (ids *IdentityServer) GetPluginInfo(ctx context.Context, req *csi.GetPluginInfoRequest) (*csi.GetPluginInfoResponse, error) {
glog.V(5).Infof("Using default GetPluginInfo")
klog.V(5).Infof("Using default GetPluginInfo")

if ids.Driver.name == "" {
return nil, status.Error(codes.Unavailable, "Driver name not configured")
Expand All @@ -34,7 +34,7 @@ func (ids *IdentityServer) Probe(ctx context.Context, req *csi.ProbeRequest) (*c
}

func (ids *IdentityServer) GetPluginCapabilities(ctx context.Context, req *csi.GetPluginCapabilitiesRequest) (*csi.GetPluginCapabilitiesResponse, error) {
glog.V(5).Infof("Using default capabilities")
klog.V(5).Infof("Using default capabilities")
return &csi.GetPluginCapabilitiesResponse{
Capabilities: []*csi.PluginCapability{
{
Expand Down
22 changes: 11 additions & 11 deletions pkg/iscsi/iscsi_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"os"
"path"

"github.com/golang/glog"
iscsi_lib "github.com/kubernetes-csi/csi-lib-iscsi/iscsi"
"k8s.io/klog/v2"
"k8s.io/utils/mount"
)

Expand All @@ -44,21 +44,21 @@ func (util *ISCSIUtil) AttachDisk(b iscsiDiskMounter) (string, error) {
return "", fmt.Errorf("Heuristic determination of mount point failed:%v", err)
}
if !notMnt {
glog.Infof("iscsi: %s already mounted", mntPath)
klog.Infof("iscsi: %s already mounted", mntPath)
return "", nil
}

if err := os.MkdirAll(mntPath, 0750); err != nil {
glog.Errorf("iscsi: failed to mkdir %s, error", mntPath)
klog.Errorf("iscsi: failed to mkdir %s, error", mntPath)
return "", err
}

// Persist iscsi disk config to json file for DetachDisk path
file := path.Join(mntPath, b.VolName+".json")
err = iscsi_lib.PersistConnector(b.connector, file)
if err != nil {
glog.Errorf("failed to persist connection info: %v", err)
glog.Errorf("disconnecting volume and failing the publish request because persistence files are required for reliable Unpublish")
klog.Errorf("failed to persist connection info: %v", err)
klog.Errorf("disconnecting volume and failing the publish request because persistence files are required for reliable Unpublish")
return "", fmt.Errorf("unable to create persistence file for connection")
}

Expand All @@ -73,7 +73,7 @@ func (util *ISCSIUtil) AttachDisk(b iscsiDiskMounter) (string, error) {

err = b.mounter.FormatAndMount(devicePath, mntPath, b.fsType, options)
if err != nil {
glog.Errorf("iscsi: failed to mount iscsi volume %s [%s] to %s, error %v", devicePath, b.fsType, mntPath, err)
klog.Errorf("iscsi: failed to mount iscsi volume %s [%s] to %s, error %v", devicePath, b.fsType, mntPath, err)
}

return devicePath, err
Expand All @@ -82,18 +82,18 @@ func (util *ISCSIUtil) AttachDisk(b iscsiDiskMounter) (string, error) {
func (util *ISCSIUtil) DetachDisk(c iscsiDiskUnmounter, targetPath string) error {
_, cnt, err := mount.GetDeviceNameFromMount(c.mounter, targetPath)
if err != nil {
glog.Errorf("iscsi detach disk: failed to get device from mnt: %s\nError: %v", targetPath, err)
klog.Errorf("iscsi detach disk: failed to get device from mnt: %s\nError: %v", targetPath, err)
return err
}

if pathExists, pathErr := mount.PathExists(targetPath); pathErr != nil {
return fmt.Errorf("Error checking if path exists: %v", pathErr)
} else if !pathExists {
glog.Warningf("Warning: Unmount skipped because path does not exist: %v", targetPath)
klog.Warningf("Warning: Unmount skipped because path does not exist: %v", targetPath)
return nil
}
if err = c.mounter.Unmount(targetPath); err != nil {
glog.Errorf("iscsi detach disk: failed to unmount: %s\nError: %v", targetPath, err)
klog.Errorf("iscsi detach disk: failed to unmount: %s\nError: %v", targetPath, err)
return err
}
cnt--
Expand All @@ -105,14 +105,14 @@ func (util *ISCSIUtil) DetachDisk(c iscsiDiskUnmounter, targetPath string) error
file := path.Join(targetPath, c.iscsiDisk.VolName+".json")
connector, err := iscsi_lib.GetConnectorFromFile(file)
if err != nil {
glog.Errorf("iscsi detach disk: failed to get iscsi config from path %s Error: %v", targetPath, err)
klog.Errorf("iscsi detach disk: failed to get iscsi config from path %s Error: %v", targetPath, err)
return err
}

iscsi_lib.Disconnect(connector.TargetIqn, connector.TargetPortals)

if err := os.RemoveAll(targetPath); err != nil {
glog.Errorf("iscsi: failed to remove mount path Error: %v", err)
klog.Errorf("iscsi: failed to remove mount path Error: %v", err)
return err
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/iscsi/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"os"
"sync"

"github.com/golang/glog"
"google.golang.org/grpc"

"github.com/container-storage-interface/spec/lib/go/csi"
"k8s.io/klog/v2"
)

// Defines Non blocking GRPC server interfaces
Expand Down Expand Up @@ -58,19 +58,19 @@ func (s *nonBlockingGRPCServer) serve(endpoint string, ids csi.IdentityServer, c

proto, addr, err := ParseEndpoint(endpoint)
if err != nil {
glog.Fatal(err.Error())
klog.Fatal(err.Error())
}

if proto == "unix" {
addr = "/" + addr
if err := os.Remove(addr); err != nil && !os.IsNotExist(err) {
glog.Fatalf("Failed to remove %s, error: %s", addr, err.Error())
klog.Fatalf("Failed to remove %s, error: %s", addr, err.Error())
}
}

listener, err := net.Listen(proto, addr)
if err != nil {
glog.Fatalf("Failed to listen: %v", err)
klog.Fatalf("Failed to listen: %v", err)
}

opts := []grpc.ServerOption{
Expand All @@ -89,7 +89,7 @@ func (s *nonBlockingGRPCServer) serve(endpoint string, ids csi.IdentityServer, c
csi.RegisterNodeServer(server, ns)
}

glog.Infof("Listening for connections on address: %#v", listener.Addr())
klog.Infof("Listening for connections on address: %#v", listener.Addr())

server.Serve(listener)

Expand Down
10 changes: 5 additions & 5 deletions pkg/iscsi/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"strings"

"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/golang/glog"
"github.com/kubernetes-csi/csi-lib-utils/protosanitizer"
"golang.org/x/net/context"
"google.golang.org/grpc"
"k8s.io/klog/v2"
)

func NewDefaultIdentityServer(d *driver) *IdentityServer {
Expand Down Expand Up @@ -44,13 +44,13 @@ func ParseEndpoint(ep string) (string, string, error) {
}

func logGRPC(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
glog.V(3).Infof("GRPC call: %s", info.FullMethod)
glog.V(5).Infof("GRPC request: %s", protosanitizer.StripSecrets(req))
klog.V(3).Infof("GRPC call: %s", info.FullMethod)
klog.V(5).Infof("GRPC request: %s", protosanitizer.StripSecrets(req))
resp, err := handler(ctx, req)
if err != nil {
glog.Errorf("GRPC error: %v", err)
klog.Errorf("GRPC error: %v", err)
} else {
glog.V(5).Infof("GRPC response: %s", protosanitizer.StripSecrets(resp))
klog.V(5).Infof("GRPC response: %s", protosanitizer.StripSecrets(resp))
}
return resp, err
}
Loading

0 comments on commit a61477f

Please sign in to comment.