mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Merge pull request #42444 from jingxu97/Mar/deleteVolume
Automatic merge from submit-queue (batch tested with PRs 42608, 42444) Return nil when deleting non-exist GCE PD When gce cloud tries to delete a disk, if the disk could not be found from the zones, the function should return nil error. This modified behavior is also consistent with AWS
This commit is contained in:
commit
e2218290cf
@ -152,7 +152,10 @@ type Routes interface {
|
|||||||
DeleteRoute(clusterName string, route *Route) error
|
DeleteRoute(clusterName string, route *Route) error
|
||||||
}
|
}
|
||||||
|
|
||||||
var InstanceNotFound = errors.New("instance not found")
|
var (
|
||||||
|
InstanceNotFound = errors.New("instance not found")
|
||||||
|
DiskNotFound = errors.New("disk is not found")
|
||||||
|
)
|
||||||
|
|
||||||
// Zone represents the location of a particular machine.
|
// Zone represents the location of a particular machine.
|
||||||
type Zone struct {
|
type Zone struct {
|
||||||
|
@ -2511,6 +2511,10 @@ func (gce *GCECloud) DeleteDisk(diskToDelete string) error {
|
|||||||
if isGCEError(err, "resourceInUseByAnotherResource") {
|
if isGCEError(err, "resourceInUseByAnotherResource") {
|
||||||
return volume.NewDeletedVolumeInUseError(err.Error())
|
return volume.NewDeletedVolumeInUseError(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err == cloudprovider.DiskNotFound {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2712,6 +2716,7 @@ func (gce *GCECloud) getDiskByName(diskName string, zone string) (*gceDisk, erro
|
|||||||
|
|
||||||
// Scans all managed zones to return the GCE PD
|
// Scans all managed zones to return the GCE PD
|
||||||
// Prefer getDiskByName, if the zone can be established
|
// Prefer getDiskByName, if the zone can be established
|
||||||
|
// Return cloudprovider.DiskNotFound if the given disk cannot be found in any zone
|
||||||
func (gce *GCECloud) getDiskByNameUnknownZone(diskName string) (*gceDisk, error) {
|
func (gce *GCECloud) getDiskByNameUnknownZone(diskName string) (*gceDisk, error) {
|
||||||
// Note: this is the gotcha right now with GCE PD support:
|
// Note: this is the gotcha right now with GCE PD support:
|
||||||
// disk names are not unique per-region.
|
// disk names are not unique per-region.
|
||||||
@ -2742,7 +2747,8 @@ func (gce *GCECloud) getDiskByNameUnknownZone(diskName string) (*gceDisk, error)
|
|||||||
if found != nil {
|
if found != nil {
|
||||||
return found, nil
|
return found, nil
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("GCE persistent disk %q not found in managed zones (%s)", diskName, strings.Join(gce.managedZones, ","))
|
glog.Warningf("GCE persistent disk %q not found in managed zones (%s)", diskName, strings.Join(gce.managedZones, ","))
|
||||||
|
return nil, cloudprovider.DiskNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetGCERegion returns region of the gce zone. Zone names
|
// GetGCERegion returns region of the gce zone. Zone names
|
||||||
|
@ -524,6 +524,13 @@ var _ = framework.KubeDescribe("Pod Disks", func() {
|
|||||||
By("Waiting for pd to detach from host0")
|
By("Waiting for pd to detach from host0")
|
||||||
framework.ExpectNoError(waitForPDDetach(diskName, host0Name), "Timed out waiting for detach pd")
|
framework.ExpectNoError(waitForPDDetach(diskName, host0Name), "Timed out waiting for detach pd")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("should be able to delete a non-existent PD without error", func() {
|
||||||
|
framework.SkipUnlessProviderIs("gce")
|
||||||
|
|
||||||
|
By("delete a PD")
|
||||||
|
framework.DeletePDWithRetry("non-exist")
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
func verifyPDContentsViaContainer(f *framework.Framework, podName, containerName string, fileAndContentToVerify map[string]string) {
|
func verifyPDContentsViaContainer(f *framework.Framework, podName, containerName string, fileAndContentToVerify map[string]string) {
|
||||||
|
Loading…
Reference in New Issue
Block a user