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

Revert "fix: wrong node matching when detaching dangling disk" #2815

Merged
merged 1 commit into from
Jan 9, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/azuredisk/azure_controller_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (c *controllerCommon) AttachDisk(ctx context.Context, diskName, diskURI str
if err != nil {
return -1, err
}
if isSameNode(string(nodeName), string(attachedNode)) {
if strings.EqualFold(string(nodeName), string(attachedNode)) {
klog.Warningf("volume %s is actually attached to current node %s, invalidate vm cache and return error", diskURI, nodeName)
// update VM(invalidate vm cache)
if errUpdate := c.UpdateVM(ctx, nodeName); errUpdate != nil {
Expand Down
35 changes: 0 additions & 35 deletions pkg/azuredisk/azuredisk.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,38 +786,3 @@ func checkAllocatable(ctx context.Context, clientset kubernetes.Interface, nodeN

return fmt.Errorf("isAllocatableSet: driver not found on node %s", nodeName)
}

// isSameNode checks whether node1 and node2 are the same node
func isSameNode(node1, node2 string) bool {
if strings.EqualFold(node1, node2) {
return true
}
// check whether node1 and node2 are VMSS instance name
if len(node1) < 6 || len(node2) < 6 {
return false
}

// machineName is composed of computerNamePrefix and 36-based instanceID.
// And instanceID part if in fixed length of 6 characters.
// Refer https://msftstack.wordpress.com/2017/05/10/figuring-out-azure-vm-scale-set-machine-names/.
if strings.EqualFold(node1[:len(node1)-6], node2[:len(node2)-6]) {
// check whether node1 is 36-based instanceID and node2 is 10-based instanceID
id1, err := strconv.ParseUint(node1[len(node1)-6:], 36, 64)
if err == nil {
id2, err := strconv.ParseUint(node2[len(node2)-6:], 10, 64)
if err == nil && id1 == id2 {
return true
}
}

// check whether node1 is 10-based instanceID and node2 is 36-based instanceID
id1, err = strconv.ParseUint(node1[len(node1)-6:], 10, 64)
if err == nil {
id2, err := strconv.ParseUint(node2[len(node2)-6:], 36, 64)
if err == nil && id1 == id2 {
return true
}
}
}
return false
}
76 changes: 0 additions & 76 deletions pkg/azuredisk/azuredisk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,79 +589,3 @@ func TestGetUsedLunsFromNode(t *testing.T) {
}
}
}

func TestIsSameNode(t *testing.T) {
tests := []struct {
name string
nodeName string
nodeName2 string
expectedValue bool
}{
{
name: "same node",
nodeName: "test-node",
nodeName2: "test-node",
expectedValue: true,
},
{
name: "different node with shorter name",
nodeName: "node1",
nodeName2: "node2",
expectedValue: false,
},
{
name: "different node",
nodeName: "test-node",
nodeName2: "test-node2",
expectedValue: false,
},
{
name: "empty node",
nodeName: "",
nodeName2: "test-node",
expectedValue: false,
},
{
name: "node1 is 10 based instance name, node2 is 36 based instance name",
nodeName: "aks-agentpool-20657377-vmss000012",
nodeName2: "aks-agentpool-20657377-vmss00000c",
expectedValue: true,
},
{
name: "node1 is 36 based instance name, node2 is 10 based instance name",
nodeName: "aks-agentpool-20657377-vmss00000c",
nodeName2: "aks-agentpool-20657377-vmss000012",
expectedValue: true,
},
{
name: "node1 is 10 based instance name, node2 is 36 based instance name, but different vmss",
nodeName: "aks-agentpool-20657377-vmss000019",
nodeName2: "aks-agentpool-20657377-vmss00000c",
expectedValue: false,
},
{
name: "node1 is 36 based instance name, node2 is 10 based instance name, but different vmss",
nodeName: "aks-agentpool-20657377-vmss00000c",
nodeName2: "aks-agentpool-20657377-vmss000019",
expectedValue: false,
},
{
name: "node1 is 10 based instance name, node2 is 10 based instance name, but different vmss",
nodeName: "aks-agentpool-20657377-vmss000019",
nodeName2: "aks-agentpool-20657377-vmss000017",
expectedValue: false,
},
{
name: "node1 is 36 based instance name, node2 is 36 based instance name, but different vmss",
nodeName: "aks-agentpool-20657377-vmss00000c",
nodeName2: "aks-agentpool-20657377-vmss00000a",
expectedValue: false,
},
}
for _, test := range tests {
result := isSameNode(test.nodeName, test.nodeName2)
if result != test.expectedValue {
t.Errorf("test(%s): result(%v) != expected result(%v)", test.name, result, test.expectedValue)
}
}
}
Loading