@@ -62,6 +62,29 @@ const (
6262 replicationTypeRegionalPD = "regional-pd"
6363)
6464
65+ func isDiskReady (disk * gce.CloudDisk ) (bool , error ) {
66+ status := disk .GetStatus ()
67+ switch status {
68+ case "READY" :
69+ return true , nil
70+ case "FAILED" :
71+ return false , fmt .Errorf ("Disk %s status is FAILED" , disk .GetName ())
72+ case "CREATING" :
73+ klog .V (4 ).Infof ("Disk %s status is CREATING" , disk .GetName ())
74+ return false , nil
75+ case "DELETING" :
76+ klog .V (4 ).Infof ("Disk %s status is DELETING" , disk .GetName ())
77+ return false , nil
78+ case "RESTORING" :
79+ klog .V (4 ).Infof ("Disk %s status is RESTORING" , disk .GetName ())
80+ return false , nil
81+ default :
82+ klog .V (4 ).Infof ("Disk %s status is: %s" , disk .GetName (), status )
83+ }
84+
85+ return false , nil
86+ }
87+
6588func (gceCS * GCEControllerServer ) CreateVolume (ctx context.Context , req * csi.CreateVolumeRequest ) (* csi.CreateVolumeResponse , error ) {
6689 var err error
6790 // Validate arguments
@@ -143,6 +166,16 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
143166 if err != nil {
144167 return nil , status .Error (codes .AlreadyExists , fmt .Sprintf ("CreateVolume disk already exists with same name and is incompatible: %v" , err ))
145168 }
169+
170+ ready , err := isDiskReady (existingDisk )
171+ if err != nil {
172+ return nil , status .Error (codes .Internal , fmt .Sprintf ("CreateVolume disk %v had error checking ready status: %v" , volKey , err ))
173+ }
174+
175+ if ! ready {
176+ return nil , status .Error (codes .Internal , fmt .Sprintf ("CreateVolume disk %v is not ready" , volKey ))
177+ }
178+
146179 // If there is no validation error, immediately return success
147180 klog .V (4 ).Infof ("CreateVolume succeeded for disk %v, it already exists and was compatible" , volKey )
148181 return generateCreateVolumeResponse (existingDisk , capBytes , zones ), nil
@@ -187,6 +220,15 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
187220 default :
188221 return nil , status .Error (codes .InvalidArgument , fmt .Sprintf ("CreateVolume replication type '%s' is not supported" , params .ReplicationType ))
189222 }
223+
224+ ready , err := isDiskReady (disk )
225+ if err != nil {
226+ return nil , status .Error (codes .Internal , fmt .Sprintf ("CreateVolume disk %v had error checking ready status: %v" , volKey , err ))
227+ }
228+ if ! ready {
229+ return nil , status .Error (codes .Internal , fmt .Sprintf ("CreateVolume disk %v is not ready" , volKey ))
230+ }
231+
190232 klog .V (4 ).Infof ("CreateVolume succeeded for disk %v" , volKey )
191233 return generateCreateVolumeResponse (disk , capBytes , zones ), nil
192234
0 commit comments