Skip to content

Commit

Permalink
Improve the error messages for topology mismatches
Browse files Browse the repository at this point in the history
Add requested nodes and sizes to the error messages sent
when there is a topology mismatch; ie, when a pod is scheduled
on a wrong node etc.
  • Loading branch information
Praveenrajmani committed Dec 18, 2023
1 parent c580047 commit 9334f35
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions pkg/csi/controller/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package controller
import (
"context"
"crypto/rand"
"fmt"
"math/big"
"strings"

Expand Down Expand Up @@ -131,13 +132,19 @@ func selectDrive(ctx context.Context, req *csi.CreateVolumeRequest) (*types.Driv

if len(drives) == 0 {
if len(req.GetAccessibilityRequirements().GetPreferred()) != 0 || len(req.GetAccessibilityRequirements().GetRequisite()) != 0 {
return nil, status.Error(codes.ResourceExhausted, "no drive found for requested topology")
requestedSize := "nil"
if req.GetCapacityRange() != nil {
requestedSize = fmt.Sprintf("%d bytes", req.GetCapacityRange().GetRequiredBytes())
}
var requestedNodes string
if requestedNodes = getNodeNamesFromTopology(req.AccessibilityRequirements.GetPreferred()); requestedNodes == "" {
requestedNodes = getNodeNamesFromTopology(req.AccessibilityRequirements.GetRequisite())
}
return nil, status.Errorf(codes.ResourceExhausted, "no drive found for requested topology; requested node(s): %s; requested size: %s", requestedNodes, requestedSize)
}

if req.GetCapacityRange() != nil {
return nil, status.Errorf(codes.OutOfRange, "no drive found for requested size %v", req.GetCapacityRange().GetRequiredBytes())
}

return nil, status.Error(codes.FailedPrecondition, "no drive found")
}

Expand All @@ -164,3 +171,19 @@ func selectDrive(ctx context.Context, req *csi.CreateVolumeRequest) (*types.Driv

return &maxFreeCapacityDrives[n.Int64()], nil
}

func getNodeNamesFromTopology(topologies []*csi.Topology) (requestedNodes string) {
for _, topology := range topologies {
for key, value := range topology.GetSegments() {
if key == string(directpvtypes.TopologyDriverNode) {
if requestedNodes != "" {
requestedNodes += ", " + value
} else {
requestedNodes = value
}
break
}
}
}
return
}

0 comments on commit 9334f35

Please sign in to comment.