Skip to content

Commit

Permalink
some improvements
Browse files Browse the repository at this point in the history
Signed-off-by: Viktor Kramarenko <[email protected]>
  • Loading branch information
ViktorKram committed Oct 2, 2024
1 parent 4a56e44 commit 65f4acd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion crds/doc-ru-lvmvolumegroupset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ spec:
schema:
openAPIV3Schema:
description: |
Интерфейс для создания за раз нескольких LVMVolumeGroup ресурсов по общему шаблону.
Интерфейс для одновременного создания нескольких LVMVolumeGroup ресурсов по общему шаблону.
properties:
spec:
properties:
Expand Down
24 changes: 18 additions & 6 deletions images/agent/src/pkg/controller/lvm_volume_group_discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ func GetLVMVolumeGroupCandidates(log logger.Logger, sdsCache *cache.Cache, bds m
VGSize: *resource.NewQuantity(vg.VGSize.Value(), resource.BinarySI),
VGFree: *resource.NewQuantity(vg.VGFree.Value(), resource.BinarySI),
VGUUID: vg.VGUUID,
Nodes: configureCandidateNodeDevices(sortedPVs, sortedBDs, vg, currentNode),
Nodes: configureCandidateNodeDevices(log, sortedPVs, sortedBDs, vg, currentNode),
}

candidates = append(candidates, candidate)
Expand Down Expand Up @@ -617,7 +617,7 @@ func sortBlockDevicesByVG(bds map[string]v1alpha1.BlockDevice, vgs []internal.VG
return result
}

func configureCandidateNodeDevices(pvs map[string][]internal.PVData, bds map[string][]v1alpha1.BlockDevice, vg internal.VGData, currentNode string) map[string][]internal.LVMVGDevice {
func configureCandidateNodeDevices(log logger.Logger, pvs map[string][]internal.PVData, bds map[string][]v1alpha1.BlockDevice, vg internal.VGData, currentNode string) map[string][]internal.LVMVGDevice {
filteredPV := pvs[vg.VGName+vg.VGUUID]
filteredBds := bds[vg.VGName+vg.VGUUID]
bdPathStatus := make(map[string]v1alpha1.BlockDevice, len(bds))
Expand All @@ -628,16 +628,28 @@ func configureCandidateNodeDevices(pvs map[string][]internal.PVData, bds map[str
}

for _, pv := range filteredPV {
bd, exist := bdPathStatus[pv.PVName]
// this is very rare case which might occurred while VG extend operation goes. In this case, in the cache the controller
// sees a new PV included in the VG, but BlockDeviceDiscover did not update the corresponding BlockDevice resource on time,
// so the BlockDevice resource does not have any info, that it is in the VG.
if !exist {
log.Warning(fmt.Sprintf("[configureCandidateNodeDevices] no BlockDevice resource is yet configured for PV %s in VG %s, retry on the next iteration", pv.PVName, vg.VGName))
continue
}

device := internal.LVMVGDevice{
Path: pv.PVName,
PVSize: *resource.NewQuantity(pv.PVSize.Value(), resource.BinarySI),
PVUUID: pv.PVUuid,
}

if bd, exist := bdPathStatus[pv.PVName]; exist {
device.DevSize = *resource.NewQuantity(bd.Status.Size.Value(), resource.BinarySI)
device.BlockDevice = bd.Name
}
//if bd, exist := bdPathStatus[pv.PVName]; exist {
// device.DevSize = *resource.NewQuantity(bd.Status.Size.Value(), resource.BinarySI)
// device.BlockDevice = bd.Name
//}

device.DevSize = *resource.NewQuantity(bd.Status.Size.Value(), resource.BinarySI)
device.BlockDevice = bd.Name

result[currentNode] = append(result[currentNode], device)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ func RunLVMVolumeGroupWatcherController(
log.Debug(fmt.Sprintf("[RunLVMVolumeGroupWatcherController] successfully got block device resources for the LVMVolumeGroup %s by the selector %v", lvg.Name, lvg.Spec.BlockDeviceSelector))

blockDevices = filterBlockDevicesByNodeName(blockDevices, lvg.Spec.Local.NodeName)

valid, reason := validateSpecBlockDevices(lvg, blockDevices)
if !valid {
log.Warning(fmt.Sprintf("[RunLVMVolumeGroupController] validation failed for the LVMVolumeGroup %s, reason: %s", lvg.Name, reason))
Expand Down

0 comments on commit 65f4acd

Please sign in to comment.