@@ -19,6 +19,7 @@ package controller
19
19
import (
20
20
"context"
21
21
"crypto/rand"
22
+ "fmt"
22
23
"math/big"
23
24
"strings"
24
25
@@ -131,13 +132,19 @@ func selectDrive(ctx context.Context, req *csi.CreateVolumeRequest) (*types.Driv
131
132
132
133
if len (drives ) == 0 {
133
134
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 )
135
144
}
136
-
137
145
if req .GetCapacityRange () != nil {
138
146
return nil , status .Errorf (codes .OutOfRange , "no drive found for requested size %v" , req .GetCapacityRange ().GetRequiredBytes ())
139
147
}
140
-
141
148
return nil , status .Error (codes .FailedPrecondition , "no drive found" )
142
149
}
143
150
@@ -164,3 +171,15 @@ func selectDrive(ctx context.Context, req *csi.CreateVolumeRequest) (*types.Driv
164
171
165
172
return & maxFreeCapacityDrives [n .Int64 ()], nil
166
173
}
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