From 47d385a173bd0ae6e3fde2e05068ab2e67d44d0f Mon Sep 17 00:00:00 2001 From: Aleksandr Zimin Date: Wed, 30 Oct 2024 23:36:21 +0300 Subject: [PATCH] some fixes Signed-off-by: Aleksandr Zimin --- .../src/pkg/controller/lvm_volume_group_watcher.go | 5 +++-- .../controller/lvm_volume_group_watcher_func.go | 14 +++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/images/agent/src/pkg/controller/lvm_volume_group_watcher.go b/images/agent/src/pkg/controller/lvm_volume_group_watcher.go index f1bc33e4..a1b2e631 100644 --- a/images/agent/src/pkg/controller/lvm_volume_group_watcher.go +++ b/images/agent/src/pkg/controller/lvm_volume_group_watcher.go @@ -118,7 +118,7 @@ func RunLVMVolumeGroupWatcherController( log.Debug(fmt.Sprintf("[RunLVMVolumeGroupWatcherController] successfully removed the label %s from the LVMVolumeGroup %s", internal.LVGUpdateTriggerLabel, lvg.Name)) } - log.Debug(fmt.Sprintf("[RunLVMVolumeGroupWatcherController] tries to get block device resources for the LVMVolumeGroup %s by the selector %v", lvg.Name, lvg.Spec.BlockDeviceSelector.MatchLabels)) + log.Debug(fmt.Sprintf("[RunLVMVolumeGroupWatcherController] tries to get block device resources for the LVMVolumeGroup %s by the selector %v", lvg.Name, lvg.Spec.BlockDeviceSelector)) blockDevices, err := GetAPIBlockDevices(ctx, cl, metrics, lvg.Spec.BlockDeviceSelector) if err != nil { log.Error(err, fmt.Sprintf("[RunLVMVolumeGroupWatcherController] unable to get BlockDevices. Retry in %s", cfg.BlockDeviceScanIntervalSec.String())) @@ -129,7 +129,8 @@ func RunLVMVolumeGroupWatcherController( return reconcile.Result{RequeueAfter: cfg.BlockDeviceScanIntervalSec}, nil } - log.Debug(fmt.Sprintf("[RunLVMVolumeGroupWatcherController] successfully got block device resources for the LVMVolumeGroup %s by the selector %v", lvg.Name, lvg.Spec.BlockDeviceSelector.MatchLabels)) + log.Debug(fmt.Sprintf("[RunLVMVolumeGroupWatcherController] successfully got block device resources for the LVMVolumeGroup %s by the selector %v", lvg.Name, lvg.Spec.BlockDeviceSelector)) + log.Trace(fmt.Sprintf("[RunLVMVolumeGroupWatcherController] block devices: %v", blockDevices)) valid, reason := validateSpecBlockDevices(lvg, blockDevices) if !valid { diff --git a/images/agent/src/pkg/controller/lvm_volume_group_watcher_func.go b/images/agent/src/pkg/controller/lvm_volume_group_watcher_func.go index 95f28e52..2833e2d3 100644 --- a/images/agent/src/pkg/controller/lvm_volume_group_watcher_func.go +++ b/images/agent/src/pkg/controller/lvm_volume_group_watcher_func.go @@ -294,15 +294,19 @@ func validateSpecBlockDevices(lvg *v1alpha1.LVMVolumeGroup, blockDevices map[str } } - bdFromOtherNode := make([]string, 0, len(blockDevices)) + bdFromOurNode := make([]string, 0, len(blockDevices)) for _, bd := range blockDevices { - if bd.Status.NodeName != lvg.Spec.Local.NodeName { - bdFromOtherNode = append(bdFromOtherNode, bd.Name) + if bd.Status.NodeName == lvg.Spec.Local.NodeName { + bdFromOurNode = append(bdFromOurNode, bd.Name) } } - if len(bdFromOtherNode) != 0 { - return false, fmt.Sprintf("block devices %s have different node names from LVMVolumeGroup Local.NodeName", strings.Join(bdFromOtherNode, ",")) + if len(bdFromOurNode) == 0 { + bdNames := make([]string, 0, len(blockDevices)) + for _, bd := range blockDevices { + bdNames = append(bdNames, bd.Name) + } + return false, fmt.Sprintf("none of specified BlockDevices %s were found on the node %s", lvg.Spec.Local.NodeName, strings.Join(bdNames, ",")) } return true, ""