Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use klog instead of glog #137

Merged
merged 1 commit into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 14 additions & 34 deletions cmd/nfsplugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,65 +22,45 @@ import (
"os"
"strconv"

"github.com/spf13/cobra"

"github.com/kubernetes-csi/csi-driver-nfs/pkg/nfs"

"k8s.io/klog/v2"
)

var (
endpoint string
nodeID string
perm string
endpoint = flag.String("endpoint", "unix://tmp/csi.sock", "CSI endpoint")
nodeID = flag.String("nodeid", "", "node id")
perm = flag.String("mount-permissions", "", "mounted folder permissions")
)

func init() {
_ = flag.Set("logtostderr", "true")
}

func main() {

_ = flag.CommandLine.Parse([]string{})

cmd := &cobra.Command{
Use: "NFS",
Short: "CSI based NFS driver",
Run: func(cmd *cobra.Command, args []string) {
handle()
},
}

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

cmd.PersistentFlags().StringVar(&nodeID, "nodeid", "", "node id")
_ = cmd.MarkPersistentFlagRequired("nodeid")

cmd.PersistentFlags().StringVar(&endpoint, "endpoint", "", "CSI endpoint")
_ = cmd.MarkPersistentFlagRequired("endpoint")

cmd.PersistentFlags().StringVar(&perm, "mount-permissions", "", "mounted folder permissions")

_ = cmd.ParseFlags(os.Args[1:])
if err := cmd.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "%s", err.Error())
os.Exit(1)
klog.InitFlags(nil)
flag.Parse()
if *nodeID == "" {
klog.Warning("nodeid is empty")
}

handle()
os.Exit(0)
}

func handle() {
// Converting string permission representation to *uint32
var parsedPerm *uint32
if perm != "" {
permu64, err := strconv.ParseUint(perm, 8, 32)
if perm != nil && *perm != "" {
permu64, err := strconv.ParseUint(*perm, 8, 32)
if err != nil {
fmt.Fprintf(os.Stderr, "Incorrect mount-permissions value: %q", perm)
fmt.Fprintf(os.Stderr, "incorrect mount-permissions value: %q", *perm)
os.Exit(1)
}
permu32 := uint32(permu64)
parsedPerm = &permu32
}

d := nfs.NewNFSdriver(nodeID, endpoint, parsedPerm)
d := nfs.NewNFSdriver(*nodeID, *endpoint, parsedPerm)
d.Run(false)
}
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ go 1.15

require (
github.com/container-storage-interface/spec v1.3.0
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/golang/protobuf v1.4.3
github.com/kubernetes-csi/csi-lib-utils v0.9.0
github.com/kubernetes-csi/external-snapshotter/v2 v2.0.0-20200617021606-4800ca72d403
github.com/onsi/ginkgo v1.11.0
github.com/onsi/gomega v1.7.1
github.com/pborman/uuid v1.2.0
github.com/spf13/cobra v1.1.1
github.com/stretchr/testify v1.6.1
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b
google.golang.org/grpc v1.29.0
Expand Down
15 changes: 8 additions & 7 deletions pkg/nfs/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ import (
"strings"

"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"
)

// ControllerServer controller server setting
Expand Down Expand Up @@ -92,7 +93,7 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
}
defer func() {
if err = cs.internalUnmount(ctx, nfsVol); err != nil {
glog.Warningf("failed to unmount nfs server: %v", err.Error())
klog.Warningf("failed to unmount nfs server: %v", err.Error())
}
}()

Expand All @@ -116,7 +117,7 @@ func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
nfsVol, err := cs.getNfsVolFromID(volumeID)
if err != nil {
// An invalid ID should be treated as doesn't exist
glog.Warningf("failed to get nfs volume for volume id %v deletion: %v", volumeID, err)
klog.Warningf("failed to get nfs volume for volume id %v deletion: %v", volumeID, err)
return &csi.DeleteVolumeResponse{}, nil
}

Expand All @@ -126,14 +127,14 @@ func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
}
defer func() {
if err = cs.internalUnmount(ctx, nfsVol); err != nil {
glog.Warningf("failed to unmount nfs server: %v", err.Error())
klog.Warningf("failed to unmount nfs server: %v", err.Error())
}
}()

// Delete subdirectory under base-dir
internalVolumePath := cs.getInternalVolumePath(nfsVol)

glog.V(2).Infof("Removing subdirectory at %v", internalVolumePath)
klog.V(2).Infof("Removing subdirectory at %v", internalVolumePath)
if err = os.RemoveAll(internalVolumePath); err != nil {
return nil, status.Errorf(codes.Internal, "failed to delete subdirectory: %v", err.Error())
}
Expand Down Expand Up @@ -245,7 +246,7 @@ func (cs *ControllerServer) internalMount(ctx context.Context, vol *nfsVolume, v
}
}

glog.V(4).Infof("internally mounting %v:%v at %v", vol.server, sharePath, targetPath)
klog.V(4).Infof("internally mounting %v:%v at %v", vol.server, sharePath, targetPath)
_, err := cs.Driver.ns.NodePublishVolume(ctx, &csi.NodePublishVolumeRequest{
TargetPath: targetPath,
VolumeContext: map[string]string{
Expand All @@ -263,7 +264,7 @@ func (cs *ControllerServer) internalUnmount(ctx context.Context, vol *nfsVolume)
targetPath := cs.getInternalMountPath(vol)

// Unmount nfs server at base-dir
glog.V(4).Infof("internally unmounting %v", targetPath)
klog.V(4).Infof("internally unmounting %v", targetPath)
_, err := cs.Driver.ns.NodeUnpublishVolume(ctx, &csi.NodeUnpublishVolumeRequest{
VolumeId: vol.id,
TargetPath: cs.getInternalMountPath(vol),
Expand Down
7 changes: 4 additions & 3 deletions pkg/nfs/indentityserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@ package nfs

import (
"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/golang/glog"
"github.com/golang/protobuf/ptypes/wrappers"
"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 @@ -55,7 +56,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
10 changes: 5 additions & 5 deletions pkg/nfs/nfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"fmt"

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

Expand Down Expand Up @@ -56,7 +56,7 @@ var (
)

func NewNFSdriver(nodeID, endpoint string, perm *uint32) *Driver {
glog.Infof("Driver: %v version: %v", DriverName, version)
klog.Infof("Driver: %v version: %v", DriverName, version)

n := &Driver{
name: DriverName,
Expand Down Expand Up @@ -113,7 +113,7 @@ func (n *Driver) Run(testMode bool) {
func (n *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})
n.cap[c] = true
}
Expand All @@ -124,7 +124,7 @@ func (n *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 All @@ -134,7 +134,7 @@ func (n *Driver) AddControllerServiceCapabilities(cl []csi.ControllerServiceCapa
func (n *Driver) AddNodeServiceCapabilities(nl []csi.NodeServiceCapability_RPC_Type) {
var nsc []*csi.NodeServiceCapability
for _, n := range nl {
glog.Infof("Enabling node service capability: %v", n.String())
klog.Infof("Enabling node service capability: %v", n.String())
nsc = append(nsc, NewNodeServiceCapability(n))
}
n.nscap = nsc
Expand Down
6 changes: 3 additions & 3 deletions pkg/nfs/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
"strings"

"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"
"k8s.io/kubernetes/pkg/volume"
"k8s.io/utils/mount"
)
Expand Down Expand Up @@ -74,7 +74,7 @@ func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
ep := req.GetVolumeContext()[paramShare]
source := fmt.Sprintf("%s:%s", s, ep)

glog.V(2).Infof("NodePublishVolume: volumeID(%v) source(%s) targetPath(%s) mountflags(%v)", volumeID, source, targetPath, mountOptions)
klog.V(2).Infof("NodePublishVolume: volumeID(%v) source(%s) targetPath(%s) mountflags(%v)", volumeID, source, targetPath, mountOptions)
err = ns.mounter.Mount(source, targetPath, "nfs", mountOptions)
if err != nil {
if os.IsPermission(err) {
Expand Down Expand Up @@ -117,7 +117,7 @@ func (ns *NodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu
return nil, status.Error(codes.NotFound, "Volume not mounted")
}

glog.V(2).Infof("NodeUnpublishVolume: CleanupMountPoint %s on volumeID(%s)", targetPath, volumeID)
klog.V(2).Infof("NodeUnpublishVolume: CleanupMountPoint %s on volumeID(%s)", targetPath, volumeID)
err = mount.CleanupMountPoint(targetPath, ns.mounter, false)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
Expand Down
15 changes: 7 additions & 8 deletions pkg/nfs/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ import (
"sync"
"time"

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

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

// Defines Non blocking GRPC server interfaces
Expand Down Expand Up @@ -73,19 +72,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 Down Expand Up @@ -115,10 +114,10 @@ func (s *nonBlockingGRPCServer) serve(endpoint string, ids csi.IdentityServer, c
}()
}

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

err = server.Serve(listener)
if err != nil {
glog.Fatalf("Failed to serve grpc server: %v", err)
klog.Fatalf("Failed to serve grpc server: %v", err)
}
}
11 changes: 6 additions & 5 deletions pkg/nfs/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ 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 @@ -70,13 +71,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