cleanup: refactor deeply nested if statements in persistentvolume.go

Refactored deeply nested if statement in persistentvolume.go to
reduce cognitive complexity.

Signed-off-by: Rakshith R <rar@redhat.com>
This commit is contained in:
Rakshith R 2021-04-04 12:22:11 +05:30 committed by mergify[bot]
parent 7d105143fc
commit 0f7b653b4e

View File

@ -129,7 +129,9 @@ func (r ReconcilePersistentVolume) reconcilePV(obj runtime.Object) error {
if !ok {
return nil
}
if pv.Spec.CSI != nil && pv.Spec.CSI.Driver == r.config.DriverName {
if pv.Spec.CSI == nil || pv.Spec.CSI.Driver != r.config.DriverName {
return nil
}
pool := pv.Spec.CSI.VolumeAttributes["pool"]
journalPool := pv.Spec.CSI.VolumeAttributes["journalPool"]
requestName := pv.Name
@ -156,7 +158,7 @@ func (r ReconcilePersistentVolume) reconcilePV(obj runtime.Object) error {
cr, err := r.getCredentials(secretName, secretNamespace)
if err != nil {
util.ErrorLogMsg("failed to get credentials %s", err)
util.ErrorLogMsg("failed to get credentials from secret %s", err)
return err
}
defer cr.DeleteCredentials()
@ -166,7 +168,6 @@ func (r ReconcilePersistentVolume) reconcilePV(obj runtime.Object) error {
util.ErrorLogMsg("failed to regenerate journal %s", err)
return err
}
}
return nil
}