From e243c0006b56af7772b5a5e50d67f2f5f7cd618c Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Fri, 4 Dec 2020 13:49:27 +0530 Subject: [PATCH] rbd: dont generate OMAP data for static volume if the user has created a static PV for a RBD image which is not created by CSI driver, dont generate the OMAP data. Signed-off-by: Madhu Rajanna --- .../persistentvolume/persistentvolume.go | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/internal/controller/persistentvolume/persistentvolume.go b/internal/controller/persistentvolume/persistentvolume.go index fd53d0600..35bce01b8 100644 --- a/internal/controller/persistentvolume/persistentvolume.go +++ b/internal/controller/persistentvolume/persistentvolume.go @@ -19,6 +19,7 @@ import ( "context" "errors" "fmt" + "strconv" ctrl "github.com/ceph/ceph-csi/internal/controller" "github.com/ceph/ceph-csi/internal/rbd" @@ -94,6 +95,18 @@ func (r *ReconcilePersistentVolume) getCredentials(name, namespace string) (map[ return credentials, nil } +func checkStaticVolume(staticVol string) (bool, error) { + static := false + var err error + if staticVol != "" { + static, err = strconv.ParseBool(staticVol) + if err != nil { + return false, fmt.Errorf("failed to parse preProvisionedVolume: %w", err) + } + } + return static, nil +} + // reconcilePV will extract the image details from the pv spec and regenerates // the omap data. func (r ReconcilePersistentVolume) reconcilePV(obj runtime.Object) error { @@ -109,7 +122,15 @@ func (r ReconcilePersistentVolume) reconcilePV(obj runtime.Object) error { volumeHandler := pv.Spec.CSI.VolumeHandle secretName := "" secretNamespace := "" - + // check static volume + static, err := checkStaticVolume(pv.Spec.CSI.VolumeAttributes["staticVolume"]) + if err != nil { + return err + } + // if the volume is static, dont generate OMAP data + if static { + return nil + } if pv.Spec.CSI.ControllerExpandSecretRef != nil { secretName = pv.Spec.CSI.ControllerExpandSecretRef.Name secretNamespace = pv.Spec.CSI.ControllerExpandSecretRef.Namespace