cleanup: simplify checkStaticVolume function and remove unwanted vars

checkStaticVolume() in the reconcilePV function has been unwantedly
introducing variables to confirm the pv spec is static or not. This
patch simplify it and make a smaller footprint of the functions.

Signed-off-by: Humble Chirammal <hchiramm@redhat.com>
This commit is contained in:
Humble Chirammal 2021-09-03 18:18:49 +05:30 committed by mergify[bot]
parent 1b64a0a505
commit 4efcc5bf97

View File

@ -19,7 +19,6 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"strconv"
ctrl "github.com/ceph/ceph-csi/internal/controller" ctrl "github.com/ceph/ceph-csi/internal/controller"
"github.com/ceph/ceph-csi/internal/rbd" "github.com/ceph/ceph-csi/internal/rbd"
@ -126,19 +125,8 @@ func (r *ReconcilePersistentVolume) getCredentials(
return cr, nil return cr, nil
} }
func checkStaticVolume(pv *corev1.PersistentVolume) (bool, error) { func checkStaticVolume(pv *corev1.PersistentVolume) bool {
static := false return pv.Spec.CSI.VolumeAttributes["staticVolume"] == "true"
var err error
staticVol := pv.Spec.CSI.VolumeAttributes["staticVolume"]
if staticVol != "" {
static, err = strconv.ParseBool(staticVol)
if err != nil {
return false, fmt.Errorf("failed to parse preProvisionedVolume: %w", err)
}
}
return static, nil
} }
// storeVolumeIDInPV stores the new volumeID in PV object. // storeVolumeIDInPV stores the new volumeID in PV object.
@ -178,10 +166,7 @@ func (r ReconcilePersistentVolume) reconcilePV(ctx context.Context, obj runtime.
secretName := "" secretName := ""
secretNamespace := "" secretNamespace := ""
// check static volume // check static volume
static, err := checkStaticVolume(pv) static := checkStaticVolume(pv)
if err != nil {
return err
}
// if the volume is static, dont generate OMAP data // if the volume is static, dont generate OMAP data
if static { if static {
return nil return nil