From 4efcc5bf9741a8b9c0428e322257bbc6e3e82014 Mon Sep 17 00:00:00 2001 From: Humble Chirammal Date: Fri, 3 Sep 2021 18:18:49 +0530 Subject: [PATCH] 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 --- .../persistentvolume/persistentvolume.go | 21 +++---------------- 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/internal/controller/persistentvolume/persistentvolume.go b/internal/controller/persistentvolume/persistentvolume.go index 0e81b58d5..269ec757c 100644 --- a/internal/controller/persistentvolume/persistentvolume.go +++ b/internal/controller/persistentvolume/persistentvolume.go @@ -19,7 +19,6 @@ import ( "context" "errors" "fmt" - "strconv" ctrl "github.com/ceph/ceph-csi/internal/controller" "github.com/ceph/ceph-csi/internal/rbd" @@ -126,19 +125,8 @@ func (r *ReconcilePersistentVolume) getCredentials( return cr, nil } -func checkStaticVolume(pv *corev1.PersistentVolume) (bool, error) { - static := false - 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 +func checkStaticVolume(pv *corev1.PersistentVolume) bool { + return pv.Spec.CSI.VolumeAttributes["staticVolume"] == "true" } // storeVolumeIDInPV stores the new volumeID in PV object. @@ -178,10 +166,7 @@ func (r ReconcilePersistentVolume) reconcilePV(ctx context.Context, obj runtime. secretName := "" secretNamespace := "" // check static volume - static, err := checkStaticVolume(pv) - if err != nil { - return err - } + static := checkStaticVolume(pv) // if the volume is static, dont generate OMAP data if static { return nil