dra controller helper: make allocation error message more readable

Here's what it looked like before:

    err="allocation of one or more pod claims failed. Claim test-dra5z9nh-resource-1an8wcr: failed allocating claim 4739f9a2-eedc-4702-ab17-e201e2dc0ad2. Claim test-dra5z9nh-resource-1bbdsj2: failed allocating claim e5525e5a-3397-40b4-a633-9ac354605303."

Some observations:

- Inserting the claim UID is just noise because it doesn't get logged anywhere else.
- Concatenating on a single line makes it hard to see the individual errors.

Joining with errors.Join leads to more readable output. The claim name only
gets inserted if not present already, to keep the individual error entries
short:

  err=<
        	claim test-dralmx55-resource-1asvr5d: resources exhausted on node "scheduler-perf-dra-w62wm"
        	claim test-dralmx55-resource-1bqq6c9: resources exhausted on node "scheduler-perf-dra-w62wm"
   >
This commit is contained in:
Patrick Ohly 2023-08-30 15:21:30 +02:00
parent f96e23e477
commit 062c57ae92

View File

@ -780,16 +780,20 @@ func (ctrl *controller) syncPodSchedulingContexts(ctx context.Context, schedulin
ctrl.allocateClaims(ctx, claims, selectedNode, selectedUser) ctrl.allocateClaims(ctx, claims, selectedNode, selectedUser)
allErrorsStr := "allocation of one or more pod claims failed." var allErrors []error
allocationFailed := false
for _, delayed := range claims { for _, delayed := range claims {
if delayed.Error != nil { if delayed.Error != nil {
allErrorsStr = fmt.Sprintf("%s Claim %s: %s.", allErrorsStr, delayed.Claim.Name, delayed.Error) if strings.Contains(delayed.Error.Error(), delayed.Claim.Name) {
allocationFailed = true // Avoid adding redundant information.
allErrors = append(allErrors, delayed.Error)
} else {
// Include claim name, it's not in the underlying error.
allErrors = append(allErrors, fmt.Errorf("claim %s: %v", delayed.Claim.Name, delayed.Error))
}
} }
} }
if allocationFailed { if len(allErrors) > 0 {
return fmt.Errorf(allErrorsStr) return errors.Join(allErrors...)
} }
} }
} }