Skip to content

Commit

Permalink
[ISSUE-1076] updateDrivesCR refactoring
Browse files Browse the repository at this point in the history
Signed-off-by: Andrzej Zukowski <[email protected]>
  • Loading branch information
Andrzej-Zukowski committed Feb 7, 2024
1 parent a7e201a commit b261900
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions pkg/node/volumemgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,31 @@ func (m *VolumeManager) Discover() error {
return nil
}

// safeUpdateCRs updates Drives CRs based on provided Drives.
// Receives golang context and drivecrd.Drive with current data to be updated
// returns error in case of apiserver connection problems, nil otherwise
func (m *VolumeManager) safeUpdateCR(ctx context.Context, toUpdate drivecrd.Drive) error {
ll := m.log.WithFields(logrus.Fields{
"component": "VolumeManager",
"method": "safeUpdateCR",
})

updateRetry := wait.Backoff{
Steps: 6,
Duration: 1 * time.Second,
Factor: 2.0,
Jitter: 0,
}

return retry.OnError(updateRetry, checkErr.AlwaysSafeReturnError, func() error {
if err1 := m.k8sClient.UpdateCR(ctx, &toUpdate); err1 != nil {
ll.Infof("Failed to update drive CR (health/status) retrying, error %v", err1)
return err1
}

Check warning on line 635 in pkg/node/volumemgr.go

View check run for this annotation

Codecov / codecov/patch

pkg/node/volumemgr.go#L633-L635

Added lines #L633 - L635 were not covered by tests
return nil
})
}

// updateDrivesCRs updates Drives CRs based on provided list of Drives.
// Receives golang context and slice of discovered api.Drive structs usually got from DriveManager
// returns struct with information about drives updates
Expand Down Expand Up @@ -662,19 +687,7 @@ func (m *VolumeManager) updateDrivesCRs(ctx context.Context, drivesFromMgr []*ap
toUpdate := driveCR
toUpdate.Spec = *drivePtr

updateRetry := wait.Backoff{
Steps: 6,
Duration: 1 * time.Second,
Factor: 2.0,
Jitter: 0,
}
if err := retry.OnError(updateRetry, checkErr.AlwaysSafeReturnError, func() error {
if err1 := m.k8sClient.UpdateCR(ctx, &toUpdate); err1 != nil {
ll.Infof("Failed to update drive CR (health/status) retrying, error %v", err1)
return err1
}
return nil
}); err != nil {
if err := m.safeUpdateCR(ctx, toUpdate); err != nil {
ll.Errorf("Failed to update drive CR (health/status) %v, error %v", toUpdate, err)
updates.AddNotChanged(previousState)
} else {
Expand Down

0 comments on commit b261900

Please sign in to comment.