Skip to content

Commit 7930dd2

Browse files
committed
Check error code DeadlineExceeded
1 parent aa2bc2f commit 7930dd2

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

pkg/sidecar-controller/snapshot_controller.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)