Skip to content

Commit f2fcb35

Browse files
sunnylovestiramisujudemars
authored andcommitted
Upgrade klog v1 to v2 and fix error wrapping
1 parent ebd2696 commit f2fcb35

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

+110
-1939
lines changed

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

+6-6
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
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/deviceutils"
@@ -104,7 +104,7 @@ func handle() {
104104
}
105105
extraVolumeLabels, err := common.ConvertLabelsStringToMap(*extraVolumeLabelsStr)
106106
if err != nil {
107-
klog.Fatalf("Bad extra volume labels: %v", err)
107+
klog.Fatalf("Bad extra volume labels: %w", err)
108108
}
109109

110110
gceDriver := driver.GetGCEDriver()
@@ -121,7 +121,7 @@ func handle() {
121121
if *runControllerService {
122122
cloudProvider, err := gce.CreateCloudProvider(ctx, version, *cloudConfigFilePath, *computeEndpoint)
123123
if err != nil {
124-
klog.Fatalf("Failed to get cloud provider: %v", err)
124+
klog.Fatalf("Failed to get cloud provider: %w", err)
125125
}
126126
controllerServer = driver.NewControllerServer(gceDriver, cloudProvider)
127127
} else if *cloudConfigFilePath != "" {
@@ -133,20 +133,20 @@ func handle() {
133133
if *runNodeService {
134134
mounter, err := mountmanager.NewSafeMounter()
135135
if err != nil {
136-
klog.Fatalf("Failed to get safe mounter: %v", err)
136+
klog.Fatalf("Failed to get safe mounter: %w", err)
137137
}
138138
deviceUtils := deviceutils.NewDeviceUtils()
139139
statter := mountmanager.NewStatter(mounter)
140140
meta, err := metadataservice.NewMetadataService()
141141
if err != nil {
142-
klog.Fatalf("Failed to set up metadata service: %v", err)
142+
klog.Fatalf("Failed to set up metadata service: %w", err)
143143
}
144144
nodeServer = driver.NewNodeServer(gceDriver, mounter, deviceUtils, meta, statter)
145145
}
146146

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

152152
gce.AttachDiskBackoff.Duration = *attachDiskBackoffDuration

go.mod

+1-2
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

-1
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/deviceutils/device-utils.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"time"
2626

2727
"k8s.io/apimachinery/pkg/util/wait"
28-
"k8s.io/klog"
28+
"k8s.io/klog/v2"
2929
pathutils "k8s.io/utils/path"
3030
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/resizefs"
3131
)

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

+1-1
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

+3-3
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

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

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

+2-2
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 (
@@ -201,7 +201,7 @@ func createCloudServiceWithDefaultServiceAccount(ctx context.Context, vendorVers
201201
func newOauthClient(ctx context.Context, tokenSource oauth2.TokenSource) (*http.Client, error) {
202202
if err := wait.PollImmediate(5*time.Second, 30*time.Second, func() (bool, error) {
203203
if _, err := tokenSource.Token(); err != nil {
204-
klog.Errorf("error fetching initial token: %v", err)
204+
klog.Errorf("error fetching initial token: %w", err)
205205
return false, nil
206206
}
207207
return true, nil

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

+4-4
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"
@@ -376,14 +376,14 @@ func (gceCS *GCEControllerServer) DeleteVolume(ctx context.Context, req *csi.Del
376376
if err != nil {
377377
// Cannot find volume associated with this ID because VolumeID is not in
378378
// correct format, this is a success according to the Spec
379-
klog.Warningf("DeleteVolume treating volume as deleted because volume id %s is invalid: %v", volumeID, err)
379+
klog.Warningf("DeleteVolume treating volume as deleted because volume id %s is invalid: %w", volumeID, err)
380380
return &csi.DeleteVolumeResponse{}, nil
381381
}
382382

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

418418
resp, err := gceCS.executeControllerPublishVolume(ctx, req)
419419
if err != nil {
420-
klog.Infof("For node %s adding backoff due to error for volume %s: %v", req.NodeId, req.VolumeId, err)
420+
klog.Infof("For node %s adding backoff due to error for volume %s: %w", req.NodeId, req.VolumeId, err)
421421
gceCS.errorBackoff.next(backoffId)
422422
} else {
423423
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
csi "github.com/container-storage-interface/spec/lib/go/csi"
2121
"google.golang.org/grpc/codes"
2222
"google.golang.org/grpc/status"
23-
"k8s.io/klog"
23+
"k8s.io/klog/v2"
2424
"k8s.io/mount-utils"
2525
common "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/common"
2626
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/deviceutils"

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

+7-7
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"
@@ -173,23 +173,23 @@ func (ns *GCENodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePub
173173

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

376376
devicePath, err := getDevicePath(ns, volumeID, "" /* partition, which is unused */)
377377
if err != nil {
378-
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)
378+
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)
379379
} else if err := ns.DeviceUtils.DisableDevice(devicePath); err != nil {
380-
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)
380+
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)
381381
}
382382

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

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

+3-3
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
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424

2525
csi "github.com/container-storage-interface/spec/lib/go/csi"
2626
"google.golang.org/grpc"
27-
"k8s.io/klog"
27+
"k8s.io/klog/v2"
2828
)
2929

3030
const (
@@ -67,7 +67,7 @@ func logGRPC(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, h
6767
klog.V(4).Infof("%s called with request: %s", info.FullMethod, req)
6868
resp, err := handler(ctx, req)
6969
if err != nil {
70-
klog.Errorf("%s returned with error: %v", info.FullMethod, err)
70+
klog.Errorf("%s returned with error: %w", info.FullMethod, err)
7171
} else {
7272
klog.V(4).Infof("%s returned with response: %s", info.FullMethod, resp)
7373
}

pkg/metrics/metrics.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"os"
2323

2424
"k8s.io/component-base/metrics"
25-
"k8s.io/klog"
25+
"k8s.io/klog/v2"
2626
)
2727

2828
const (
@@ -101,7 +101,7 @@ func (mm *metricsManager) InitializeHttpHandler(address, path string) {
101101
go func() {
102102
klog.Infof("Metric server listening at %q", address)
103103
if err := http.ListenAndServe(address, mux); err != nil {
104-
klog.Fatalf("Failed to start metric server at specified address (%q) and path (%q): %s", address, path, err)
104+
klog.Fatalf("Failed to start metric server at specified address (%q) and path (%q): %w", address, path, err)
105105
}
106106
}()
107107
}

pkg/mount-manager/safe-mounter-v1_windows.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
volumeapi "github.com/kubernetes-csi/csi-proxy/client/api/volume/v1"
3535
volumeclient "github.com/kubernetes-csi/csi-proxy/client/groups/volume/v1"
3636

37-
"k8s.io/klog"
37+
"k8s.io/klog/v2"
3838
mount "k8s.io/mount-utils"
3939
)
4040

pkg/mount-manager/safe-mounter-v1beta_windows.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
volumeapi "github.com/kubernetes-csi/csi-proxy/client/api/volume/v1beta1"
3535
volumeclient "github.com/kubernetes-csi/csi-proxy/client/groups/volume/v1beta1"
3636

37-
"k8s.io/klog"
37+
"k8s.io/klog/v2"
3838
mount "k8s.io/mount-utils"
3939
)
4040

pkg/mount-manager/safe-mounter_windows.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ limitations under the License.
1717
package mountmanager
1818

1919
import (
20-
"k8s.io/klog"
20+
"k8s.io/klog/v2"
2121
"k8s.io/mount-utils"
2222
utilexec "k8s.io/utils/exec"
2323
)

pkg/resizefs/resizefs_linux.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"google.golang.org/grpc/codes"
2323
"google.golang.org/grpc/status"
2424

25-
"k8s.io/klog"
25+
"k8s.io/klog/v2"
2626
"k8s.io/mount-utils"
2727
)
2828

pkg/resizefs/resizefs_windows.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
volumeapiv1 "github.com/kubernetes-csi/csi-proxy/client/api/volume/v1"
2626
volumeapiv1beta1 "github.com/kubernetes-csi/csi-proxy/client/api/volume/v1beta1"
2727

28-
"k8s.io/klog"
28+
"k8s.io/klog/v2"
2929
"k8s.io/mount-utils"
3030
mounter "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/mount-manager"
3131
)

test/e2e/tests/multi_zone_e2e_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
. "github.com/onsi/gomega"
2525
"k8s.io/apimachinery/pkg/util/sets"
2626
"k8s.io/apimachinery/pkg/util/uuid"
27-
"k8s.io/klog"
27+
"k8s.io/klog/v2"
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"
3030
testutils "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/test/e2e/utils"
@@ -191,7 +191,7 @@ func testLifecycleWithVerify(volID string, volName string, instance *remote.Inst
191191
// Detach Disk
192192
err = client.ControllerUnpublishVolume(volID, instance.GetNodeID())
193193
if err != nil {
194-
klog.Errorf("Failed to detach disk: %v", err)
194+
klog.Errorf("Failed to detach disk: %w", err)
195195
}
196196

197197
}()
@@ -206,19 +206,19 @@ func testLifecycleWithVerify(volID string, volName string, instance *remote.Inst
206206

207207
//err = client.NodeStageExt4Volume(volID, stageDir)
208208
if err != nil {
209-
return fmt.Errorf("NodeStageExt4Volume failed with error: %v", err)
209+
return fmt.Errorf("NodeStageExt4Volume failed with error: %w", err)
210210
}
211211

212212
defer func() {
213213
// Unstage Disk
214214
err = client.NodeUnstageVolume(volID, stageDir)
215215
if err != nil {
216-
klog.Errorf("Failed to unstage volume: %v", err)
216+
klog.Errorf("Failed to unstage volume: %w", err)
217217
}
218218
fp := filepath.Join("/tmp/", volName)
219219
err = testutils.RmAll(instance, fp)
220220
if err != nil {
221-
klog.Errorf("Failed to rm file path %s: %v", fp, err)
221+
klog.Errorf("Failed to rm file path %s: %w", fp, err)
222222
}
223223
}()
224224

0 commit comments

Comments
 (0)