Skip to content

Commit

Permalink
Merge pull request kubernetes-csi#195 from avalluri/fix-listvolumes
Browse files Browse the repository at this point in the history
sanity: capture newly created volume IDs
  • Loading branch information
k8s-ci-robot authored May 8, 2019
2 parents ae9f625 + ce3711a commit bd0bf72
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pkg/sanity/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) {
// currentTotalVols is the total number of volumes at a given time. It
// is used to verify that all the volumes have been listed.
currentTotalVols := 0
// newVolIDs to keep a record of the newly created volume ids.
var newVolIDs []string
// newVols to keep a record of the newly created volume names and ids.
newVols := map[string]string{}

// Get the number of existing volumes.
vols, err := c.ListVolumes(
Expand All @@ -299,10 +299,10 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) {

By("creating required new volumes")
requiredVols := minVolCount - initialTotalVols
name := "sanity"
for i := 1; i <= requiredVols; i++ {
name := "sanity" + strconv.Itoa(i)
req := &csi.CreateVolumeRequest{
Name: name + strconv.Itoa(i),
Name: name,
VolumeCapabilities: []*csi.VolumeCapability{
{
AccessType: &csi.VolumeCapability_Mount{
Expand All @@ -319,6 +319,8 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) {
vol, err := c.CreateVolume(context.Background(), req)
Expect(err).NotTo(HaveOccurred())
Expect(vol).NotTo(BeNil())
cl.RegisterVolume(name, VolumeInfo{VolumeID: vol.Volume.VolumeId})
newVols[name] = vol.Volume.VolumeId
}

// Update the current total vols count.
Expand All @@ -342,14 +344,15 @@ var _ = DescribeSanity("Controller Service", func(sc *SanityContext) {
if initialTotalVols < minVolCount {

By("cleaning up deleting the volumes")
for _, volID := range newVolIDs {
for name, volID := range newVols {
delReq := &csi.DeleteVolumeRequest{
VolumeId: volID,
Secrets: sc.Secrets.DeleteVolumeSecret,
}

_, err := c.DeleteVolume(context.Background(), delReq)
Expect(err).NotTo(HaveOccurred())
cl.UnregisterVolume(name)
}
}
})
Expand Down

0 comments on commit bd0bf72

Please sign in to comment.