@@ -23,6 +23,8 @@ import (
2323
2424 crdv1 "github.com/kubernetes-csi/external-snapshotter/v2/pkg/apis/volumesnapshot/v1beta1"
2525 "github.com/kubernetes-csi/external-snapshotter/v2/pkg/utils"
26+ codes "google.golang.org/grpc/codes"
27+ "google.golang.org/grpc/status"
2628 v1 "k8s.io/api/core/v1"
2729 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2830 "k8s.io/klog"
@@ -331,19 +333,20 @@ func (ctrl *csiSnapshotSideCarController) createSnapshotOperation(content *crdv1
331333 // resources on the storage system
332334 err = ctrl .setAnnVolumeSnapshotBeingCreated (content )
333335 if err != nil {
334- return nil , fmt .Errorf ("failed to set VolumeSnapshotBeingCreated annotation to Yes on the content %s: %q" , content .Name , err )
336+ return nil , fmt .Errorf ("failed to add VolumeSnapshotBeingCreated annotation on the content %s: %q" , content .Name , err )
335337 }
336338
337339 driverName , snapshotID , creationTime , size , readyToUse , err := ctrl .handler .CreateSnapshot (content , class .Parameters , snapshotterCredentials )
338340 if err != nil {
339341 // NOTE(xyang): handle create timeout
340342 // If it is not a timeout error, remove annotation to indicate
341343 // storage system has responded with an error
342- errStr := fmt .Sprintf ("%q" , err )
343- if ! strings .Contains (errStr , "DeadlineExceeded" ) {
344- err = ctrl .removeAnnVolumeSnapshotBeingCreated (content )
345- if err != nil {
346- return nil , fmt .Errorf ("failed to set VolumeSnapshotBeingCreated annotation to No on the content %s: %q" , content .Name , err )
344+ if e , ok := status .FromError (err ); ok {
345+ if e .Code () == codes .DeadlineExceeded {
346+ err = ctrl .removeAnnVolumeSnapshotBeingCreated (content )
347+ if err != nil {
348+ return nil , fmt .Errorf ("failed to remove VolumeSnapshotBeingCreated annotation from the content %s: %q" , content .Name , err )
349+ }
347350 }
348351 }
349352
@@ -366,7 +369,7 @@ func (ctrl *csiSnapshotSideCarController) createSnapshotOperation(content *crdv1
366369 // cut the snapshot
367370 err = ctrl .removeAnnVolumeSnapshotBeingCreated (content )
368371 if err != nil {
369- return nil , fmt .Errorf ("failed to set VolumeSnapshotBeingCreated annotation to No on the content %s: %q" , content .Name , err )
372+ return nil , fmt .Errorf ("failed to remove VolumeSnapshotBeingCreated annotation on the content %s: %q" , content .Name , err )
370373 }
371374
372375 // Update content in the cache store
0 commit comments