Skip to content

Commit

Permalink
fix(localpv): handle case of BDC-BD taking longer time (#1262)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
kmova authored and Amit Kumar Das committed Jun 7, 2019
1 parent 26f97e7 commit df079dc
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions cmd/provisioner-localpv/app/helper_blockdevice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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).
Expand All @@ -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
Expand Down

0 comments on commit df079dc

Please sign in to comment.