Skip to content

Commit

Permalink
Fix bug we initiate a backup when the volume has started detaching
Browse files Browse the repository at this point in the history
When the volume.Spec.NodeID is different than the node ID of the backup
VA ticket, we should not initiate a backup as the volume is going to
detach soon

longhorn-7937

Signed-off-by: Phan Le <phan.le@suse.com>
  • Loading branch information
PhanLe1010 authored and innobead committed Feb 23, 2024
1 parent 43013ae commit 586331b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion controller/backup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,9 @@ func (bc *BackupController) VerifyAttachment(backup *longhorn.Backup, volumeName
}

attachmentTicketID := longhorn.GetAttachmentTicketID(longhorn.AttacherTypeBackupController, backup.Name)
isVolumeStillDesiredToAttachToSameNodeAsAttachmentTicket := vol.Spec.NodeID == longhorn.GetNodeIdOfAttachmentTicket(attachmentTicketID, va)

return longhorn.IsAttachmentTicketSatisfied(attachmentTicketID, va), nil
return isVolumeStillDesiredToAttachToSameNodeAsAttachmentTicket && longhorn.IsAttachmentTicketSatisfied(attachmentTicketID, va), nil
}

func (bc *BackupController) isResponsibleFor(b *longhorn.Backup, defaultEngineImage string) (bool, error) {
Expand Down
12 changes: 12 additions & 0 deletions k8s/pkg/apis/longhorn/v1beta2/volumeattachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ func GetAttachmentTicketID(attacherType AttacherType, id string) string {
return retID
}

func GetNodeIdOfAttachmentTicket(attachmentID string, va *VolumeAttachment) string {
if va == nil {
return ""
}
attachmentTicket, ok := va.Spec.AttachmentTickets[attachmentID]
if !ok {
return ""
}

return attachmentTicket.NodeID
}

func IsAttachmentTicketSatisfied(attachmentID string, va *VolumeAttachment) bool {
if va == nil {
return false
Expand Down

0 comments on commit 586331b

Please sign in to comment.