Skip to content

Commit 546cafa

Browse files
committed
Remove redundant else blocks
Signed-off-by: Humble Chirammal <[email protected]>
1 parent 0e4d11b commit 546cafa

File tree

4 files changed

+23
-31
lines changed

4 files changed

+23
-31
lines changed

pkg/controller/framework_test.go

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -276,21 +276,19 @@ func (r *snapshotReactor) React(action core.Action) (handled bool, ret runtime.O
276276
if found {
277277
glog.V(4).Infof("GetVolume: found %s", content.Name)
278278
return true, content, nil
279-
} else {
280-
glog.V(4).Infof("GetVolume: content %s not found", name)
281-
return true, nil, fmt.Errorf("cannot find content %s", name)
282279
}
280+
glog.V(4).Infof("GetVolume: content %s not found", name)
281+
return true, nil, fmt.Errorf("cannot find content %s", name)
283282

284283
case action.Matches("get", "volumesnapshots"):
285284
name := action.(core.GetAction).GetName()
286285
snapshot, found := r.snapshots[name]
287286
if found {
288287
glog.V(4).Infof("GetSnapshot: found %s", snapshot.Name)
289288
return true, snapshot, nil
290-
} else {
291-
glog.V(4).Infof("GetSnapshot: content %s not found", name)
292-
return true, nil, fmt.Errorf("cannot find snapshot %s", name)
293289
}
290+
glog.V(4).Infof("GetSnapshot: content %s not found", name)
291+
return true, nil, fmt.Errorf("cannot find snapshot %s", name)
294292

295293
case action.Matches("delete", "volumesnapshotcontents"):
296294
name := action.(core.DeleteAction).GetName()
@@ -300,9 +298,8 @@ func (r *snapshotReactor) React(action core.Action) (handled bool, ret runtime.O
300298
delete(r.contents, name)
301299
r.changedSinceLastSync++
302300
return true, nil, nil
303-
} else {
304-
return true, nil, fmt.Errorf("cannot delete content %s: not found", name)
305301
}
302+
return true, nil, fmt.Errorf("cannot delete content %s: not found", name)
306303

307304
case action.Matches("delete", "volumesnapshots"):
308305
name := action.(core.DeleteAction).GetName()
@@ -312,53 +309,49 @@ func (r *snapshotReactor) React(action core.Action) (handled bool, ret runtime.O
312309
delete(r.snapshots, name)
313310
r.changedSinceLastSync++
314311
return true, nil, nil
315-
} else {
316-
return true, nil, fmt.Errorf("cannot delete snapshot %s: not found", name)
317312
}
313+
return true, nil, fmt.Errorf("cannot delete snapshot %s: not found", name)
318314

319315
case action.Matches("get", "persistentvolumes"):
320316
name := action.(core.GetAction).GetName()
321317
volume, found := r.volumes[name]
322318
if found {
323319
glog.V(4).Infof("GetVolume: found %s", volume.Name)
324320
return true, volume, nil
325-
} else {
326-
glog.V(4).Infof("GetVolume: volume %s not found", name)
327-
return true, nil, fmt.Errorf("cannot find volume %s", name)
328321
}
322+
glog.V(4).Infof("GetVolume: volume %s not found", name)
323+
return true, nil, fmt.Errorf("cannot find volume %s", name)
329324

330325
case action.Matches("get", "persistentvolumeclaims"):
331326
name := action.(core.GetAction).GetName()
332327
claim, found := r.claims[name]
333328
if found {
334329
glog.V(4).Infof("GetClaim: found %s", claim.Name)
335330
return true, claim, nil
336-
} else {
337-
glog.V(4).Infof("GetClaim: claim %s not found", name)
338-
return true, nil, fmt.Errorf("cannot find claim %s", name)
339331
}
332+
glog.V(4).Infof("GetClaim: claim %s not found", name)
333+
return true, nil, fmt.Errorf("cannot find claim %s", name)
340334

341335
case action.Matches("get", "storageclasses"):
342336
name := action.(core.GetAction).GetName()
343337
storageClass, found := r.storageClasses[name]
344338
if found {
345339
glog.V(4).Infof("GetStorageClass: found %s", storageClass.Name)
346340
return true, storageClass, nil
347-
} else {
348-
glog.V(4).Infof("GetStorageClass: storageClass %s not found", name)
349-
return true, nil, fmt.Errorf("cannot find storageClass %s", name)
350341
}
342+
glog.V(4).Infof("GetStorageClass: storageClass %s not found", name)
343+
return true, nil, fmt.Errorf("cannot find storageClass %s", name)
351344

352345
case action.Matches("get", "secrets"):
353346
name := action.(core.GetAction).GetName()
354347
secret, found := r.secrets[name]
355348
if found {
356349
glog.V(4).Infof("GetSecret: found %s", secret.Name)
357350
return true, secret, nil
358-
} else {
359-
glog.V(4).Infof("GetSecret: secret %s not found", name)
360-
return true, nil, fmt.Errorf("cannot find secret %s", name)
361351
}
352+
glog.V(4).Infof("GetSecret: secret %s not found", name)
353+
return true, nil, fmt.Errorf("cannot find secret %s", name)
354+
362355
}
363356

364357
return false, nil, nil

pkg/controller/snapshot_controller.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ func (ctrl *csiSnapshotController) syncSnapshot(snapshot *crdv1.VolumeSnapshot)
194194

195195
if !snapshot.Status.ReadyToUse {
196196
return ctrl.syncUnreadySnapshot(snapshot)
197-
} else {
198-
return ctrl.syncReadySnapshot(snapshot)
199197
}
198+
return ctrl.syncReadySnapshot(snapshot)
199+
200200
}
201201

202202
// syncReadySnapshot checks the snapshot which has been bound to snapshot content successfully before.
@@ -567,9 +567,8 @@ func (ctrl *csiSnapshotController) checkandUpdateBoundSnapshotStatusOperation(sn
567567
if err != nil {
568568
glog.Errorf("checkandUpdateBoundSnapshotStatusOperation: failed to call create snapshot to check whether the snapshot is ready to use %q", err)
569569
return nil, err
570-
} else {
571-
glog.V(5).Infof("checkandUpdateBoundSnapshotStatusOperation: driver %s, snapshotId %s, timestamp %d, size %d, readyToUse %t", driverName, snapshotID, timestamp, size, readyToUse)
572570
}
571+
glog.V(5).Infof("checkandUpdateBoundSnapshotStatusOperation: driver %s, snapshotId %s, timestamp %d, size %d, readyToUse %t", driverName, snapshotID, timestamp, size, readyToUse)
573572

574573
if timestamp == 0 {
575574
timestamp = time.Now().UnixNano()
@@ -820,9 +819,9 @@ func (ctrl *csiSnapshotController) updateSnapshotStatus(snapshot *crdv1.VolumeSn
820819
newSnapshotObj, err := ctrl.clientset.VolumesnapshotV1alpha1().VolumeSnapshots(snapshotClone.Namespace).Update(snapshotClone)
821820
if err != nil {
822821
return nil, newControllerUpdateError(snapshotKey(snapshot), err.Error())
823-
} else {
824-
return newSnapshotObj, nil
825822
}
823+
return newSnapshotObj, nil
824+
826825
}
827826
return snapshot, nil
828827
}

pkg/controller/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const (
6868
)
6969

7070
var snapshotterSecretParams = deprecatedSecretParamsMap{
71-
name: "Snapshotter",
71+
name: "Snapshotter",
7272
deprecatedSecretNameKey: snapshotterSecretNameKey,
7373
deprecatedSecretNamespaceKey: snapshotterSecretNamespaceKey,
7474
secretNameKey: prefixedSnapshotterSecretNameKey,

pkg/controller/util_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ func TestGetSecretReference(t *testing.T) {
111111
if err != nil {
112112
if tc.expectErr {
113113
return
114-
} else {
115-
t.Fatalf("Did not expect error but got: %v", err)
116114
}
115+
t.Fatalf("Did not expect error but got: %v", err)
116+
117117
} else {
118118
if tc.expectErr {
119119
t.Fatalf("Expected error but got none")

0 commit comments

Comments
 (0)