Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cherry pick of #82640: fix: azure disk detach failure if node not exists #82729

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 11 additions & 5 deletions pkg/cloudprovider/providers/azure/azure_controller_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,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 {
vmset, err := c.getNodeVMSet(nodeName)
if err != nil {
return err
}

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
}

klog.V(2).Infof("detach %v from node %q", diskURI, nodeName)

// make the lock here as small as possible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ func TestDetachDisk(t *testing.T) {

err := common.DetachDisk("", diskURI, "node1")
if err != nil {
fmt.Printf("TestAttachDisk return expected error: %v", err)
} else {
t.Errorf("TestAttachDisk unexpected nil err")
t.Errorf("TestAttachDisk got unexpected error: %v", err)
}
}