Skip to content

Commit 1f4d6a7

Browse files
authored
Merge pull request #534 from huww98/klog
switch from glog to klog
2 parents 5857009 + c7f35a1 commit 1f4d6a7

File tree

23 files changed

+76
-2588
lines changed

23 files changed

+76
-2588
lines changed

cmd/hostpathplugin/main.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,11 @@ import (
2525
"path"
2626
"syscall"
2727

28-
"github.com/golang/glog"
2928
"github.com/kubernetes-csi/csi-driver-host-path/internal/proxy"
3029
"github.com/kubernetes-csi/csi-driver-host-path/pkg/hostpath"
30+
"k8s.io/klog/v2"
3131
)
3232

33-
func init() {
34-
flag.Set("logtostderr", "true")
35-
}
36-
3733
var (
3834
// Set by the build process
3935
version = ""
@@ -70,6 +66,7 @@ func main() {
7066
// for proxying incoming calls to the embedded mock CSI driver.
7167
proxyEndpoint := flag.String("proxy-endpoint", "", "Instead of running the CSI driver code, just proxy connections from csiEndpoint to the given listening socket.")
7268

69+
klog.InitFlags(nil)
7370
flag.Parse()
7471

7572
if *showVersion {
@@ -87,7 +84,7 @@ func main() {
8784
defer cancel()
8885
closer, err := proxy.Run(ctx, cfg.Endpoint, *proxyEndpoint)
8986
if err != nil {
90-
glog.Fatalf("failed to run proxy: %v", err)
87+
klog.Fatalf("failed to run proxy: %v", err)
9188
}
9289
defer closer.Close()
9390

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ go 1.21
44

55
require (
66
github.com/container-storage-interface/spec v1.9.0
7-
github.com/golang/glog v1.2.1
87
github.com/golang/protobuf v1.5.4
98
github.com/kubernetes-csi/csi-lib-utils v0.17.0
109
github.com/pborman/uuid v1.2.1

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
1313
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
1414
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
1515
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
16-
github.com/golang/glog v1.2.1 h1:OptwRhECazUx5ix5TTWC3EZhsZEHWcYWY4FQHTIubm4=
17-
github.com/golang/glog v1.2.1/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w=
1816
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
1917
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
2018
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=

internal/proxy/proxy.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ import (
3535
"io"
3636
"net"
3737

38-
"github.com/golang/glog"
39-
4038
"github.com/kubernetes-csi/csi-driver-host-path/internal/endpoint"
39+
"k8s.io/klog/v2"
4140
)
4241

4342
// New listens on both endpoints and starts accepting connections
@@ -63,7 +62,7 @@ func Run(ctx context.Context, endpoint1, endpoint2 string) (io.Closer, error) {
6362
return nil, fmt.Errorf("listen %s: %v", endpoint2, err)
6463
}
6564

66-
glog.V(3).Infof("proxy listening on %s and %s", endpoint1, endpoint2)
65+
klog.V(3).Infof("proxy listening on %s and %s", endpoint1, endpoint2)
6766

6867
go func() {
6968
for {
@@ -73,19 +72,19 @@ func Run(ctx context.Context, endpoint1, endpoint2 string) (io.Closer, error) {
7372
conn1 := accept(proxy.ctx, proxy.s1, endpoint1)
7473
if conn1 == nil {
7574
// Done, shut down.
76-
glog.V(5).Infof("proxy endpoint %s closed, shutting down", endpoint1)
75+
klog.V(5).Infof("proxy endpoint %s closed, shutting down", endpoint1)
7776
return
7877
}
7978
conn2 := accept(proxy.ctx, proxy.s2, endpoint2)
8079
if conn2 == nil {
8180
// Done, shut down. The already accepted
8281
// connection gets closed.
83-
glog.V(5).Infof("proxy endpoint %s closed, shutting down and close established connection", endpoint2)
82+
klog.V(5).Infof("proxy endpoint %s closed, shutting down and close established connection", endpoint2)
8483
conn1.Close()
8584
return
8685
}
8786

88-
glog.V(3).Infof("proxy established a new connection between %s and %s", endpoint1, endpoint2)
87+
klog.V(3).Infof("proxy established a new connection between %s and %s", endpoint1, endpoint2)
8988
go copy(conn1, conn2, endpoint1, endpoint2)
9089
go copy(conn2, conn1, endpoint2, endpoint1)
9190
}
@@ -122,13 +121,13 @@ func (p *proxy) Close() error {
122121
}
123122

124123
func copy(from, to net.Conn, fromEndpoint, toEndpoint string) {
125-
glog.V(5).Infof("starting to copy %s -> %s", fromEndpoint, toEndpoint)
124+
klog.V(5).Infof("starting to copy %s -> %s", fromEndpoint, toEndpoint)
126125
// Signal recipient that no more data is going to come.
127126
// This also stops reading from it.
128127
defer to.Close()
129128
// Copy data until EOF.
130129
cnt, err := io.Copy(to, from)
131-
glog.V(5).Infof("done copying %s -> %s: %d bytes, %v", fromEndpoint, toEndpoint, cnt, err)
130+
klog.V(5).Infof("done copying %s -> %s: %d bytes, %v", fromEndpoint, toEndpoint, cnt, err)
132131
}
133132

134133
func accept(ctx context.Context, s net.Listener, endpoint string) net.Conn {
@@ -141,6 +140,6 @@ func accept(ctx context.Context, s net.Listener, endpoint string) net.Conn {
141140
if ctx.Err() != nil {
142141
return nil
143142
}
144-
glog.V(3).Infof("accept on %s failed: %v", endpoint, err)
143+
klog.V(3).Infof("accept on %s failed: %v", endpoint, err)
145144
}
146145
}

pkg/hostpath/controllerserver.go

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525

2626
"github.com/golang/protobuf/ptypes"
2727

28-
"github.com/golang/glog"
2928
"github.com/golang/protobuf/ptypes/wrappers"
3029
"github.com/pborman/uuid"
3130
"golang.org/x/net/context"
@@ -45,13 +44,13 @@ const (
4544

4645
func (hp *hostPath) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) (resp *csi.CreateVolumeResponse, finalErr error) {
4746
if err := hp.validateControllerServiceRequest(csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME); err != nil {
48-
glog.V(3).Infof("invalid create volume req: %v", req)
47+
klog.V(3).Infof("invalid create volume req: %v", req)
4948
return nil, err
5049
}
5150

5251
if len(req.GetMutableParameters()) > 0 {
5352
if err := hp.validateControllerServiceRequest(csi.ControllerServiceCapability_RPC_MODIFY_VOLUME); err != nil {
54-
glog.V(3).Infof("invalid create volume req: %v", req)
53+
klog.V(3).Infof("invalid create volume req: %v", req)
5554
return nil, err
5655
}
5756
// Check if the mutable parameters are in the accepted list
@@ -152,7 +151,7 @@ func (hp *hostPath) CreateVolume(ctx context.Context, req *csi.CreateVolumeReque
152151
if err != nil {
153152
return nil, err
154153
}
155-
glog.V(4).Infof("created volume %s at path %s", vol.VolID, vol.VolPath)
154+
klog.V(4).Infof("created volume %s at path %s", vol.VolID, vol.VolPath)
156155

157156
if req.GetVolumeContentSource() != nil {
158157
path := hp.getVolumePath(volumeID)
@@ -172,13 +171,13 @@ func (hp *hostPath) CreateVolume(ctx context.Context, req *csi.CreateVolumeReque
172171
err = status.Errorf(codes.InvalidArgument, "%v not a proper volume source", volumeSource)
173172
}
174173
if err != nil {
175-
glog.V(4).Infof("VolumeSource error: %v", err)
174+
klog.V(4).Infof("VolumeSource error: %v", err)
176175
if delErr := hp.deleteVolume(volumeID); delErr != nil {
177-
glog.V(2).Infof("deleting hostpath volume %v failed: %v", volumeID, delErr)
176+
klog.V(2).Infof("deleting hostpath volume %v failed: %v", volumeID, delErr)
178177
}
179178
return nil, err
180179
}
181-
glog.V(4).Infof("successfully populated volume %s", vol.VolID)
180+
klog.V(4).Infof("successfully populated volume %s", vol.VolID)
182181
}
183182

184183
return &csi.CreateVolumeResponse{
@@ -199,7 +198,7 @@ func (hp *hostPath) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeReque
199198
}
200199

201200
if err := hp.validateControllerServiceRequest(csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME); err != nil {
202-
glog.V(3).Infof("invalid delete volume req: %v", req)
201+
klog.V(3).Infof("invalid delete volume req: %v", req)
203202
return nil, err
204203
}
205204

@@ -227,7 +226,7 @@ func (hp *hostPath) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeReque
227226
if err := hp.deleteVolume(volId); err != nil {
228227
return nil, fmt.Errorf("failed to delete volume %v: %w", volId, err)
229228
}
230-
glog.V(4).Infof("volume %v successfully deleted", volId)
229+
klog.V(4).Infof("volume %v successfully deleted", volId)
231230

232231
return &csi.DeleteVolumeResponse{}, nil
233232
}
@@ -446,7 +445,7 @@ func (hp *hostPath) ListVolumes(ctx context.Context, req *csi.ListVolumesRequest
446445
for index := startIdx - 1; index < volumesLength && index < maxLength; index++ {
447446
hpVolume = volumes[index]
448447
healthy, msg := hp.doHealthCheckInControllerSide(hpVolume.VolID)
449-
glog.V(3).Infof("Healthy state: %s Volume: %t", hpVolume.VolName, healthy)
448+
klog.V(3).Infof("Healthy state: %s Volume: %t", hpVolume.VolName, healthy)
450449
volumeRes.Entries = append(volumeRes.Entries, &csi.ListVolumesResponse_Entry{
451450
Volume: &csi.Volume{
452451
VolumeId: hpVolume.VolID,
@@ -462,7 +461,7 @@ func (hp *hostPath) ListVolumes(ctx context.Context, req *csi.ListVolumesRequest
462461
})
463462
}
464463

465-
glog.V(5).Infof("Volumes are: %+v", *volumeRes)
464+
klog.V(5).Infof("Volumes are: %+v", *volumeRes)
466465
return volumeRes, nil
467466
}
468467

@@ -489,7 +488,7 @@ func (hp *hostPath) ControllerGetVolume(ctx context.Context, req *csi.Controller
489488
}
490489

491490
healthy, msg := hp.doHealthCheckInControllerSide(req.GetVolumeId())
492-
glog.V(3).Infof("Healthy state: %s Volume: %t", volume.VolName, healthy)
491+
klog.V(3).Infof("Healthy state: %s Volume: %t", volume.VolName, healthy)
493492
return &csi.ControllerGetVolumeResponse{
494493
Volume: &csi.Volume{
495494
VolumeId: volume.VolID,
@@ -541,7 +540,7 @@ func (hp *hostPath) ControllerModifyVolume(ctx context.Context, req *csi.Control
541540
// archives of entire directories. The host image must have "tar" binaries in /bin, /usr/sbin, or /usr/bin.
542541
func (hp *hostPath) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequest) (*csi.CreateSnapshotResponse, error) {
543542
if err := hp.validateControllerServiceRequest(csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT); err != nil {
544-
glog.V(3).Infof("invalid create snapshot req: %v", req)
543+
klog.V(3).Infof("invalid create snapshot req: %v", req)
545544
return nil, err
546545
}
547546

@@ -592,7 +591,7 @@ func (hp *hostPath) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotR
592591
return nil, err
593592
}
594593

595-
glog.V(4).Infof("create volume snapshot %s", file)
594+
klog.V(4).Infof("create volume snapshot %s", file)
596595
snapshot := state.Snapshot{}
597596
snapshot.Name = req.GetName()
598597
snapshot.Id = snapshotID
@@ -623,7 +622,7 @@ func (hp *hostPath) DeleteSnapshot(ctx context.Context, req *csi.DeleteSnapshotR
623622
}
624623

625624
if err := hp.validateControllerServiceRequest(csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT); err != nil {
626-
glog.V(3).Infof("invalid delete snapshot req: %v", req)
625+
klog.V(3).Infof("invalid delete snapshot req: %v", req)
627626
return nil, err
628627
}
629628
snapshotID := req.GetSnapshotId()
@@ -638,7 +637,7 @@ func (hp *hostPath) DeleteSnapshot(ctx context.Context, req *csi.DeleteSnapshotR
638637
return nil, status.Errorf(codes.InvalidArgument, "Snapshot with ID %s is part of groupsnapshot %s", snapshotID, snapshot.GroupSnapshotID)
639638
}
640639

641-
glog.V(4).Infof("deleting snapshot %s", snapshotID)
640+
klog.V(4).Infof("deleting snapshot %s", snapshotID)
642641
path := hp.getSnapshotPath(snapshotID)
643642
os.RemoveAll(path)
644643
if err := hp.state.DeleteSnapshot(snapshotID); err != nil {
@@ -649,7 +648,7 @@ func (hp *hostPath) DeleteSnapshot(ctx context.Context, req *csi.DeleteSnapshotR
649648

650649
func (hp *hostPath) ListSnapshots(ctx context.Context, req *csi.ListSnapshotsRequest) (*csi.ListSnapshotsResponse, error) {
651650
if err := hp.validateControllerServiceRequest(csi.ControllerServiceCapability_RPC_LIST_SNAPSHOTS); err != nil {
652-
glog.V(3).Infof("invalid list snapshot req: %v", req)
651+
klog.V(3).Infof("invalid list snapshot req: %v", req)
653652
return nil, err
654653
}
655654

pkg/hostpath/groupcontrollerserver.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ import (
2020
"os"
2121

2222
"github.com/container-storage-interface/spec/lib/go/csi"
23-
"github.com/golang/glog"
2423
"github.com/golang/protobuf/ptypes"
2524
"github.com/pborman/uuid"
2625
"golang.org/x/net/context"
2726
"google.golang.org/grpc/codes"
2827
"google.golang.org/grpc/status"
28+
"k8s.io/klog/v2"
2929

3030
"github.com/kubernetes-csi/csi-driver-host-path/pkg/state"
3131
)
@@ -44,7 +44,7 @@ func (hp *hostPath) GroupControllerGetCapabilities(context.Context, *csi.GroupCo
4444

4545
func (hp *hostPath) CreateVolumeGroupSnapshot(ctx context.Context, req *csi.CreateVolumeGroupSnapshotRequest) (*csi.CreateVolumeGroupSnapshotResponse, error) {
4646
if err := hp.validateGroupControllerServiceRequest(csi.GroupControllerServiceCapability_RPC_CREATE_DELETE_GET_VOLUME_GROUP_SNAPSHOT); err != nil {
47-
glog.V(3).Infof("invalid create volume group snapshot req: %v", req)
47+
klog.V(3).Infof("invalid create volume group snapshot req: %v", req)
4848
return nil, err
4949
}
5050

@@ -129,7 +129,7 @@ func (hp *hostPath) CreateVolumeGroupSnapshot(ctx context.Context, req *csi.Crea
129129
return nil, err
130130
}
131131

132-
glog.V(4).Infof("create volume snapshot %s", file)
132+
klog.V(4).Infof("create volume snapshot %s", file)
133133
snapshot := state.Snapshot{}
134134
snapshot.Name = req.GetName() + "-" + volumeID
135135
snapshot.Id = snapshotID
@@ -170,7 +170,7 @@ func (hp *hostPath) CreateVolumeGroupSnapshot(ctx context.Context, req *csi.Crea
170170

171171
func (hp *hostPath) DeleteVolumeGroupSnapshot(ctx context.Context, req *csi.DeleteVolumeGroupSnapshotRequest) (*csi.DeleteVolumeGroupSnapshotResponse, error) {
172172
if err := hp.validateGroupControllerServiceRequest(csi.GroupControllerServiceCapability_RPC_CREATE_DELETE_GET_VOLUME_GROUP_SNAPSHOT); err != nil {
173-
glog.V(3).Infof("invalid delete volume group snapshot req: %v", req)
173+
klog.V(3).Infof("invalid delete volume group snapshot req: %v", req)
174174
return nil, err
175175
}
176176

@@ -197,7 +197,7 @@ func (hp *hostPath) DeleteVolumeGroupSnapshot(ctx context.Context, req *csi.Dele
197197
}
198198

199199
for _, snapshotID := range groupSnapshot.SnapshotIDs {
200-
glog.V(4).Infof("deleting snapshot %s", snapshotID)
200+
klog.V(4).Infof("deleting snapshot %s", snapshotID)
201201
path := hp.getSnapshotPath(snapshotID)
202202
os.RemoveAll(path)
203203

@@ -206,7 +206,7 @@ func (hp *hostPath) DeleteVolumeGroupSnapshot(ctx context.Context, req *csi.Dele
206206
}
207207
}
208208

209-
glog.V(4).Infof("deleting groupsnapshot %s", groupSnapshotID)
209+
klog.V(4).Infof("deleting groupsnapshot %s", groupSnapshotID)
210210
if err := hp.state.DeleteGroupSnapshot(groupSnapshotID); err != nil {
211211
return nil, err
212212
}
@@ -216,7 +216,7 @@ func (hp *hostPath) DeleteVolumeGroupSnapshot(ctx context.Context, req *csi.Dele
216216

217217
func (hp *hostPath) GetVolumeGroupSnapshot(ctx context.Context, req *csi.GetVolumeGroupSnapshotRequest) (*csi.GetVolumeGroupSnapshotResponse, error) {
218218
if err := hp.validateGroupControllerServiceRequest(csi.GroupControllerServiceCapability_RPC_CREATE_DELETE_GET_VOLUME_GROUP_SNAPSHOT); err != nil {
219-
glog.V(3).Infof("invalid get volume group snapshot req: %v", req)
219+
klog.V(3).Infof("invalid get volume group snapshot req: %v", req)
220220
return nil, err
221221
}
222222

pkg/hostpath/healthcheck.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"os/exec"
2424
"strings"
2525

26-
"github.com/golang/glog"
26+
"k8s.io/klog/v2"
2727
fs "k8s.io/kubernetes/pkg/volume/util/fs"
2828
)
2929

@@ -85,7 +85,7 @@ func checkMountPointExist(volumePath string) (bool, error) {
8585

8686
out, err := exec.Command(cmdPath, "--json").CombinedOutput()
8787
if err != nil {
88-
glog.V(3).Infof("failed to execute command: %+v", cmdPath)
88+
klog.V(3).Infof("failed to execute command: %+v", cmdPath)
8989
return false, err
9090
}
9191

@@ -138,7 +138,7 @@ func (hp *hostPath) checkPVCapacityValid(volID string) (bool, error) {
138138
return false, err
139139
}
140140
volumeCapacity := volume.VolSize
141-
glog.V(3).Infof("volume capacity: %+v fs capacity:%+v", volumeCapacity, fscapacity)
141+
klog.V(3).Infof("volume capacity: %+v fs capacity:%+v", volumeCapacity, fscapacity)
142142
return fscapacity >= volumeCapacity, nil
143143
}
144144

@@ -153,13 +153,13 @@ func (hp *hostPath) checkPVUsage(volID string) (bool, error) {
153153
return false, err
154154
}
155155

156-
glog.V(3).Infof("fs available: %+v", fsavailable)
156+
klog.V(3).Infof("fs available: %+v", fsavailable)
157157
return fsavailable > 0, nil
158158
}
159159

160160
func (hp *hostPath) doHealthCheckInControllerSide(volID string) (bool, string) {
161161
volumePath := hp.getVolumePath(volID)
162-
glog.V(3).Infof("Volume with ID %s has path %s.", volID, volumePath)
162+
klog.V(3).Infof("Volume with ID %s has path %s.", volID, volumePath)
163163
spExist, err := checkPathExist(volumePath)
164164
if err != nil {
165165
return false, err.Error()

0 commit comments

Comments
 (0)