Skip to content

Commit

Permalink
Improve the error messages for topology mismatches (#888)
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.

Co-authored-by: Bala FA <bala@minio.io>
  • Loading branch information
Praveenrajmani and balamurugana committed Dec 18, 2023
1 parent a70e7af commit b184312
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions pkg/csi/controller/utils.go
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()); len(requestedNodes) == 0 {
requestedNodes = getNodeNamesFromTopology(req.AccessibilityRequirements.GetRequisite())
}
return nil, status.Errorf(codes.ResourceExhausted, "no drive found for requested topology; requested node(s): %s; requested size: %s", strings.Join(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,15 @@ 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) {
requestedNodes = append(requestedNodes, value)
break
}
}
}
return
}

0 comments on commit b184312

Please sign in to comment.