Merge pull request #80518 from jsafrane/cinder-detach-idempotent

Fix detachment of deleted volumes
This commit is contained in:
Kubernetes Prow Robot 2019-07-25 20:48:24 -07:00 committed by GitHub
commit 1a95199311
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -41,7 +41,7 @@ import (
"github.com/mitchellh/mapstructure"
"gopkg.in/gcfg.v1"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
netutil "k8s.io/apimachinery/pkg/util/net"

View File

@ -26,7 +26,7 @@ import (
"strings"
"time"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/types"
cloudprovider "k8s.io/cloud-provider"
@ -177,6 +177,9 @@ func (volumes *VolumesV1) getVolume(volumeID string) (Volume, error) {
timeTaken := time.Since(startTime).Seconds()
recordOpenstackOperationMetric("get_v1_volume", timeTaken, err)
if err != nil {
if isNotFound(err) {
return Volume{}, ErrNotFound
}
return Volume{}, fmt.Errorf("error occurred getting volume by ID: %s, err: %v", volumeID, err)
}
@ -202,6 +205,9 @@ func (volumes *VolumesV2) getVolume(volumeID string) (Volume, error) {
timeTaken := time.Since(startTime).Seconds()
recordOpenstackOperationMetric("get_v2_volume", timeTaken, err)
if err != nil {
if isNotFound(err) {
return Volume{}, ErrNotFound
}
return Volume{}, fmt.Errorf("error occurred getting volume by ID: %s, err: %v", volumeID, err)
}
@ -227,6 +233,9 @@ func (volumes *VolumesV3) getVolume(volumeID string) (Volume, error) {
timeTaken := time.Since(startTime).Seconds()
recordOpenstackOperationMetric("get_v3_volume", timeTaken, err)
if err != nil {
if isNotFound(err) {
return Volume{}, ErrNotFound
}
return Volume{}, fmt.Errorf("error occurred getting volume by ID: %s, err: %v", volumeID, err)
}
@ -614,6 +623,10 @@ func (os *OpenStack) DiskIsAttached(instanceID, volumeID string) (bool, error) {
}
volume, err := os.getVolume(volumeID)
if err != nil {
if err == ErrNotFound {
// Volume does not exists, it can't be attached.
return false, nil
}
return false, err
}