@@ -281,8 +281,8 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) {
281281 // currentTotalVols is the total number of volumes at a given time. It
282282 // is used to verify that all the volumes have been listed.
283283 currentTotalVols := 0
284- // newVolIDs to keep a record of the newly created volume ids.
285- var newVolIDs [ ]string
284+ // newVols to keep a record of the newly created volume names and ids.
285+ newVols := map [ string ]string {}
286286
287287 // Get the number of existing volumes.
288288 vols , err := c .ListVolumes (
@@ -299,10 +299,10 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) {
299299
300300 By ("creating required new volumes" )
301301 requiredVols := minVolCount - initialTotalVols
302- name := "sanity"
303302 for i := 1 ; i <= requiredVols ; i ++ {
303+ name := "sanity" + strconv .Itoa (i )
304304 req := & csi.CreateVolumeRequest {
305- Name : name + strconv . Itoa ( i ) ,
305+ Name : name ,
306306 VolumeCapabilities : []* csi.VolumeCapability {
307307 {
308308 AccessType : & csi.VolumeCapability_Mount {
@@ -319,6 +319,8 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) {
319319 vol , err := c .CreateVolume (context .Background (), req )
320320 Expect (err ).NotTo (HaveOccurred ())
321321 Expect (vol ).NotTo (BeNil ())
322+ cl .RegisterVolume (name , VolumeInfo {VolumeID : vol .Volume .VolumeId })
323+ newVols [name ] = vol .Volume .VolumeId
322324 }
323325
324326 // Update the current total vols count.
@@ -342,14 +344,15 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) {
342344 if initialTotalVols < minVolCount {
343345
344346 By ("cleaning up deleting the volumes" )
345- for _ , volID := range newVolIDs {
347+ for name , volID := range newVols {
346348 delReq := & csi.DeleteVolumeRequest {
347349 VolumeId : volID ,
348350 Secrets : sc .Secrets .DeleteVolumeSecret ,
349351 }
350352
351353 _ , err := c .DeleteVolume (context .Background (), delReq )
352354 Expect (err ).NotTo (HaveOccurred ())
355+ cl .UnregisterVolume (name )
353356 }
354357 }
355358 })
0 commit comments