From 286e6e600ec9e47fec3be0e527f60f0ecc4cb4af Mon Sep 17 00:00:00 2001 From: Derek Su Date: Thu, 12 Oct 2023 22:14:33 +0800 Subject: [PATCH] Add logs for volume attachment and detachment Signed-off-by: Derek Su --- controller/share_manager_controller.go | 2 +- controller/volume_attachment_controller.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/controller/share_manager_controller.go b/controller/share_manager_controller.go index cc4874885e..c5f687fa5f 100644 --- a/controller/share_manager_controller.go +++ b/controller/share_manager_controller.go @@ -421,7 +421,7 @@ func (c *ShareManagerController) createShareManagerAttachmentTicket(sm *longhorn } } if shareManagerAttachmentTicket.NodeID != sm.Status.OwnerID { - log.Infof("Attachment ticket %v request a new node %v from old node %v", shareManagerAttachmentTicket.ID, shareManagerAttachmentTicket.NodeID, sm.Status.OwnerID) + log.Infof("Attachment ticket %v request a new node %v from old node %v", shareManagerAttachmentTicket.ID, sm.Status.OwnerID, shareManagerAttachmentTicket.NodeID) shareManagerAttachmentTicket.NodeID = sm.Status.OwnerID } diff --git a/controller/volume_attachment_controller.go b/controller/volume_attachment_controller.go index cabbf82f34..c3e737d004 100644 --- a/controller/volume_attachment_controller.go +++ b/controller/volume_attachment_controller.go @@ -440,6 +440,8 @@ func (vac *VolumeAttachmentController) handleVolumeMigrationRollback(va *longhor } func (vac *VolumeAttachmentController) handleVolumeDetachment(va *longhorn.VolumeAttachment, vol *longhorn.Volume) { + log := getLoggerForLHVolumeAttachment(vac.logger, va) + // Volume is already trying to detach if vol.Spec.NodeID == "" { return @@ -449,6 +451,8 @@ func (vac *VolumeAttachmentController) handleVolumeDetachment(va *longhorn.Volum return } + log.Infof("Volume %v is selected to detach from node %v", vol.Name, vol.Spec.NodeID) + // There is no attachment ticket that request the current vol.Spec.NodeID. // Therefore, set desire state of volume to empty vol.Spec.NodeID = "" @@ -488,6 +492,7 @@ func (vac *VolumeAttachmentController) shouldDoDetach(va *longhorn.VolumeAttachm } if len(currentAttachmentTickets) == 0 { + log.Infof("Should detach volume %v because there is no matching attachment ticket", vol.Spec.NodeID) return true } @@ -549,6 +554,8 @@ func hasWorkloadTicket(attachmentTickets map[string]*longhorn.AttachmentTicket, } func (vac *VolumeAttachmentController) handleVolumeAttachment(va *longhorn.VolumeAttachment, vol *longhorn.Volume) { + log := getLoggerForLHVolumeAttachment(vac.logger, va) + // Wait for volume to be fully detached if !isVolumeFullyDetached(vol) { return @@ -565,6 +572,8 @@ func (vac *VolumeAttachmentController) handleVolumeAttachment(va *longhorn.Volum return } + log.Infof("Volume %v is selected to attach to node %v, ticket +%v", vol.Name, attachmentTicket.NodeID, attachmentTicket) + vol.Spec.NodeID = attachmentTicket.NodeID setAttachmentParameter(attachmentTicket.Parameters, vol) }