From cf706ec3079b662ee8e7c01510e90277fec40b4b Mon Sep 17 00:00:00 2001 From: Kacper-Michon-DELL Date: Tue, 20 Feb 2024 16:22:11 +0100 Subject: [PATCH 1/2] [Issue-1088] Adding logic to change drive status when health changed to bad Signed-off-by: Kacper-Michon-DELL --- pkg/node/volumemgr.go | 11 +++++++++++ pkg/node/volumemgr_test.go | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/pkg/node/volumemgr.go b/pkg/node/volumemgr.go index fac40e58f..3570aafac 100644 --- a/pkg/node/volumemgr.go +++ b/pkg/node/volumemgr.go @@ -645,6 +645,7 @@ func (m *VolumeManager) updateDrivesCRs(ctx context.Context, drivesFromMgr []*ap } if value, ok := driveCR.GetAnnotations()[driveHealthOverrideAnnotation]; ok { m.overrideDriveHealth(drivePtr, value, driveCR.Name) + m.overrideDriveStatusWhenHealthBad(drivePtr, value, driveCR.Name) } if driveCR.Equals(drivePtr) { updates.AddNotChanged(&driveCR) @@ -1316,6 +1317,16 @@ func (m *VolumeManager) overrideDriveHealth(drive *api.Drive, overriddenHealth, } } +// overrideDriveStatusWhenHealthBad replaces drive status to offline when health is being overidden to bad or unknown +func (m *VolumeManager) overrideDriveStatusWhenHealthBad(drive *api.Drive, overriddenHealth, driveCRName string) { + if (overriddenHealth == apiV1.HealthBad) || + (overriddenHealth == apiV1.HealthUnknown) { + m.log.Warnf("Drive %s has health %s. Status is overridden with %s.", + driveCRName, drive.Health, apiV1.DriveStatusOffline) + drive.Status = apiV1.DriveStatusOffline + } +} + func (m *VolumeManager) setWbtValue(vol *volumecrd.Volume) error { device, err := m.findDeviceName(vol) if err != nil { diff --git a/pkg/node/volumemgr_test.go b/pkg/node/volumemgr_test.go index b6a40fb9d..2cab1e7e2 100644 --- a/pkg/node/volumemgr_test.go +++ b/pkg/node/volumemgr_test.go @@ -831,6 +831,10 @@ func TestVolumeManager_updatesDrivesCRs_Success(t *testing.T) { assert.Nil(t, vm.k8sClient.ReadCR(testCtx, drive.Name, "", actualDrive)) assert.Nil(t, err) assert.Equal(t, actualDrive.Spec.Health, apiV1.HealthBad) + + updatedDrive := &drivecrd.Drive{} + assert.Nil(t, vm.k8sClient.ReadCR(testCtx, drive.Name, "", updatedDrive)) + assert.Equal(t, apiV1.DriveStatusOffline, updatedDrive.Spec.Status) }) t.Run("new drive", func(t *testing.T) { From bbf0a7def26272e688a1bb3eb69ede5c16cd5a32 Mon Sep 17 00:00:00 2001 From: Kacper-Michon-DELL Date: Wed, 21 Feb 2024 09:49:33 +0100 Subject: [PATCH 2/2] [Issue-1088] Adding logic to change drive status when health changed to bad Signed-off-by: Kacper-Michon-DELL --- pkg/node/volumemgr.go | 2 +- pkg/node/volumemgr_test.go | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/pkg/node/volumemgr.go b/pkg/node/volumemgr.go index 3570aafac..69ad1764f 100644 --- a/pkg/node/volumemgr.go +++ b/pkg/node/volumemgr.go @@ -645,7 +645,6 @@ func (m *VolumeManager) updateDrivesCRs(ctx context.Context, drivesFromMgr []*ap } if value, ok := driveCR.GetAnnotations()[driveHealthOverrideAnnotation]; ok { m.overrideDriveHealth(drivePtr, value, driveCR.Name) - m.overrideDriveStatusWhenHealthBad(drivePtr, value, driveCR.Name) } if driveCR.Equals(drivePtr) { updates.AddNotChanged(&driveCR) @@ -1311,6 +1310,7 @@ func (m *VolumeManager) overrideDriveHealth(drive *api.Drive, overriddenHealth, m.log.Warnf("Drive %s has health annotation. Health %s has been overridden with %s.", driveCRName, drive.Health, overriddenHealth) drive.Health = overriddenHealth + m.overrideDriveStatusWhenHealthBad(drive, overriddenHealth, driveCRName) } else { m.log.Errorf("Drive %s has health annotation, but value %s is not %s/%s/%s/%s. Health is not overridden.", driveCRName, overriddenHealth, apiV1.HealthGood, apiV1.HealthSuspect, apiV1.HealthBad, apiV1.HealthUnknown) diff --git a/pkg/node/volumemgr_test.go b/pkg/node/volumemgr_test.go index 2cab1e7e2..e63015ab9 100644 --- a/pkg/node/volumemgr_test.go +++ b/pkg/node/volumemgr_test.go @@ -831,10 +831,7 @@ func TestVolumeManager_updatesDrivesCRs_Success(t *testing.T) { assert.Nil(t, vm.k8sClient.ReadCR(testCtx, drive.Name, "", actualDrive)) assert.Nil(t, err) assert.Equal(t, actualDrive.Spec.Health, apiV1.HealthBad) - - updatedDrive := &drivecrd.Drive{} - assert.Nil(t, vm.k8sClient.ReadCR(testCtx, drive.Name, "", updatedDrive)) - assert.Equal(t, apiV1.DriveStatusOffline, updatedDrive.Spec.Status) + assert.Equal(t, apiV1.DriveStatusOffline, actualDrive.Spec.Status) }) t.Run("new drive", func(t *testing.T) {