Skip to content

Commit

Permalink
provisioner/lvm: ensure only one lvmvg for the vgName
Browse files Browse the repository at this point in the history
    - Because the lvmvg name is generated with the prefix, we need to
      ensure we only have one lvmvg CR for the specific vgName in the
      same node.

Signed-off-by: Vicente Cheng <[email protected]>
  • Loading branch information
Vicente-Cheng committed Oct 28, 2024
1 parent 14dd63c commit 267e155
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/provisioner/lvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provisioner
import (
"fmt"
"reflect"
"sync"

"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -20,6 +21,7 @@ type LVMProvisioner struct {
vgName string
nodeName string
vgClient ctldiskv1.LVMVolumeGroupController
lock sync.Mutex
}

func NewLVMProvisioner(vgName, nodeName string, lvmVGs ctldiskv1.LVMVolumeGroupController, device *diskv1.BlockDevice, blockInfo block.Info) (Provisioner, error) {
Expand All @@ -33,6 +35,7 @@ func NewLVMProvisioner(vgName, nodeName string, lvmVGs ctldiskv1.LVMVolumeGroupC
vgName: vgName,
vgClient: lvmVGs,
nodeName: nodeName,
lock: sync.Mutex{},
}, nil
}

Expand Down Expand Up @@ -67,6 +70,8 @@ func (l *LVMProvisioner) UnFormat() (bool, error) {
func (l *LVMProvisioner) Provision() (bool, error) {
logrus.Infof("Provisioning block device %s to vg: %s", l.device.Name, l.vgName)
found := true
// because the LVMVG name is a generated name, we need to lock here to ensure we only have one LVMVG CRD for specific vgName.
l.lock.Lock()
lvmvg, err := l.getTargetLVMVG()
if err != nil {
if !errors.IsNotFound(err) {
Expand All @@ -78,6 +83,7 @@ func (l *LVMProvisioner) Provision() (bool, error) {
if err != nil {
return requeue, err
}
l.lock.Unlock()

// first round the lvmvg must be nil, so we need to check it.
if lvmvg != nil && lvmvg.Status != nil && lvmvg.Status.Status == diskv1.VGStatusActive {
Expand Down

0 comments on commit 267e155

Please sign in to comment.