@@ -18,6 +18,7 @@ package driver
1818
1919import (
2020 "context"
21+ "errors"
2122 "fmt"
2223 "os"
2324 "strconv"
@@ -182,7 +183,7 @@ func (d *controllerService) CreateVolume(ctx context.Context, req *csi.CreateVol
182183 }
183184 // Check if the disk already exists
184185 // Disk exists only if previous createVolume request fails due to any network/tcp error
185- disk , _ := d .cloud .GetDiskByName (volName )
186+ disk , err := d .cloud .GetDiskByName (volName )
186187 if disk != nil {
187188 // wait for volume to be available as the volume already exists
188189 klog .V (3 ).Infof ("CreateVolume: Found an existing volume %s in %q state." , volName , disk .State )
@@ -191,15 +192,24 @@ func (d *controllerService) CreateVolume(ctx context.Context, req *csi.CreateVol
191192 return nil , err
192193 }
193194 if disk .State != cloud .VolumeAvailableState {
194- err = d .cloud .WaitForVolumeState (disk .VolumeID , cloud .VolumeAvailableState )
195+ vol , err : = d .cloud .WaitForVolumeState (disk .VolumeID , cloud .VolumeAvailableState )
195196 if err != nil {
196197 return nil , status .Errorf (codes .Internal , "Disk exists, but not in required state. Current:%s Required:%s" , disk .State , cloud .VolumeAvailableState )
197198 }
199+ // When the disk is still in the "Creating" state, the WWN will not be available.
200+ // In such a case, once when the volume is available, assign the WWN to the disk if not already assigned.
201+ if disk .WWN == "" {
202+ disk .WWN = vol .Wwn
203+ }
198204 }
199205 } else {
200- disk , err = d .cloud .CreateDisk (volName , opts )
201- if err != nil {
202- return nil , status .Errorf (codes .Internal , "Could not create volume %q: %v" , volName , err )
206+ if errors .Is (err , cloud .ErrNotFound ) {
207+ disk , err = d .cloud .CreateDisk (volName , opts )
208+ if err != nil {
209+ return nil , status .Errorf (codes .Internal , "Could not create volume %q: %v" , volName , err )
210+ }
211+ } else {
212+ return nil , status .Errorf (codes .Internal , "Could not find volume by name %q: %v" , volName , err )
203213 }
204214 }
205215 klog .V (3 ).Infof ("CreateVolume: created volume %s, took %s" , volName , time .Since (start ))
@@ -256,7 +266,7 @@ func (d *controllerService) ControllerPublishVolume(ctx context.Context, req *cs
256266
257267 pvInfo := map [string ]string {WWNKey : req .VolumeContext [WWNKey ]}
258268
259- err := d .cloud .AttachDisk (volumeID , nodeID )
269+ _ , err := d .cloud .AttachDisk (volumeID , nodeID )
260270 if err != nil {
261271 if strings .Contains (err .Error (), cloud .ErrConflictVolumeAlreadyExists .Error ()) {
262272 return nil , status .Error (codes .AlreadyExists , err .Error ())
@@ -288,7 +298,7 @@ func (d *controllerService) ControllerUnpublishVolume(ctx context.Context, req *
288298 return nil , status .Error (codes .InvalidArgument , "Node ID not provided" )
289299 }
290300
291- err := d .cloud .DetachDisk (volumeID , nodeID )
301+ _ , err := d .cloud .DetachDisk (volumeID , nodeID )
292302 if err != nil {
293303 if strings .Contains (err .Error (), cloud .ErrVolumeDetachNotFound .Error ()) {
294304 klog .V (4 ).Infof ("ControllerUnpublishVolume: volume %s is detached from node %s, took %s" , volumeID , nodeID , time .Since (start ))
0 commit comments