Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the error messages for topology mismatches #888

Merged
merged 2 commits into from
Dec 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 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()); 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
}
Loading