From df079dceb0a47b67168368879433ec00531e719f Mon Sep 17 00:00:00 2001 From: Kiran Mova Date: Fri, 7 Jun 2019 15:14:48 +0530 Subject: [PATCH] fix(localpv): handle case of BDC-BD taking longer time (#1262) When a PVC with Local PV host device is triggered, Local PV provisioner will create BDC and waits for 60 seconds to get the BD attached. Post that it returns the control back to K8s. K8s will re-attempt to create a PV, and in the second iteration - the Local PV provisioner will check if the BDC was already created and will try to re-use it instead of creating another one. Creating another BDC, in the setup where BD/BDC takes longer will never result in PV getting created. Also, timing out and reporting the error to user will make the process intuitive when BD/BDC process is taking longer. Signed-off-by: kmova --- .../app/helper_blockdevice.go | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/cmd/provisioner-localpv/app/helper_blockdevice.go b/cmd/provisioner-localpv/app/helper_blockdevice.go index 5d14db74b1..b6b1da5296 100644 --- a/cmd/provisioner-localpv/app/helper_blockdevice.go +++ b/cmd/provisioner-localpv/app/helper_blockdevice.go @@ -96,12 +96,6 @@ func (p *Provisioner) createBlockDeviceClaim(blkDevOpts *HelperBlockDeviceOption return err } - //if blkDevOpts.hasBDC() { - // //already created - // glog.Infof("Volume %v has been initialized with BDC:%v", blkDevOpts.name, blkDevOpts.bdcName) - // return nil - //} - //Create a BDC for this PV (of type device). NDM will //look for the device matching the capacity and node on which //pod is being scheduled. Since this BDC is specific to a PV @@ -110,6 +104,18 @@ func (p *Provisioner) createBlockDeviceClaim(blkDevOpts *HelperBlockDeviceOption //on BDC with PV/PVC details. bdcName := "bdc-" + blkDevOpts.name + //Check if the BDC is already created. This can happen + //if the previous reconcilation of PVC-PV, resulted in + //creating a BDC, but BD was not yet available for 60+ seconds + _, err := blockdeviceclaim.NewKubeClient(). + WithNamespace(p.namespace). + Get(bdcName, metav1.GetOptions{}) + if err == nil { + blkDevOpts.bdcName = bdcName + glog.Infof("Volume %v has been initialized with BDC:%v", blkDevOpts.name, bdcName) + return nil + } + bdcObj, err := blockdeviceclaim.NewBuilder(). WithNamespace(p.namespace). WithName(bdcName). @@ -129,7 +135,7 @@ func (p *Provisioner) createBlockDeviceClaim(blkDevOpts *HelperBlockDeviceOption if err != nil { //TODO : Need to relook at this error //If the error is about BDC being already present, then return nil - return errors.Wrapf(err, "failed to create BDC{%v}", blkDevOpts.name) + return errors.Wrapf(err, "failed to create BDC{%v}", bdcName) } blkDevOpts.bdcName = bdcName