Skip to content

Commit

Permalink
refine error messages for labeling and label removal in sg handling
Browse files Browse the repository at this point in the history
Signed-off-by: Shi, Crane <crane.shi@emc.com>
  • Loading branch information
CraneShiEMC committed Jun 26, 2023
1 parent daf9fc3 commit d861003
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/crcontrollers/storagegroup/storagegroupcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"reflect"
"strconv"
"strings"
"time"

"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -399,17 +400,20 @@ func (c *Controller) handleStorageGroupDeletion(ctx context.Context, log *logrus
log.Errorf("failed to read drives list: %v", err)
return ctrl.Result{Requeue: true}, err
}

var labelRemovalErrMsgs []string
removalNoError := true
for _, drive := range drivesList.Items {
drive := drive
if drive.Labels[apiV1.StorageGroupLabelKey] == sg.Name {
if err := c.removeDriveAndACStorageGroupLabel(ctx, log, &drive, sg); err != nil {
labelRemovalErrMsgs = append(labelRemovalErrMsgs, err.Error())
removalNoError = false
}
}
}
if !removalNoError {
return ctrl.Result{Requeue: true}, fmt.Errorf("error in removing storage-group label")
return ctrl.Result{Requeue: true}, fmt.Errorf(strings.Join(labelRemovalErrMsgs, "\n"))
}
return c.removeFinalizer(ctx, log, sg)
}
Expand Down Expand Up @@ -438,6 +442,8 @@ func (c *Controller) handleStorageGroupCreationOrUpdate(ctx context.Context, log
drivesCount := map[string]int32{}
driveSelector := sg.Spec.DriveSelector

var labelingErrMsgs []string

// used for candidate drives to be selected by storagegroup with numberDrivesPerNode > 0
var candidateDrives []*drivecrd.Drive
for _, d := range drivesList.Items {
Expand All @@ -463,6 +469,7 @@ func (c *Controller) handleStorageGroupCreationOrUpdate(ctx context.Context, log

if err := c.addDriveAndACStorageGroupLabel(ctx, log, &drive, sg); err != nil {
labelingNoError = false
labelingErrMsgs = append(labelingErrMsgs, err.Error())
}
noDriveSelected = false
}
Expand All @@ -473,6 +480,7 @@ func (c *Controller) handleStorageGroupCreationOrUpdate(ctx context.Context, log
if drivesCount[drive.Spec.NodeId] < driveSelector.NumberDrivesPerNode {
if err := c.addDriveAndACStorageGroupLabel(ctx, log, drive, sg); err != nil {
labelingNoError = false
labelingErrMsgs = append(labelingErrMsgs, err.Error())
}
noDriveSelected = false
drivesCount[drive.Spec.NodeId]++
Expand All @@ -490,7 +498,7 @@ func (c *Controller) handleStorageGroupCreationOrUpdate(ctx context.Context, log
}
return ctrl.Result{}, nil
}
return ctrl.Result{Requeue: true}, fmt.Errorf("error in adding storage-group label")
return ctrl.Result{Requeue: true}, fmt.Errorf(strings.Join(labelingErrMsgs, "\n"))
}

func (c *Controller) isDriveSelectedByValidMatchFields(log *logrus.Entry, drive *api.Drive, matchFields *map[string]string) bool {
Expand Down

0 comments on commit d861003

Please sign in to comment.