Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE-1178]: Disk Eject, fixed fake attach after node reboot during DR #1179

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func (s *CSINodeService) annotateIfAllVolsFakeAttached(ctx context.Context, volu
//
// Returns:
// - bool: a boolean indicating whether fake attach annotation is present, it's always true when fake attach is needed in DR.
// - bool: a boolean indicating whether fake attach is needed in DR.
// - bool: a boolean indicating whether fake attach is needed in DR or all volumes related to drive were fake attached before reboot.
func (s *CSINodeService) isFakeAttachNeed(volumeCR *volumecrd.Volume) (bool, bool) {
fakeAttachBasic, fakeAttachDR := false, false

Expand All @@ -259,7 +259,10 @@ func (s *CSINodeService) isFakeAttachNeed(volumeCR *volumecrd.Volume) (bool, boo
if value, ok := pvc.Annotations[fakeAttachAnnotation]; ok && value == fakeAttachAllowKey {
fakeAttachBasic = true
if driveCR, err := s.crHelper.GetDriveCRByVolume(volumeCR); err == nil {
fakeAttachDR = driveCR.Spec.Usage == apiV1.DriveUsageReleased && driveCR.Spec.Status == apiV1.DriveStatusOnline
value, found := driveCR.Annotations[allVolumesFakeAttachedAnnotation]
// it's required to keep fake-attach during node reboot
allVolsPreviouslyFakeAttached := found && value == allVolumesFakeAttachedKey
fakeAttachDR = (driveCR.Spec.Usage == apiV1.DriveUsageReleased && driveCR.Spec.Status == apiV1.DriveStatusOnline) || allVolsPreviouslyFakeAttached
}
}

Expand Down
47 changes: 47 additions & 0 deletions pkg/node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,54 @@ var _ = Describe("CSINodeService Fake-Attach", func() {
Expect(vol1.Annotations[fakeAttachVolumeAnnotation]).To(Equal(fakeAttachVolumeKey))
Expect(vol1.Annotations[fakeDeviceVolumeAnnotation]).To(Equal(expectedFakeDevice))
})
It("Should stage healthy block-mode volume successfully after node reboot (DR)", func() {
req := getNodeStageRequest(testVolume1.Id, *testVolumeCap)
drive1 := &drivecrd.Drive{}
drive1.Name = "drive1"
drive1.Spec.Usage = apiV1.DriveUsageRemoved
drive1.Spec.Status = apiV1.DriveStatusOnline
drive1.Annotations = map[string]string{allVolumesFakeAttachedAnnotation: allVolumesFakeAttachedKey}
err := node.k8sClient.CreateCR(testCtx, drive1.Name, drive1)
Expect(err).To(BeNil())

vol1 := &vcrd.Volume{}
err = node.k8sClient.ReadCR(testCtx, testVolume1.Id, testNs, vol1)
Expect(err).To(BeNil())
vol1.Spec.CSIStatus = apiV1.Created
vol1.Spec.Mode = apiV1.ModeRAWPART
vol1.Spec.LocationType = apiV1.LocationTypeDrive
vol1.Spec.Location = drive1.Name
err = node.k8sClient.UpdateCR(testCtx, vol1)
Expect(err).To(BeNil())

createPVAndPVCForFakeAttach(vol1.Name)

partitionPath := "/partition/path/for/volume1"
prov.On("GetVolumePath", &vol1.Spec).Return(partitionPath, nil)
fsOps.On("PrepareAndPerformMount",
partitionPath, path.Join(req.GetStagingTargetPath(), stagingFileName), true, false).
Return(nil).Once()

expectedFakeDevice := "/dev/loop2"
fakeDeviceSrcFile := fakeDeviceSrcFileDir + vol1.Name

// The case that create fake device successfully
fsOps.On("CreateFakeDevice", fakeDeviceSrcFile).
Return(expectedFakeDevice, nil).Once()
fsOps.On("PrepareAndPerformMount",
expectedFakeDevice, path.Join(req.GetStagingTargetPath(), stagingFileName), true, false).
Return(nil).Once()

resp, err := node.NodeStageVolume(testCtx, req)
Expect(resp).NotTo(BeNil())
Expect(err).To(BeNil())

err = node.k8sClient.ReadCR(testCtx, testV1ID, "", vol1)
Expect(err).To(BeNil())
Expect(vol1.Spec.CSIStatus).To(Equal(apiV1.VolumeReady))
Expect(vol1.Annotations[fakeAttachVolumeAnnotation]).To(Equal(fakeAttachVolumeKey))
Expect(vol1.Annotations[fakeDeviceVolumeAnnotation]).To(Equal(expectedFakeDevice))
})
It("Should stage unhealthy block-mode volume successfully", func() {
req := getNodeStageRequest(testVolume1.Id, *testVolumeCap)
vol1 := &vcrd.Volume{}
Expand Down
Loading