mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 04:06:03 +00:00
fix: azure disk detach failure if node not exists
fix comments
This commit is contained in:
parent
06609b77e8
commit
d11cac9ada
@ -150,17 +150,23 @@ func (c *controllerCommon) AttachDisk(isManagedDisk bool, diskName, diskURI stri
|
||||
|
||||
// DetachDisk detaches a disk from host. The vhd can be identified by diskName or diskURI.
|
||||
func (c *controllerCommon) DetachDisk(diskName, diskURI string, nodeName types.NodeName) error {
|
||||
instanceid, err := c.cloud.InstanceID(context.TODO(), nodeName)
|
||||
if err != nil {
|
||||
if err == cloudprovider.InstanceNotFound {
|
||||
// if host doesn't exist, no need to detach
|
||||
klog.Warningf("azureDisk - failed to get azure instance id(%q), DetachDisk(%s) will assume disk is already detached",
|
||||
nodeName, diskURI)
|
||||
return nil
|
||||
}
|
||||
klog.Warningf("failed to get azure instance id (%v)", err)
|
||||
return fmt.Errorf("failed to get azure instance id for node %q (%v)", nodeName, err)
|
||||
}
|
||||
|
||||
vmset, err := c.getNodeVMSet(nodeName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
instanceid, err := c.cloud.InstanceID(context.TODO(), nodeName)
|
||||
if err != nil {
|
||||
klog.Warningf("failed to get azure instance id (%v)", err)
|
||||
return fmt.Errorf("failed to get azure instance id for node %q (%v)", nodeName, err)
|
||||
}
|
||||
|
||||
klog.V(2).Infof("detach %v from node %q", diskURI, nodeName)
|
||||
|
||||
// make the lock here as small as possible
|
||||
|
@ -88,9 +88,9 @@ func TestCommonDetachDisk(t *testing.T) {
|
||||
expectedErr bool
|
||||
}{
|
||||
{
|
||||
desc: "an error shall be returned if there's no such instance corresponding to given nodeName",
|
||||
desc: "error should not be returned if there's no such instance corresponding to given nodeName",
|
||||
nodeName: "vm1",
|
||||
expectedErr: true,
|
||||
expectedErr: false,
|
||||
},
|
||||
{
|
||||
desc: "no error shall be returned if there's no matching disk according to given diskName",
|
||||
|
Loading…
Reference in New Issue
Block a user