mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-25 07:40:19 +00:00
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:
parent
7d105143fc
commit
0f7b653b4e
@ -129,43 +129,44 @@ func (r ReconcilePersistentVolume) reconcilePV(obj runtime.Object) error {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
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 {
|
||||||
pool := pv.Spec.CSI.VolumeAttributes["pool"]
|
return nil
|
||||||
journalPool := pv.Spec.CSI.VolumeAttributes["journalPool"]
|
}
|
||||||
requestName := pv.Name
|
pool := pv.Spec.CSI.VolumeAttributes["pool"]
|
||||||
imageName := pv.Spec.CSI.VolumeAttributes["imageName"]
|
journalPool := pv.Spec.CSI.VolumeAttributes["journalPool"]
|
||||||
volumeHandler := pv.Spec.CSI.VolumeHandle
|
requestName := pv.Name
|
||||||
secretName := ""
|
imageName := pv.Spec.CSI.VolumeAttributes["imageName"]
|
||||||
secretNamespace := ""
|
volumeHandler := pv.Spec.CSI.VolumeHandle
|
||||||
// check static volume
|
secretName := ""
|
||||||
static, err := checkStaticVolume(pv)
|
secretNamespace := ""
|
||||||
if err != nil {
|
// check static volume
|
||||||
return err
|
static, err := checkStaticVolume(pv)
|
||||||
}
|
if err != nil {
|
||||||
// if the volume is static, dont generate OMAP data
|
return err
|
||||||
if static {
|
}
|
||||||
return nil
|
// if the volume is static, dont generate OMAP data
|
||||||
}
|
if static {
|
||||||
if pv.Spec.CSI.ControllerExpandSecretRef != nil {
|
return nil
|
||||||
secretName = pv.Spec.CSI.ControllerExpandSecretRef.Name
|
}
|
||||||
secretNamespace = pv.Spec.CSI.ControllerExpandSecretRef.Namespace
|
if pv.Spec.CSI.ControllerExpandSecretRef != nil {
|
||||||
} else if pv.Spec.CSI.NodeStageSecretRef != nil {
|
secretName = pv.Spec.CSI.ControllerExpandSecretRef.Name
|
||||||
secretName = pv.Spec.CSI.NodeStageSecretRef.Name
|
secretNamespace = pv.Spec.CSI.ControllerExpandSecretRef.Namespace
|
||||||
secretNamespace = pv.Spec.CSI.NodeStageSecretRef.Namespace
|
} else if pv.Spec.CSI.NodeStageSecretRef != nil {
|
||||||
}
|
secretName = pv.Spec.CSI.NodeStageSecretRef.Name
|
||||||
|
secretNamespace = pv.Spec.CSI.NodeStageSecretRef.Namespace
|
||||||
|
}
|
||||||
|
|
||||||
cr, err := r.getCredentials(secretName, secretNamespace)
|
cr, err := r.getCredentials(secretName, secretNamespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.ErrorLogMsg("failed to get credentials %s", err)
|
util.ErrorLogMsg("failed to get credentials from secret %s", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer cr.DeleteCredentials()
|
defer cr.DeleteCredentials()
|
||||||
|
|
||||||
err = rbd.RegenerateJournal(imageName, volumeHandler, pool, journalPool, requestName, cr)
|
err = rbd.RegenerateJournal(imageName, volumeHandler, pool, journalPool, requestName, cr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.ErrorLogMsg("failed to regenerate journal %s", err)
|
util.ErrorLogMsg("failed to regenerate journal %s", err)
|
||||||
return err
|
return err
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user