Skip to content

Commit b184312

Browse files
Praveenrajmanibalamurugana
andauthoredDec 18, 2023
Improve the error messages for topology mismatches (#888)
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>
1 parent a70e7af commit b184312

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed
 

‎pkg/csi/controller/utils.go

+22-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package controller
1919
import (
2020
"context"
2121
"crypto/rand"
22+
"fmt"
2223
"math/big"
2324
"strings"
2425

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

132133
if len(drives) == 0 {
133134
if len(req.GetAccessibilityRequirements().GetPreferred()) != 0 || len(req.GetAccessibilityRequirements().GetRequisite()) != 0 {
134-
return nil, status.Error(codes.ResourceExhausted, "no drive found for requested topology")
135+
requestedSize := "nil"
136+
if req.GetCapacityRange() != nil {
137+
requestedSize = fmt.Sprintf("%d bytes", req.GetCapacityRange().GetRequiredBytes())
138+
}
139+
var requestedNodes []string
140+
if requestedNodes = getNodeNamesFromTopology(req.AccessibilityRequirements.GetPreferred()); len(requestedNodes) == 0 {
141+
requestedNodes = getNodeNamesFromTopology(req.AccessibilityRequirements.GetRequisite())
142+
}
143+
return nil, status.Errorf(codes.ResourceExhausted, "no drive found for requested topology; requested node(s): %s; requested size: %s", strings.Join(requestedNodes, ","), requestedSize)
135144
}
136-
137145
if req.GetCapacityRange() != nil {
138146
return nil, status.Errorf(codes.OutOfRange, "no drive found for requested size %v", req.GetCapacityRange().GetRequiredBytes())
139147
}
140-
141148
return nil, status.Error(codes.FailedPrecondition, "no drive found")
142149
}
143150

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

165172
return &maxFreeCapacityDrives[n.Int64()], nil
166173
}
174+
175+
func getNodeNamesFromTopology(topologies []*csi.Topology) (requestedNodes []string) {
176+
for _, topology := range topologies {
177+
for key, value := range topology.GetSegments() {
178+
if key == string(directpvtypes.TopologyDriverNode) {
179+
requestedNodes = append(requestedNodes, value)
180+
break
181+
}
182+
}
183+
}
184+
return
185+
}

0 commit comments

Comments
 (0)