Skip to content

Commit 71ce822

Browse files
authored
[occm] align messages formatting (kubernetes#2487)
* [occm] align messages formatting * Align grpc/status.Errorf calls
1 parent 92f5fe3 commit 71ce822

File tree

15 files changed

+78
-80
lines changed

15 files changed

+78
-80
lines changed

pkg/autohealing/cloudprovider/openstack/provider.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,12 @@ func (provider CloudProvider) waitForServerDetachVolumes(serverID string, timeou
210210
for _, attachment := range attachments {
211211
volume, err := volumes.Get(provider.Cinder, attachment.VolumeID).Extract()
212212
if err != nil {
213-
return false, fmt.Errorf("failed to get volume %s, error: %s", attachment.VolumeID, err)
213+
return false, fmt.Errorf("failed to get volume %s, error: %v", attachment.VolumeID, err)
214214
}
215215

216216
bootable, err := strconv.ParseBool(volume.Bootable)
217217
if err != nil {
218-
log.Warningf("Unexpected value for bootable volume %s in volume %s, error %s", volume.Bootable, volume, err)
218+
log.Warningf("Unexpected value for bootable volume %s in volume %v, error %v", volume.Bootable, *volume, err)
219219
}
220220

221221
log.Infof("volume %s is bootable %t", attachment.VolumeID, bootable)
@@ -224,7 +224,7 @@ func (provider CloudProvider) waitForServerDetachVolumes(serverID string, timeou
224224
log.Infof("detaching volume %s for instance %s", attachment.VolumeID, serverID)
225225
err := volumeattach.Delete(provider.Nova, serverID, attachment.ID).ExtractErr()
226226
if err != nil {
227-
return false, fmt.Errorf("failed to detach volume %s from instance %s, error: %s", attachment.VolumeID, serverID, err)
227+
return false, fmt.Errorf("failed to detach volume %s from instance %s, error: %v", attachment.VolumeID, serverID, err)
228228
}
229229
} else {
230230
rootVolumeID = attachment.VolumeID

pkg/autohealing/cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func initConfig() {
124124

125125
// If a config file is found, read it in.
126126
if err := viper.ReadInConfig(); err != nil {
127-
log.Fatalf("Failed to read config file, error: %s", err)
127+
log.Fatalf("Failed to read config file, error: %v", err)
128128
}
129129

130130
log.Infof("Using config file %s", viper.ConfigFileUsed())

pkg/client/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func (authOpts AuthOpts) ToAuthOptions() gophercloud.AuthOptions {
156156

157157
ao, err := clientconfig.AuthOptions(&opts)
158158
if err != nil {
159-
klog.V(1).Infof("Error parsing auth: %s", err)
159+
klog.V(1).Infof("Error parsing auth: %v", err)
160160
return gophercloud.AuthOptions{}
161161
}
162162

@@ -256,7 +256,7 @@ func NewOpenStackClient(cfg *AuthOpts, userAgent string, extraUserAgent ...strin
256256
// read and parse CA certificate from file
257257
caPool, err = cert.NewPool(cfg.CAFile)
258258
if err != nil {
259-
return nil, fmt.Errorf("failed to read and parse %s certificate: %s", cfg.CAFile, err)
259+
return nil, fmt.Errorf("failed to read and parse %s certificate: %v", cfg.CAFile, err)
260260
}
261261
} else if cfg.CAFileContents != "" {
262262
// parse CA certificate from the contents
@@ -277,7 +277,7 @@ func NewOpenStackClient(cfg *AuthOpts, userAgent string, extraUserAgent ...strin
277277
if cfg.CertFile != "" && cfg.KeyFile != "" {
278278
cert, err := tls.LoadX509KeyPair(cfg.CertFile, cfg.KeyFile)
279279
if err != nil {
280-
return nil, fmt.Errorf("error loading TLS key pair: %s", err)
280+
return nil, fmt.Errorf("error loading TLS key pair: %v", err)
281281
}
282282
config.Certificates = []tls.Certificate{cert}
283283
}

pkg/csi/cinder/controllerserver.go

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package cinder
1818

1919
import (
20-
"fmt"
2120
"strconv"
2221

2322
"github.com/container-storage-interface/spec/lib/go/csi"
@@ -86,7 +85,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
8685
volumes, err := cloud.GetVolumesByName(volName)
8786
if err != nil {
8887
klog.Errorf("Failed to query for existing Volume during CreateVolume: %v", err)
89-
return nil, status.Error(codes.Internal, fmt.Sprintf("Failed to get volumes: %s", err))
88+
return nil, status.Errorf(codes.Internal, "Failed to get volumes: %v", err)
9089
}
9190

9291
if len(volumes) == 1 {
@@ -139,7 +138,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
139138

140139
if err != nil {
141140
klog.Errorf("Failed to CreateVolume: %v", err)
142-
return nil, status.Error(codes.Internal, fmt.Sprintf("CreateVolume failed with error %v", err))
141+
return nil, status.Errorf(codes.Internal, "CreateVolume failed with error %v", err)
143142

144143
}
145144

@@ -163,7 +162,7 @@ func (cs *controllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
163162
return &csi.DeleteVolumeResponse{}, nil
164163
}
165164
klog.Errorf("Failed to DeleteVolume: %v", err)
166-
return nil, status.Error(codes.Internal, fmt.Sprintf("DeleteVolume failed with error %v", err))
165+
return nil, status.Errorf(codes.Internal, "DeleteVolume failed with error %v", err)
167166
}
168167

169168
klog.V(4).Infof("DeleteVolume: Successfully deleted volume %s", volID)
@@ -194,34 +193,34 @@ func (cs *controllerServer) ControllerPublishVolume(ctx context.Context, req *cs
194193
if cpoerrors.IsNotFound(err) {
195194
return nil, status.Errorf(codes.NotFound, "[ControllerPublishVolume] Volume %s not found", volumeID)
196195
}
197-
return nil, status.Error(codes.Internal, fmt.Sprintf("[ControllerPublishVolume] get volume failed with error %v", err))
196+
return nil, status.Errorf(codes.Internal, "[ControllerPublishVolume] get volume failed with error %v", err)
198197
}
199198

200199
_, err = cs.Cloud.GetInstanceByID(instanceID)
201200
if err != nil {
202201
if cpoerrors.IsNotFound(err) {
203202
return nil, status.Errorf(codes.NotFound, "[ControllerPublishVolume] Instance %s not found", instanceID)
204203
}
205-
return nil, status.Error(codes.Internal, fmt.Sprintf("[ControllerPublishVolume] GetInstanceByID failed with error %v", err))
204+
return nil, status.Errorf(codes.Internal, "[ControllerPublishVolume] GetInstanceByID failed with error %v", err)
206205
}
207206

208207
_, err = cs.Cloud.AttachVolume(instanceID, volumeID)
209208
if err != nil {
210209
klog.Errorf("Failed to AttachVolume: %v", err)
211-
return nil, status.Error(codes.Internal, fmt.Sprintf("[ControllerPublishVolume] Attach Volume failed with error %v", err))
210+
return nil, status.Errorf(codes.Internal, "[ControllerPublishVolume] Attach Volume failed with error %v", err)
212211

213212
}
214213

215214
err = cs.Cloud.WaitDiskAttached(instanceID, volumeID)
216215
if err != nil {
217216
klog.Errorf("Failed to WaitDiskAttached: %v", err)
218-
return nil, status.Error(codes.Internal, fmt.Sprintf("[ControllerPublishVolume] failed to attach volume: %v", err))
217+
return nil, status.Errorf(codes.Internal, "[ControllerPublishVolume] failed to attach volume: %v", err)
219218
}
220219

221220
devicePath, err := cs.Cloud.GetAttachmentDiskPath(instanceID, volumeID)
222221
if err != nil {
223222
klog.Errorf("Failed to GetAttachmentDiskPath: %v", err)
224-
return nil, status.Error(codes.Internal, fmt.Sprintf("[ControllerPublishVolume] failed to get device path of attached volume : %v", err))
223+
return nil, status.Errorf(codes.Internal, "[ControllerPublishVolume] failed to get device path of attached volume: %v", err)
225224
}
226225

227226
klog.V(4).Infof("ControllerPublishVolume %s on %s is successful", volumeID, instanceID)
@@ -251,7 +250,7 @@ func (cs *controllerServer) ControllerUnpublishVolume(ctx context.Context, req *
251250
klog.V(3).Infof("ControllerUnpublishVolume assuming volume %s is detached, because node %s does not exist", volumeID, instanceID)
252251
return &csi.ControllerUnpublishVolumeResponse{}, nil
253252
}
254-
return nil, status.Error(codes.Internal, fmt.Sprintf("[ControllerUnpublishVolume] GetInstanceByID failed with error %v", err))
253+
return nil, status.Errorf(codes.Internal, "[ControllerUnpublishVolume] GetInstanceByID failed with error %v", err)
255254
}
256255

257256
err = cs.Cloud.DetachVolume(instanceID, volumeID)
@@ -261,7 +260,7 @@ func (cs *controllerServer) ControllerUnpublishVolume(ctx context.Context, req *
261260
return &csi.ControllerUnpublishVolumeResponse{}, nil
262261
}
263262
klog.Errorf("Failed to DetachVolume: %v", err)
264-
return nil, status.Error(codes.Internal, fmt.Sprintf("ControllerUnpublishVolume Detach Volume failed with error %v", err))
263+
return nil, status.Errorf(codes.Internal, "ControllerUnpublishVolume Detach Volume failed with error %v", err)
265264
}
266265

267266
err = cs.Cloud.WaitDiskDetached(instanceID, volumeID)
@@ -271,7 +270,7 @@ func (cs *controllerServer) ControllerUnpublishVolume(ctx context.Context, req *
271270
klog.V(3).Infof("ControllerUnpublishVolume assuming volume %s is detached, because it was deleted in the meanwhile", volumeID)
272271
return &csi.ControllerUnpublishVolumeResponse{}, nil
273272
}
274-
return nil, status.Error(codes.Internal, fmt.Sprintf("ControllerUnpublishVolume failed with error %v", err))
273+
return nil, status.Errorf(codes.Internal, "ControllerUnpublishVolume failed with error %v", err)
275274
}
276275

277276
klog.V(4).Infof("ControllerUnpublishVolume %s on %s", volumeID, instanceID)
@@ -283,8 +282,7 @@ func (cs *controllerServer) ListVolumes(ctx context.Context, req *csi.ListVolume
283282
klog.V(4).Infof("ListVolumes: called with %+#v request", req)
284283

285284
if req.MaxEntries < 0 {
286-
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf(
287-
"[ListVolumes] Invalid max entries request %v, must not be negative ", req.MaxEntries))
285+
return nil, status.Errorf(codes.InvalidArgument, "[ListVolumes] Invalid max entries request %v, must not be negative ", req.MaxEntries)
288286
}
289287
maxEntries := int(req.MaxEntries)
290288

@@ -294,7 +292,7 @@ func (cs *controllerServer) ListVolumes(ctx context.Context, req *csi.ListVolume
294292
if cpoerrors.IsInvalidError(err) {
295293
return nil, status.Errorf(codes.Aborted, "[ListVolumes] Invalid request: %v", err)
296294
}
297-
return nil, status.Error(codes.Internal, fmt.Sprintf("ListVolumes failed with error %v", err))
295+
return nil, status.Errorf(codes.Internal, "ListVolumes failed with error %v", err)
298296
}
299297

300298
ventries := make([]*csi.ListVolumesResponse_Entry, 0, len(vlist))
@@ -378,7 +376,7 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
378376
snap, err = cs.Cloud.CreateSnapshot(name, volumeID, &properties)
379377
if err != nil {
380378
klog.Errorf("Failed to Create snapshot: %v", err)
381-
return nil, status.Error(codes.Internal, fmt.Sprintf("CreateSnapshot failed with error %v", err))
379+
return nil, status.Errorf(codes.Internal, "CreateSnapshot failed with error %v", err)
382380
}
383381

384382
klog.V(3).Infof("CreateSnapshot %s from volume with ID: %s", name, volumeID)
@@ -392,7 +390,7 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
392390
err = cs.Cloud.WaitSnapshotReady(snap.ID)
393391
if err != nil {
394392
klog.Errorf("Failed to WaitSnapshotReady: %v", err)
395-
return nil, status.Error(codes.Internal, fmt.Sprintf("CreateSnapshot failed with error %v", err))
393+
return nil, status.Errorf(codes.Internal, "CreateSnapshot failed with error %v", err)
396394
}
397395

398396
return &csi.CreateSnapshotResponse{
@@ -423,7 +421,7 @@ func (cs *controllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteS
423421
return &csi.DeleteSnapshotResponse{}, nil
424422
}
425423
klog.Errorf("Failed to Delete snapshot: %v", err)
426-
return nil, status.Error(codes.Internal, fmt.Sprintf("DeleteSnapshot failed with error %v", err))
424+
return nil, status.Errorf(codes.Internal, "DeleteSnapshot failed with error %v", err)
427425
}
428426
return &csi.DeleteSnapshotResponse{}, nil
429427
}
@@ -438,7 +436,7 @@ func (cs *controllerServer) ListSnapshots(ctx context.Context, req *csi.ListSnap
438436
klog.V(3).Infof("Snapshot %s not found", snapshotID)
439437
return &csi.ListSnapshotsResponse{}, nil
440438
}
441-
return nil, status.Errorf(codes.Internal, "Failed to GetSnapshot %s : %v", snapshotID, err)
439+
return nil, status.Errorf(codes.Internal, "Failed to GetSnapshot %s: %v", snapshotID, err)
442440
}
443441

444442
ctime := timestamppb.New(snap.CreatedAt)
@@ -532,9 +530,9 @@ func (cs *controllerServer) ValidateVolumeCapabilities(ctx context.Context, req
532530
_, err := cs.Cloud.GetVolume(volumeID)
533531
if err != nil {
534532
if cpoerrors.IsNotFound(err) {
535-
return nil, status.Error(codes.NotFound, fmt.Sprintf("ValidateVolumeCapabiltites Volume %s not found", volumeID))
533+
return nil, status.Errorf(codes.NotFound, "ValidateVolumeCapabiltites Volume %s not found", volumeID)
536534
}
537-
return nil, status.Error(codes.Internal, fmt.Sprintf("ValidateVolumeCapabiltites %v", err))
535+
return nil, status.Errorf(codes.Internal, "ValidateVolumeCapabiltites %v", err)
538536
}
539537

540538
for _, cap := range reqVolCap {
@@ -575,7 +573,7 @@ func (cs *controllerServer) ControllerGetVolume(ctx context.Context, req *csi.Co
575573
if cpoerrors.IsNotFound(err) {
576574
return nil, status.Errorf(codes.NotFound, "Volume %s not found", volumeID)
577575
}
578-
return nil, status.Error(codes.Internal, fmt.Sprintf("ControllerGetVolume failed with error %v", err))
576+
return nil, status.Errorf(codes.Internal, "ControllerGetVolume failed with error %v", err)
579577
}
580578

581579
ventry := csi.ControllerGetVolumeResponse{
@@ -620,7 +618,7 @@ func (cs *controllerServer) ControllerExpandVolume(ctx context.Context, req *csi
620618
if cpoerrors.IsNotFound(err) {
621619
return nil, status.Error(codes.NotFound, "Volume not found")
622620
}
623-
return nil, status.Error(codes.Internal, fmt.Sprintf("GetVolume failed with error %v", err))
621+
return nil, status.Errorf(codes.Internal, "GetVolume failed with error %v", err)
624622
}
625623

626624
if volume.Size >= volSizeGB {
@@ -634,15 +632,15 @@ func (cs *controllerServer) ControllerExpandVolume(ctx context.Context, req *csi
634632

635633
err = cs.Cloud.ExpandVolume(volumeID, volume.Status, volSizeGB)
636634
if err != nil {
637-
return nil, status.Errorf(codes.Internal, fmt.Sprintf("Could not resize volume %q to size %v: %v", volumeID, volSizeGB, err))
635+
return nil, status.Errorf(codes.Internal, "Could not resize volume %q to size %v: %v", volumeID, volSizeGB, err)
638636
}
639637

640638
// we need wait for the volume to be available or InUse, it might be error_extending in some scenario
641639
targetStatus := []string{openstack.VolumeAvailableStatus, openstack.VolumeInUseStatus}
642640
err = cs.Cloud.WaitVolumeTargetStatus(volumeID, targetStatus)
643641
if err != nil {
644642
klog.Errorf("Failed to WaitVolumeTargetStatus of volume %s: %v", volumeID, err)
645-
return nil, status.Error(codes.Internal, fmt.Sprintf("[ControllerExpandVolume] Volume %s not in target state after resize operation : %v", volumeID, err))
643+
return nil, status.Errorf(codes.Internal, "[ControllerExpandVolume] Volume %s not in target state after resize operation: %v", volumeID, err)
646644
}
647645

648646
klog.V(4).Infof("ControllerExpandVolume resized volume %v to size %v", volumeID, volSizeGB)

0 commit comments

Comments
 (0)