From bcef4fead22af8c1239a5f15aab32548f19b549e Mon Sep 17 00:00:00 2001 From: Viktor Kramarenko Date: Wed, 2 Oct 2024 11:22:19 +0300 Subject: [PATCH] fix validation Signed-off-by: Viktor Kramarenko --- .../lvm_volume_group_watcher_func.go | 18 +++++++++--------- .../controller/block_device_labels_watcher.go | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 9 deletions(-) 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 9c1bd622..cde50ad1 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 @@ -101,6 +101,15 @@ func shouldLVGWatcherReconcileUpdateEvent(log logger.Logger, oldLVG, newLVG *v1a return true } + for _, c := range newLVG.Status.Conditions { + if c.Type == internal.TypeVGConfigurationApplied { + if c.Reason == internal.ReasonUpdating || c.Reason == internal.ReasonCreating { + log.Debug(fmt.Sprintf("[shouldLVGWatcherReconcileUpdateEvent] update event should not be reconciled as the LVMVolumeGroup %s reconciliation still in progress", newLVG.Name)) + return false + } + } + } + if _, exist := newLVG.Labels[internal.LVGUpdateTriggerLabel]; exist { log.Debug(fmt.Sprintf("[shouldLVGWatcherReconcileUpdateEvent] update event should be reconciled as the LVMVolumeGroup %s has the label %s", newLVG.Name, internal.LVGUpdateTriggerLabel)) return true @@ -116,15 +125,6 @@ func shouldLVGWatcherReconcileUpdateEvent(log logger.Logger, oldLVG, newLVG *v1a return true } - for _, c := range newLVG.Status.Conditions { - if c.Type == internal.TypeVGConfigurationApplied { - if c.Reason == internal.ReasonUpdating || c.Reason == internal.ReasonCreating { - log.Debug(fmt.Sprintf("[shouldLVGWatcherReconcileUpdateEvent] update event should not be reconciled as the LVMVolumeGroup %s reconciliation still in progress", newLVG.Name)) - return false - } - } - } - for _, n := range newLVG.Status.Nodes { for _, d := range n.Devices { if !utils.AreSizesEqualWithinDelta(d.PVSize, d.DevSize, internal.ResizeDelta) { diff --git a/images/sds-health-watcher-controller/src/pkg/controller/block_device_labels_watcher.go b/images/sds-health-watcher-controller/src/pkg/controller/block_device_labels_watcher.go index 8fc811a8..7a4ec431 100644 --- a/images/sds-health-watcher-controller/src/pkg/controller/block_device_labels_watcher.go +++ b/images/sds-health-watcher-controller/src/pkg/controller/block_device_labels_watcher.go @@ -119,6 +119,12 @@ func reconcileBlockDeviceLabels(ctx context.Context, cl client.Client, log logge continue } + if !checkIfLVGInProgress(&lvg) { + log.Warning(fmt.Sprintf("[reconcileBlockDeviceLabels] the LVMVolumeGroup %s is in a progress, retry later...", lvg.Name)) + shouldRetry = true + continue + } + log.Debug(fmt.Sprintf("[reconcileBlockDeviceLabels] tries to configure a selector from blockDeviceSelector of the LVMVolumeGroup %s", lvg.Name)) selector, err := metav1.LabelSelectorAsSelector(lvg.Spec.BlockDeviceSelector) if err != nil { @@ -157,6 +163,18 @@ func reconcileBlockDeviceLabels(ctx context.Context, cl client.Client, log logge return shouldRetry, nil } +func checkIfLVGInProgress(newLVG *v1alpha1.LVMVolumeGroup) bool { + for _, c := range newLVG.Status.Conditions { + if c.Type == internal.TypeVGConfigurationApplied { + if c.Reason == internal.ReasonUpdating || c.Reason == internal.ReasonCreating { + return false + } + } + } + + return true +} + func shouldTriggerLVGUpdateIfMatches(log logger.Logger, lvg *v1alpha1.LVMVolumeGroup, blockDevice *v1alpha1.BlockDevice, usedBdNames map[string]struct{}) bool { log.Debug(fmt.Sprintf("[reconcileBlockDeviceLabels] BlockDevice %s matches a blockDeviceSelector of the LVMVolumeGroup %s", blockDevice.Name, lvg.Name)) if _, used := usedBdNames[blockDevice.Name]; !used {