Skip to content

Commit

Permalink
[ISSUE-1159]: cr notes refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
korzepadawid committed Jun 3, 2024
1 parent 389983a commit 128610d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 27 deletions.
34 changes: 21 additions & 13 deletions pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,23 +195,31 @@ func (s *CSINodeService) processFakeAttachInNodeStageVolume(
return nil
}

// isFakeAttachNeededForDR - checks if a fake attach is needed for drive replacement,
// returns true if the volume's corresponding PVC has the fake attach annotation and the drive has usage: REMOVING and STATUS: ONLINE,
// otherwise, returns false.
func (s *CSINodeService) isFakeAttachNeededForDR(volumeCR *volumecrd.Volume) bool {
// isFakeAttachNeededForDR checks if fake attach annotation is present and needed for drive replacement.
//
// Parameters:
// - volumeCR: a pointer to a volumecrd.Volume object representing the volume to check.
//
// Returns:
// - bool: a boolean indicating whether fake attach annotation is present.
// - bool: a boolean indicating whether fake attach is needed in DR.
func (s *CSINodeService) isFakeAttachNeededForDR(volumeCR *volumecrd.Volume) (bool, bool) {
fakeAttachBasic, fakeAttachDR := false, false

pvc, err := s.getPVCForVolume(volumeCR.Spec.Id)
if err != nil {
s.log.Errorf("Failed to get Persistent Volume Claim for Volume %s: %+v", volumeCR.Spec.Id, err)
return false
return fakeAttachBasic, fakeAttachDR
}

if value, ok := pvc.Annotations[fakeAttachAnnotation]; ok && value == fakeAttachAllowKey {
fakeAttachBasic = true
if driveCR, err := s.crHelper.GetDriveCRByVolume(volumeCR); err == nil {
return driveCR.Spec.Usage == apiV1.DriveUsageRemoving && driveCR.Spec.Status == apiV1.DriveStatusOnline
fakeAttachDR = driveCR.Spec.Usage == apiV1.DriveUsageRemoving && driveCR.Spec.Status == apiV1.DriveStatusOnline
}
}

return false
return fakeAttachBasic, fakeAttachDR
}

// NodeStageVolume is the implementation of CSI Spec NodeStageVolume. Performs when the first pod consumes a volume.
Expand Down Expand Up @@ -288,11 +296,11 @@ func (s *CSINodeService) NodeStageVolume(ctx context.Context, req *csi.NodeStage
}

targetPath := getStagingPath(ll, req.GetStagingTargetPath())
isFakeAttachNeed, isFakeAttachNeedDR := false, s.isFakeAttachNeededForDR(volumeCR)
isFakeAttachAnnotation, isFakeAttachDR := s.isFakeAttachNeededForDR(volumeCR)
isErr := false
ignoreErrorIfFakeAttach := func(err error) {
if s.isPVCNeedFakeAttach(volumeID) || isFakeAttachNeedDR {
isFakeAttachNeed = true
} else {
isErr = true
if !isFakeAttachAnnotation {
newStatus = apiV1.Failed
resp, errToReturn = nil, status.Error(codes.Internal, fmt.Sprintf("failed to stage volume: %s", err.Error()))
}
Expand All @@ -317,8 +325,8 @@ func (s *CSINodeService) NodeStageVolume(ctx context.Context, req *csi.NodeStage
ll,
volumeCR,
targetPath,
isFakeAttachNeed || isFakeAttachNeedDR,
isFakeAttachNeedDR,
(isErr && isFakeAttachAnnotation) || isFakeAttachDR,
isFakeAttachDR,
); err != nil {
return nil, err
}
Expand Down
14 changes: 0 additions & 14 deletions pkg/node/volumemgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -1303,20 +1303,6 @@ func (m *VolumeManager) getPVCForVolume(volumeID string) (*corev1.PersistentVolu
return pvc, nil
}

func (m *VolumeManager) isPVCNeedFakeAttach(volumeID string) bool {
pvc, err := m.getPVCForVolume(volumeID)
if err != nil {
m.log.Errorf("Failed to get Persistent Volume Claim for Volume %s: %+v", volumeID, err)
return false
}

if value, ok := pvc.Annotations[fakeAttachAnnotation]; ok && value == fakeAttachAllowKey {
return true
}

return false
}

// overrideDriveHealth replaces drive health with passed value,
// generates error message if value is not valid
func (m *VolumeManager) overrideDriveHealth(drive *api.Drive, overriddenHealth, driveCRName string) {
Expand Down

0 comments on commit 128610d

Please sign in to comment.