Skip to content

Commit 1d6927b

Browse files
Upgrade klog v1 to v2 and fix error wrapping
1 parent f7af585 commit 1d6927b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+141
-1936
lines changed

cmd/gce-pd-csi-driver/main.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"runtime"
2424
"time"
2525

26-
"k8s.io/klog"
26+
"k8s.io/klog/v2"
2727

2828
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/common"
2929
gce "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/gce-cloud-provider/compute"
@@ -105,7 +105,7 @@ func handle() {
105105
}
106106
extraVolumeLabels, err := common.ConvertLabelsStringToMap(*extraVolumeLabelsStr)
107107
if err != nil {
108-
klog.Fatalf("Bad extra volume labels: %v", err)
108+
klog.Fatalf("Bad extra volume labels: %w", err)
109109
}
110110

111111
gceDriver := driver.GetGCEDriver()
@@ -122,7 +122,7 @@ func handle() {
122122
if *runControllerService {
123123
cloudProvider, err := gce.CreateCloudProvider(ctx, version, *cloudConfigFilePath)
124124
if err != nil {
125-
klog.Fatalf("Failed to get cloud provider: %v", err)
125+
klog.Fatalf("Failed to get cloud provider: %w", err)
126126
}
127127
initialBackoffDuration := time.Duration(*errorBackoffInitialDurationMs) * time.Millisecond
128128
maxBackoffDuration := time.Duration(*errorBackoffMaxDurationMs) * time.Microsecond
@@ -136,20 +136,20 @@ func handle() {
136136
if *runNodeService {
137137
mounter, err := mountmanager.NewSafeMounter()
138138
if err != nil {
139-
klog.Fatalf("Failed to get safe mounter: %v", err)
139+
klog.Fatalf("Failed to get safe mounter: %w", err)
140140
}
141141
deviceUtils := mountmanager.NewDeviceUtils()
142142
statter := mountmanager.NewStatter(mounter)
143143
meta, err := metadataservice.NewMetadataService()
144144
if err != nil {
145-
klog.Fatalf("Failed to set up metadata service: %v", err)
145+
klog.Fatalf("Failed to set up metadata service: %w", err)
146146
}
147147
nodeServer = driver.NewNodeServer(gceDriver, mounter, deviceUtils, meta, statter)
148148
}
149149

150150
err = gceDriver.SetupGCEDriver(driverName, version, extraVolumeLabels, identityServer, controllerServer, nodeServer)
151151
if err != nil {
152-
klog.Fatalf("Failed to initialize GCE CSI Driver: %v", err)
152+
klog.Fatalf("Failed to initialize GCE CSI Driver: %w", err)
153153
}
154154

155155
gce.AttachDiskBackoff.Duration = *attachDiskBackoffDuration

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ require (
2222
k8s.io/apimachinery v0.24.1
2323
k8s.io/client-go v11.0.1-0.20190805182717-6502b5e7b1b5+incompatible
2424
k8s.io/component-base v0.24.1
25-
k8s.io/klog v1.0.0
25+
k8s.io/klog/v2 v2.60.1
2626
k8s.io/kubernetes v1.24.1
2727
k8s.io/mount-utils v0.24.1
2828
k8s.io/utils v0.0.0-20220713171938-56c0de1e6f5e
@@ -84,7 +84,6 @@ require (
8484
gopkg.in/yaml.v2 v2.4.0 // indirect
8585
gopkg.in/yaml.v3 v3.0.1 // indirect
8686
k8s.io/api v0.24.1 // indirect
87-
k8s.io/klog/v2 v2.60.1 // indirect
8887
k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42 // indirect
8988
k8s.io/test-infra v0.0.0-20210730160938-8ad9b8c53bd8 // indirect
9089
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect

go.sum

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2451,7 +2451,6 @@ k8s.io/gengo v0.0.0-20211129171323-c02415ce4185/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAE
24512451
k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
24522452
k8s.io/klog v0.3.0/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
24532453
k8s.io/klog v0.3.3/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
2454-
k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8=
24552454
k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
24562455
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
24572456
k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y=

pkg/gce-cloud-provider/compute/fake-gce.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"google.golang.org/api/googleapi"
2626
"google.golang.org/grpc/codes"
2727
"google.golang.org/grpc/status"
28-
"k8s.io/klog"
28+
"k8s.io/klog/v2"
2929
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/common"
3030

3131
"k8s.io/apimachinery/pkg/util/sets"

pkg/gce-cloud-provider/compute/gce-compute.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"google.golang.org/grpc/codes"
2929
"google.golang.org/grpc/status"
3030
"k8s.io/apimachinery/pkg/util/wait"
31-
"k8s.io/klog"
31+
"k8s.io/klog/v2"
3232
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/common"
3333
)
3434

@@ -946,7 +946,7 @@ func (cloud *CloudProvider) waitForImageCreation(ctx context.Context, project, i
946946
klog.V(6).Infof("Checking GCE Image %s.", imageName)
947947
image, err := cloud.GetImage(ctx, project, imageName)
948948
if err != nil {
949-
klog.Warningf("Error in getting image %s, %v", imageName, err)
949+
klog.Warningf("Error in getting image %s, %w", imageName, err)
950950
} else if image != nil {
951951
if image.Status != "PENDING" {
952952
klog.V(6).Infof("Image %s status is %s", imageName, image.Status)
@@ -1114,7 +1114,7 @@ func (cloud *CloudProvider) waitForSnapshotCreation(ctx context.Context, project
11141114
klog.V(6).Infof("Checking GCE Snapshot %s.", snapshotName)
11151115
snapshot, err := cloud.GetSnapshot(ctx, project, snapshotName)
11161116
if err != nil {
1117-
klog.Warningf("Error in getting snapshot %s, %v", snapshotName, err)
1117+
klog.Warningf("Error in getting snapshot %s, %w", snapshotName, err)
11181118
} else if snapshot != nil {
11191119
if snapshot.Status != "CREATING" {
11201120
klog.V(6).Infof("Snapshot %s status is %s", snapshotName, snapshot.Status)

pkg/gce-cloud-provider/compute/gce.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
"google.golang.org/api/compute/v1"
3333
"google.golang.org/api/googleapi"
3434
"k8s.io/apimachinery/pkg/util/wait"
35-
"k8s.io/klog"
35+
"k8s.io/klog/v2"
3636
)
3737

3838
const (
@@ -193,7 +193,7 @@ func createCloudServiceWithDefaultServiceAccount(ctx context.Context, vendorVers
193193
func newOauthClient(ctx context.Context, tokenSource oauth2.TokenSource) (*http.Client, error) {
194194
if err := wait.PollImmediate(5*time.Second, 30*time.Second, func() (bool, error) {
195195
if _, err := tokenSource.Token(); err != nil {
196-
klog.Errorf("error fetching initial token: %v", err)
196+
klog.Errorf("error fetching initial token: %w", err)
197197
return false, nil
198198
}
199199
return true, nil

pkg/gce-pd-csi-driver/controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
"k8s.io/apimachinery/pkg/util/sets"
3232
"k8s.io/apimachinery/pkg/util/uuid"
3333
"k8s.io/client-go/util/flowcontrol"
34-
"k8s.io/klog"
34+
"k8s.io/klog/v2"
3535

3636
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/common"
3737
gce "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/gce-cloud-provider/compute"
@@ -371,14 +371,14 @@ func (gceCS *GCEControllerServer) DeleteVolume(ctx context.Context, req *csi.Del
371371
if err != nil {
372372
// Cannot find volume associated with this ID because VolumeID is not in
373373
// correct format, this is a success according to the Spec
374-
klog.Warningf("DeleteVolume treating volume as deleted because volume id %s is invalid: %v", volumeID, err)
374+
klog.Warningf("DeleteVolume treating volume as deleted because volume id %s is invalid: %w", volumeID, err)
375375
return &csi.DeleteVolumeResponse{}, nil
376376
}
377377

378378
project, volKey, err = gceCS.CloudProvider.RepairUnderspecifiedVolumeKey(ctx, project, volKey)
379379
if err != nil {
380380
if gce.IsGCENotFoundError(err) {
381-
klog.Warningf("DeleteVolume treating volume as deleted because cannot find volume %v: %v", volumeID, err)
381+
klog.Warningf("DeleteVolume treating volume as deleted because cannot find volume %v: %w", volumeID, err)
382382
return &csi.DeleteVolumeResponse{}, nil
383383
}
384384
return nil, status.Errorf(codes.Internal, "DeleteVolume error repairing underspecified volume key: %v", err)
@@ -412,7 +412,7 @@ func (gceCS *GCEControllerServer) ControllerPublishVolume(ctx context.Context, r
412412

413413
resp, err := gceCS.executeControllerPublishVolume(ctx, req)
414414
if err != nil {
415-
klog.Infof("For node %s adding backoff due to error for volume %s: %v", req.NodeId, req.VolumeId, err)
415+
klog.Infof("For node %s adding backoff due to error for volume %s: %w", req.NodeId, req.VolumeId, err)
416416
gceCS.errorBackoff.next(backoffId)
417417
} else {
418418
klog.Infof("For node %s clear backoff due to successful publish of volume %v", req.NodeId, req.VolumeId)

pkg/gce-pd-csi-driver/gce-pd-driver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
csi "github.com/container-storage-interface/spec/lib/go/csi"
2222
"google.golang.org/grpc/codes"
2323
"google.golang.org/grpc/status"
24-
"k8s.io/klog"
24+
"k8s.io/klog/v2"
2525
"k8s.io/mount-utils"
2626
common "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/common"
2727
gce "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/gce-cloud-provider/compute"

pkg/gce-pd-csi-driver/node.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626

2727
csi "github.com/container-storage-interface/spec/lib/go/csi"
2828

29-
"k8s.io/klog"
29+
"k8s.io/klog/v2"
3030
"k8s.io/mount-utils"
3131

3232
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/common"
@@ -172,23 +172,23 @@ func (ns *GCENodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePub
172172

173173
err = ns.Mounter.Interface.Mount(sourcePath, targetPath, fstype, options)
174174
if err != nil {
175-
klog.Errorf("Mount of disk %s failed: %v", targetPath, err)
175+
klog.Errorf("Mount of disk %s failed: %w", targetPath, err)
176176
notMnt, mntErr := ns.Mounter.Interface.IsLikelyNotMountPoint(targetPath)
177177
if mntErr != nil {
178-
klog.Errorf("IsLikelyNotMountPoint check failed: %v", mntErr)
178+
klog.Errorf("IsLikelyNotMountPoint check failed: %w", mntErr)
179179
return nil, status.Error(codes.Internal, fmt.Sprintf("NodePublishVolume failed to check whether target path is a mount point: %v", err))
180180
}
181181
if !notMnt {
182182
// TODO: check the logic here again. If mntErr == nil & notMnt == false, it means volume is actually mounted.
183183
// Why need to unmount?
184184
klog.Warningf("Although volume mount failed, but IsLikelyNotMountPoint returns volume %s is mounted already at %s", volumeID, targetPath)
185185
if mntErr = ns.Mounter.Interface.Unmount(targetPath); mntErr != nil {
186-
klog.Errorf("Failed to unmount: %v", mntErr)
186+
klog.Errorf("Failed to unmount: %w", mntErr)
187187
return nil, status.Error(codes.Internal, fmt.Sprintf("NodePublishVolume failed to unmount target path: %v", err))
188188
}
189189
notMnt, mntErr := ns.Mounter.Interface.IsLikelyNotMountPoint(targetPath)
190190
if mntErr != nil {
191-
klog.Errorf("IsLikelyNotMountPoint check failed: %v", mntErr)
191+
klog.Errorf("IsLikelyNotMountPoint check failed: %w", mntErr)
192192
return nil, status.Error(codes.Internal, fmt.Sprintf("NodePublishVolume failed to check whether target path is a mount point: %v", err))
193193
}
194194
if !notMnt {
@@ -366,9 +366,9 @@ func (ns *GCENodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUns
366366

367367
devicePath, err := getDevicePath(ns, volumeID, "" /* partition, which is unused */)
368368
if err != nil {
369-
klog.Errorf("Failed to find device path for volume %s. Device may not be detached cleanly (error is ignored and unstaging is continuing): %v", volumeID, err)
369+
klog.Errorf("Failed to find device path for volume %s. Device may not be detached cleanly (error is ignored and unstaging is continuing): %w", volumeID, err)
370370
} else if err := ns.DeviceUtils.DisableDevice(devicePath); err != nil {
371-
klog.Errorf("Failed to disabled device %s for volume %s. Device may not be detached cleanly (error is ignored and unstaging is continuing): %v", devicePath, volumeID, err)
371+
klog.Errorf("Failed to disabled device %s for volume %s. Device may not be detached cleanly (error is ignored and unstaging is continuing): %w", devicePath, volumeID, err)
372372
}
373373

374374
klog.V(4).Infof("NodeUnstageVolume succeeded on %v from %s", volumeID, stagingTargetPath)

pkg/gce-pd-csi-driver/server.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"sync"
2323

2424
"google.golang.org/grpc"
25-
"k8s.io/klog"
25+
"k8s.io/klog/v2"
2626

2727
csi "github.com/container-storage-interface/spec/lib/go/csi"
2828
)
@@ -106,7 +106,7 @@ func (s *nonBlockingGRPCServer) serve(endpoint string, ids csi.IdentityServer, c
106106
klog.V(4).Infof("Start listening with scheme %v, addr %v", u.Scheme, addr)
107107
listener, err := net.Listen(u.Scheme, addr)
108108
if err != nil {
109-
klog.Fatalf("Failed to listen: %v", err)
109+
klog.Fatalf("Failed to listen: %w", err)
110110
}
111111

112112
server := grpc.NewServer(opts...)
@@ -125,7 +125,7 @@ func (s *nonBlockingGRPCServer) serve(endpoint string, ids csi.IdentityServer, c
125125
klog.V(4).Infof("Listening for connections on address: %#v", listener.Addr())
126126

127127
if err := server.Serve(listener); err != nil {
128-
klog.Fatalf("Failed to serve: %v", err)
128+
klog.Fatalf("Failed to serve: %w", err)
129129
}
130130

131131
}

0 commit comments

Comments
 (0)