Skip to content

Commit

Permalink
Remove redundant else blocks
Browse files Browse the repository at this point in the history
Signed-off-by: Humble Chirammal <hchiramm@redhat.com>
  • Loading branch information
humblec committed Jan 6, 2019
1 parent 0e4d11b commit 1eeeadf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 30 deletions.
37 changes: 15 additions & 22 deletions pkg/controller/framework_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,21 +276,19 @@ func (r *snapshotReactor) React(action core.Action) (handled bool, ret runtime.O
if found {
glog.V(4).Infof("GetVolume: found %s", content.Name)
return true, content, nil
} else {
glog.V(4).Infof("GetVolume: content %s not found", name)
return true, nil, fmt.Errorf("cannot find content %s", name)
}
glog.V(4).Infof("GetVolume: content %s not found", name)
return true, nil, fmt.Errorf("cannot find content %s", name)

case action.Matches("get", "volumesnapshots"):
name := action.(core.GetAction).GetName()
snapshot, found := r.snapshots[name]
if found {
glog.V(4).Infof("GetSnapshot: found %s", snapshot.Name)
return true, snapshot, nil
} else {
glog.V(4).Infof("GetSnapshot: content %s not found", name)
return true, nil, fmt.Errorf("cannot find snapshot %s", name)
}
glog.V(4).Infof("GetSnapshot: content %s not found", name)
return true, nil, fmt.Errorf("cannot find snapshot %s", name)

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

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

case action.Matches("get", "persistentvolumes"):
name := action.(core.GetAction).GetName()
volume, found := r.volumes[name]
if found {
glog.V(4).Infof("GetVolume: found %s", volume.Name)
return true, volume, nil
} else {
glog.V(4).Infof("GetVolume: volume %s not found", name)
return true, nil, fmt.Errorf("cannot find volume %s", name)
}
glog.V(4).Infof("GetVolume: volume %s not found", name)
return true, nil, fmt.Errorf("cannot find volume %s", name)

case action.Matches("get", "persistentvolumeclaims"):
name := action.(core.GetAction).GetName()
claim, found := r.claims[name]
if found {
glog.V(4).Infof("GetClaim: found %s", claim.Name)
return true, claim, nil
} else {
glog.V(4).Infof("GetClaim: claim %s not found", name)
return true, nil, fmt.Errorf("cannot find claim %s", name)
}
glog.V(4).Infof("GetClaim: claim %s not found", name)
return true, nil, fmt.Errorf("cannot find claim %s", name)

case action.Matches("get", "storageclasses"):
name := action.(core.GetAction).GetName()
storageClass, found := r.storageClasses[name]
if found {
glog.V(4).Infof("GetStorageClass: found %s", storageClass.Name)
return true, storageClass, nil
} else {
glog.V(4).Infof("GetStorageClass: storageClass %s not found", name)
return true, nil, fmt.Errorf("cannot find storageClass %s", name)
}
glog.V(4).Infof("GetStorageClass: storageClass %s not found", name)
return true, nil, fmt.Errorf("cannot find storageClass %s", name)

case action.Matches("get", "secrets"):
name := action.(core.GetAction).GetName()
secret, found := r.secrets[name]
if found {
glog.V(4).Infof("GetSecret: found %s", secret.Name)
return true, secret, nil
} else {
glog.V(4).Infof("GetSecret: secret %s not found", name)
return true, nil, fmt.Errorf("cannot find secret %s", name)
}
glog.V(4).Infof("GetSecret: secret %s not found", name)
return true, nil, fmt.Errorf("cannot find secret %s", name)

}

return false, nil, nil
Expand Down
11 changes: 5 additions & 6 deletions pkg/controller/snapshot_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ func (ctrl *csiSnapshotController) syncSnapshot(snapshot *crdv1.VolumeSnapshot)

if !snapshot.Status.ReadyToUse {
return ctrl.syncUnreadySnapshot(snapshot)
} else {
return ctrl.syncReadySnapshot(snapshot)
}
return ctrl.syncReadySnapshot(snapshot)

}

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

if timestamp == 0 {
timestamp = time.Now().UnixNano()
Expand Down Expand Up @@ -820,9 +819,9 @@ func (ctrl *csiSnapshotController) updateSnapshotStatus(snapshot *crdv1.VolumeSn
newSnapshotObj, err := ctrl.clientset.VolumesnapshotV1alpha1().VolumeSnapshots(snapshotClone.Namespace).Update(snapshotClone)
if err != nil {
return nil, newControllerUpdateError(snapshotKey(snapshot), err.Error())
} else {
return newSnapshotObj, nil
}
return newSnapshotObj, nil

}
return snapshot, nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ func TestGetSecretReference(t *testing.T) {
if err != nil {
if tc.expectErr {
return
} else {
t.Fatalf("Did not expect error but got: %v", err)
}
t.Fatalf("Did not expect error but got: %v", err)

} else {
if tc.expectErr {
t.Fatalf("Expected error but got none")
Expand Down

0 comments on commit 1eeeadf

Please sign in to comment.