Skip to content

Commit be6c6c5

Browse files
authored
Merge pull request #1216 from sunnylovestiramisu/automated-cherry-pick-of-#1084-upstream-release-1.7
Automated cherry pick of #1084: Upgrade klog v1 to v2 and fix error wrapping
2 parents 0fe1da4 + 348848f commit be6c6c5

Some content is hidden

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

68 files changed

+2285
-2607
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"
@@ -102,7 +102,7 @@ func handle() {
102102
}
103103
extraVolumeLabels, err := common.ConvertLabelsStringToMap(*extraVolumeLabelsStr)
104104
if err != nil {
105-
klog.Fatalf("Bad extra volume labels: %v", err)
105+
klog.Fatalf("Bad extra volume labels: %w", err)
106106
}
107107

108108
gceDriver := driver.GetGCEDriver()
@@ -119,7 +119,7 @@ func handle() {
119119
if *runControllerService {
120120
cloudProvider, err := gce.CreateCloudProvider(ctx, version, *cloudConfigFilePath)
121121
if err != nil {
122-
klog.Fatalf("Failed to get cloud provider: %v", err)
122+
klog.Fatalf("Failed to get cloud provider: %w", err)
123123
}
124124
controllerServer = driver.NewControllerServer(gceDriver, cloudProvider)
125125
} else if *cloudConfigFilePath != "" {
@@ -131,20 +131,20 @@ func handle() {
131131
if *runNodeService {
132132
mounter, err := mountmanager.NewSafeMounter()
133133
if err != nil {
134-
klog.Fatalf("Failed to get safe mounter: %v", err)
134+
klog.Fatalf("Failed to get safe mounter: %w", err)
135135
}
136136
deviceUtils := mountmanager.NewDeviceUtils()
137137
statter := mountmanager.NewStatter(mounter)
138138
meta, err := metadataservice.NewMetadataService()
139139
if err != nil {
140-
klog.Fatalf("Failed to set up metadata service: %v", err)
140+
klog.Fatalf("Failed to set up metadata service: %w", err)
141141
}
142142
nodeServer = driver.NewNodeServer(gceDriver, mounter, deviceUtils, meta, statter)
143143
}
144144

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

150150
gce.AttachDiskBackoff.Duration = *attachDiskBackoffDuration

go.mod

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ require (
2222
k8s.io/apimachinery v0.22.0
2323
k8s.io/client-go v11.0.1-0.20190805182717-6502b5e7b1b5+incompatible
2424
k8s.io/component-base v0.22.0
25-
k8s.io/klog v1.0.0
25+
k8s.io/klog/v2 v2.60.1
2626
k8s.io/kubernetes v1.22.0
2727
k8s.io/mount-utils v0.22.0
2828
k8s.io/test-infra v0.0.0-20200115230622-70a5174aa78d
@@ -36,7 +36,7 @@ require (
3636
github.com/cespare/xxhash/v2 v2.1.1 // indirect
3737
github.com/davecgh/go-spew v1.1.1 // indirect
3838
github.com/fsnotify/fsnotify v1.4.9 // indirect
39-
github.com/go-logr/logr v0.4.0 // indirect
39+
github.com/go-logr/logr v1.2.0 // indirect
4040
github.com/gogo/protobuf v1.3.2 // indirect
4141
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
4242
github.com/google/go-cmp v0.5.5 // indirect
@@ -71,7 +71,6 @@ require (
7171
gopkg.in/yaml.v2 v2.4.0 // indirect
7272
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
7373
k8s.io/api v0.22.0 // indirect
74-
k8s.io/klog/v2 v2.9.0 // indirect
7574
sigs.k8s.io/structured-merge-diff/v4 v4.1.2 // indirect
7675
sigs.k8s.io/yaml v1.2.0 // indirect
7776
)

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,9 @@ github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG
242242
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
243243
github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
244244
github.com/go-logr/logr v0.3.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
245-
github.com/go-logr/logr v0.4.0 h1:K7/B1jt6fIBQVd4Owv2MqGQClcgf0R266+7C/QjRcLc=
246245
github.com/go-logr/logr v0.4.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
246+
github.com/go-logr/logr v1.2.0 h1:QK40JKJyMdUDz+h+xvCsru/bJhvG0UxvePV0ufL/AcE=
247+
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
247248
github.com/go-logr/zapr v0.1.0/go.mod h1:tabnROwaDl0UNxkVeFRbY8bwB37GwRv0P8lg6aAiEnk=
248249
github.com/go-logr/zapr v0.1.1/go.mod h1:tabnROwaDl0UNxkVeFRbY8bwB37GwRv0P8lg6aAiEnk=
249250
github.com/go-openapi/jsonpointer v0.19.2/go.mod h1:3akKfEdA7DF1sugOqz1dVQHBcuDBPKZGEoHC/NkiQRg=
@@ -1216,8 +1217,9 @@ k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
12161217
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
12171218
k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y=
12181219
k8s.io/klog/v2 v2.4.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y=
1219-
k8s.io/klog/v2 v2.9.0 h1:D7HV+n1V57XeZ0m6tdRkfknthUaM06VFbWldOFh8kzM=
12201220
k8s.io/klog/v2 v2.9.0/go.mod h1:hy9LJ/NvuK+iVyP4Ehqva4HxZG/oXyIS3n3Jmire4Ec=
1221+
k8s.io/klog/v2 v2.60.1 h1:VW25q3bZx9uE3vvdL6M8ezOX79vA2Aq1nEWLqNQclHc=
1222+
k8s.io/klog/v2 v2.60.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
12211223
k8s.io/kube-aggregator v0.22.0/go.mod h1:zHTepg0Q4tKzru7Pwg1QYHWrU/wrvIXM8hUdDAH66qg=
12221224
k8s.io/kube-controller-manager v0.22.0/go.mod h1:E/EYMoCj8bbPRmu19JF4B9QLyQL8Tywg+9Q/rg+F80U=
12231225
k8s.io/kube-openapi v0.0.0-20180731170545-e3762e86a74c/go.mod h1:BXM9ceUBTj2QnfH2MK1odQs778ajze1RxcmP6S8RVVc=

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)
@@ -1112,7 +1112,7 @@ func (cloud *CloudProvider) waitForSnapshotCreation(ctx context.Context, project
11121112
klog.V(6).Infof("Checking GCE Snapshot %s.", snapshotName)
11131113
snapshot, err := cloud.GetSnapshot(ctx, project, snapshotName)
11141114
if err != nil {
1115-
klog.Warningf("Error in getting snapshot %s, %v", snapshotName, err)
1115+
klog.Warningf("Error in getting snapshot %s, %w", snapshotName, err)
11161116
} else if snapshot != nil {
11171117
if snapshot.Status != "CREATING" {
11181118
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
@@ -32,7 +32,7 @@ import (
3232
"k8s.io/apimachinery/pkg/util/sets"
3333
"k8s.io/apimachinery/pkg/util/uuid"
3434
"k8s.io/client-go/util/flowcontrol"
35-
"k8s.io/klog"
35+
"k8s.io/klog/v2"
3636

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

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

419419
resp, err := gceCS.executeControllerPublishVolume(ctx, req)
420420
if err != nil {
421-
klog.Infof("For node %s adding backoff due to error for volume %s: %v", req.NodeId, req.VolumeId, err)
421+
klog.Infof("For node %s adding backoff due to error for volume %s: %w", req.NodeId, req.VolumeId, err)
422422
gceCS.errorBackoff.next(backoffId)
423423
} else {
424424
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
@@ -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
gce "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/gce-cloud-provider/compute"

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

Lines changed: 5 additions & 5 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 {

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)