Check error code DeadlineExceeded

This commit is contained in:
xing-yang
2020-03-06 03:59:51 +00:00
parent aa2bc2fb9c
commit 7930dd261d

View File

@@ -23,6 +23,8 @@ import (
crdv1 "github.com/kubernetes-csi/external-snapshotter/v2/pkg/apis/volumesnapshot/v1beta1" crdv1 "github.com/kubernetes-csi/external-snapshotter/v2/pkg/apis/volumesnapshot/v1beta1"
"github.com/kubernetes-csi/external-snapshotter/v2/pkg/utils" "github.com/kubernetes-csi/external-snapshotter/v2/pkg/utils"
codes "google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog" "k8s.io/klog"
@@ -331,7 +333,7 @@ func (ctrl *csiSnapshotSideCarController) createSnapshotOperation(content *crdv1
// resources on the storage system // resources on the storage system
err = ctrl.setAnnVolumeSnapshotBeingCreated(content) err = ctrl.setAnnVolumeSnapshotBeingCreated(content)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to set VolumeSnapshotBeingCreated annotation to Yes on the content %s: %q", content.Name, err) return nil, fmt.Errorf("failed to add VolumeSnapshotBeingCreated annotation on the content %s: %q", content.Name, err)
} }
driverName, snapshotID, creationTime, size, readyToUse, err := ctrl.handler.CreateSnapshot(content, class.Parameters, snapshotterCredentials) driverName, snapshotID, creationTime, size, readyToUse, err := ctrl.handler.CreateSnapshot(content, class.Parameters, snapshotterCredentials)
@@ -339,11 +341,12 @@ func (ctrl *csiSnapshotSideCarController) createSnapshotOperation(content *crdv1
// NOTE(xyang): handle create timeout // NOTE(xyang): handle create timeout
// If it is not a timeout error, remove annotation to indicate // If it is not a timeout error, remove annotation to indicate
// storage system has responded with an error // storage system has responded with an error
errStr := fmt.Sprintf("%q", err) if e, ok := status.FromError(err); ok {
if !strings.Contains(errStr, "DeadlineExceeded") { if e.Code() == codes.DeadlineExceeded {
err = ctrl.removeAnnVolumeSnapshotBeingCreated(content) err = ctrl.removeAnnVolumeSnapshotBeingCreated(content)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to set VolumeSnapshotBeingCreated annotation to No on the content %s: %q", content.Name, err) return nil, fmt.Errorf("failed to remove VolumeSnapshotBeingCreated annotation from the content %s: %q", content.Name, err)
}
} }
} }
@@ -366,7 +369,7 @@ func (ctrl *csiSnapshotSideCarController) createSnapshotOperation(content *crdv1
// cut the snapshot // cut the snapshot
err = ctrl.removeAnnVolumeSnapshotBeingCreated(content) err = ctrl.removeAnnVolumeSnapshotBeingCreated(content)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to set VolumeSnapshotBeingCreated annotation to No on the content %s: %q", content.Name, err) return nil, fmt.Errorf("failed to remove VolumeSnapshotBeingCreated annotation on the content %s: %q", content.Name, err)
} }
// Update content in the cache store // Update content in the cache store