From 65ec9071c2b8d2f740bd57e71ad070d991050805 Mon Sep 17 00:00:00 2001 From: Tim Serong Date: Thu, 28 Mar 2024 17:21:27 +1100 Subject: [PATCH] Set backing image state to failed in case of size or virtualSize mismatch Doing this means if there's somehow a mismatch between backing image size or virtual size reported by backing image manager vs. what's currently in the backing image resource's status, the error will be made visible in status.diskFileStatusMap.$DISKUUID.message, i.e. the user should be able to can see the problem by running `kubectl -n longhorn-system get lhbi -o yaml`. This is the same logic as is already used in updateStatusWithFileInfo(). The one thing I'm struggling with here is how to inject such a failure into a running system in order to prove that this change works correctly. Signed-off-by: Tim Serong (cherry picked from commit 6df051064711a2646c5b28c546d80b7bde83e439) --- controller/backing_image_controller.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/controller/backing_image_controller.go b/controller/backing_image_controller.go index 3de5dfb801..1df1c34b79 100644 --- a/controller/backing_image_controller.go +++ b/controller/backing_image_controller.go @@ -663,7 +663,13 @@ func (bic *BackingImageController) syncBackingImageFileInfo(bi *longhorn.Backing bic.eventRecorder.Eventf(bi, corev1.EventTypeNormal, constant.EventReasonUpdate, "Set size to %v", bi.Status.Size) } if bi.Status.Size != info.Size { - return fmt.Errorf("found mismatching size %v reported by backing image manager %v in disk %v, the size recorded in status is %v", info.Size, bim.Name, bim.Spec.DiskUUID, bi.Status.Size) + if bi.Status.DiskFileStatusMap[bim.Spec.DiskUUID].State != longhorn.BackingImageStateFailed { + msg := fmt.Sprintf("found mismatching size %v reported by backing image manager %v in disk %v, the size recorded in status is %v", + info.Size, bim.Name, bim.Spec.DiskUUID, bi.Status.Size) + log.Error(msg) + bi.Status.DiskFileStatusMap[bim.Spec.DiskUUID].State = longhorn.BackingImageStateFailed + bi.Status.DiskFileStatusMap[bim.Spec.DiskUUID].Message = msg + } } } if info.VirtualSize > 0 { @@ -672,8 +678,13 @@ func (bic *BackingImageController) syncBackingImageFileInfo(bi *longhorn.Backing bic.eventRecorder.Eventf(bi, corev1.EventTypeNormal, constant.EventReasonUpdate, "Set virtualSize to %v", bi.Status.VirtualSize) } if bi.Status.VirtualSize != info.VirtualSize { - return fmt.Errorf("found mismatching virtualSize %v reported by backing image manager %v in disk %v, the virtualSize recorded in status is %v", - info.VirtualSize, bim.Name, bim.Spec.DiskUUID, bi.Status.VirtualSize) + if bi.Status.DiskFileStatusMap[bim.Spec.DiskUUID].State != longhorn.BackingImageStateFailed { + msg := fmt.Sprintf("found mismatching virtualSize %v reported by backing image manager %v in disk %v, the virtualSize recorded in status is %v", + info.VirtualSize, bim.Name, bim.Spec.DiskUUID, bi.Status.VirtualSize) + log.Error(msg) + bi.Status.DiskFileStatusMap[bim.Spec.DiskUUID].State = longhorn.BackingImageStateFailed + bi.Status.DiskFileStatusMap[bim.Spec.DiskUUID].Message = msg + } } } }