Skip to content

Commit

Permalink
Set backing image state to failed in case of size or virtualSize mism…
Browse files Browse the repository at this point in the history
…atch

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 <tserong@suse.com>
(cherry picked from commit 6df0510)
  • Loading branch information
tserong authored and innobead committed Apr 10, 2024
1 parent d5a05cc commit 34d22c9
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions controller/backing_image_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
}
}
}
Expand Down

0 comments on commit 34d22c9

Please sign in to comment.