Skip to content

Commit

Permalink
feat(volume-controller): enhance precheck error
Browse files Browse the repository at this point in the history
Signed-off-by: Chin-Ya Huang <chin-ya.huang@suse.com>
  • Loading branch information
c3y1huang authored and derekbit committed Jul 5, 2024
1 parent 79435d7 commit 4aa94f1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
20 changes: 13 additions & 7 deletions controller/volume_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2251,11 +2251,17 @@ func (c *VolumeController) replenishReplicas(v *longhorn.Volume, e *longhorn.Eng
// Bypassing the precheck when hardNodeAffinity is provided, because
// we expect the new replica to be relocated to a specific node.
if hardNodeAffinity == "" {
if err := c.precheckCreateReplica(newReplica, rs, v); err != nil {
if multiError, err := c.precheckCreateReplica(newReplica, rs, v); err != nil {
log.WithError(err).Warnf("Unable to create new replica %v", newReplica.Name)

aggregatedReplicaScheduledError := util.NewMultiError(longhorn.ErrorReplicaSchedulePrecheckNewReplicaFailed)
if multiError != nil {
aggregatedReplicaScheduledError.Append(multiError)
}

v.Status.Conditions = types.SetCondition(v.Status.Conditions,
longhorn.VolumeConditionTypeScheduled, longhorn.ConditionStatusFalse,
longhorn.VolumeConditionReasonReplicaSchedulingFailure, longhorn.ErrorReplicaSchedulePrecheckNewReplicaFailed)
longhorn.VolumeConditionReasonReplicaSchedulingFailure, aggregatedReplicaScheduledError.Join())
continue
}
}
Expand Down Expand Up @@ -3406,17 +3412,17 @@ func (c *VolumeController) newReplica(v *longhorn.Volume, e *longhorn.Engine, ha
}
}

func (c *VolumeController) precheckCreateReplica(replica *longhorn.Replica, replicas map[string]*longhorn.Replica, volume *longhorn.Volume) error {
diskCandidates, _, err := c.scheduler.FindDiskCandidates(replica, replicas, volume)
func (c *VolumeController) precheckCreateReplica(replica *longhorn.Replica, replicas map[string]*longhorn.Replica, volume *longhorn.Volume) (util.MultiError, error) {
diskCandidates, multiError, err := c.scheduler.FindDiskCandidates(replica, replicas, volume)
if err != nil {
return err
return nil, err
}

if len(diskCandidates) == 0 {
return errors.Errorf("No available disk candidates to create a new replica of size %v", replica.Spec.VolumeSize)
return multiError, errors.Errorf("No available disk candidates to create a new replica of size %v", replica.Spec.VolumeSize)
}

return nil
return nil, nil
}

func (c *VolumeController) createReplica(replica *longhorn.Replica, v *longhorn.Volume, rs map[string]*longhorn.Replica, isRebuildingReplica bool) error {
Expand Down
3 changes: 2 additions & 1 deletion controller/volume_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ func (s *TestSuite) TestVolumeLifeCycle(c *C) {
tc.expectVolume.Status.CurrentImage = tc.volume.Spec.Image
tc.expectVolume.Status.Robustness = longhorn.VolumeRobustnessFaulted
tc.expectVolume.Status.Conditions = setVolumeConditionWithoutTimestamp(tc.expectVolume.Status.Conditions,
longhorn.VolumeConditionTypeScheduled, longhorn.ConditionStatusFalse, longhorn.VolumeConditionReasonReplicaSchedulingFailure, longhorn.ErrorReplicaSchedulePrecheckNewReplicaFailed)
longhorn.VolumeConditionTypeScheduled, longhorn.ConditionStatusFalse, longhorn.VolumeConditionReasonReplicaSchedulingFailure,
fmt.Sprintf("%s;%s", longhorn.ErrorReplicaSchedulePrecheckNewReplicaFailed, longhorn.ErrorReplicaScheduleNodeUnavailable))
testCases["volume create - replica creation failure"] = tc

// unable to create volume because no node to schedule
Expand Down

0 comments on commit 4aa94f1

Please sign in to comment.