{"record":{"id":"d959e8c7d7954461","repo":"kubernetes/kops","slug":"waiting-for-virtual-network-deletion-completion","errorCode":null,"errorMessage":"waiting for virtual network deletion completion: %w","messagePattern":"waiting for virtual network deletion completion: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/azure/virtualnetwork.go","lineNumber":81,"sourceCode":"\t\tif err != nil {\n\t\t\tvar respErr *azcore.ResponseError\n\t\t\tif errors.As(err, &respErr) && respErr.ErrorCode == \"ResourceGroupNotFound\" {\n\t\t\t\treturn nil, nil\n\t\t\t}\n\t\t\treturn nil, fmt.Errorf(\"listing virtual networks: %w\", err)\n\t\t}\n\t\tl = append(l, resp.Value...)\n\t}\n\treturn l, nil\n}\n\nfunc (c *virtualNetworksClientImpl) Delete(ctx context.Context, resourceGroupName, vnetName string) error {\n\tfuture, err := c.c.BeginDelete(ctx, resourceGroupName, vnetName, nil)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"deleting virtual network: %w\", err)\n\t}\n\tif _, err = future.PollUntilDone(ctx, nil); err != nil {\n\t\treturn fmt.Errorf(\"waiting for virtual network deletion completion: %w\", err)\n\t}\n\treturn nil\n}\n\nfunc newVirtualNetworksClientImpl(subscriptionID string, cred *azidentity.DefaultAzureCredential) (*virtualNetworksClientImpl, error) {\n\tc, err := network.NewVirtualNetworksClient(subscriptionID, cred, nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"creating virtual networks client: %w\", err)\n\t}\n\treturn &virtualNetworksClientImpl{\n\t\tc: c,\n\t}, nil\n}\n","sourceCodeStart":63,"sourceCodeEnd":95,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/azure/virtualnetwork.go#L63-L95","documentation":"Wrapped when the long-running delete operation fails during future.PollUntilDone — BeginDelete succeeded but the vnet deletion later failed or the context ended first. Typically Azure refuses because dependent resources are still attached, or the poll was cancelled/timed out.","triggerScenarios":"Delete's future.PollUntilDone(ctx, nil) returns an error: the ARM delete operation reached Failed state (dependent resources like load balancers, public IPs, or NICs still referencing the vnet/subnet), or ctx cancellation/timeout during polling.","commonSituations":"kops delete cluster tearing down while peering connections, load balancers or application security groups still reference subnets; user cancels the delete mid-way; ARM slow deletes exceeding local timeouts.","solutions":["Check Activity Log for the failed delete and delete dependent resources (load balancers, public IPs, peerings, NSGs) first, then retry","Re-run kops delete cluster — deletion is idempotent and retries are safe","Extend the context timeout so polling isn't cut off on large deployments","If truly stuck, remove the vnet manually with az network vnet delete after clearing dependencies"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Go: pre-check dependencies that block vnet deletion\npeerings, err := vnetPeeringsClient.List(ctx, rg, vnetName)\nif err == nil && len(peerings) > 0 {\n    return fmt.Errorf(\"delete %d vnet peerings before deleting %s\", len(peerings), vnetName)\n}","typeGuard":null,"tryCatchPattern":"err := vnetsClient.Delete(ctx, rg, vnetName)\nif err != nil {\n    if ctx.Err() != nil {\n        return fmt.Errorf(\"vnet deletion interrupted; re-run kops delete cluster to resume\")\n    }\n    return fmt.Errorf(\"vnet delete failed (check Activity Log for dependent resources): %w\", err)\n}","preventionTips":["Remove load balancers, public IPs, peerings, and NICs before deleting a vnet","Allow generous timeouts for teardown of large clusters","Re-run kops delete cluster; deletion is resumable/idempotent","If stuck, clear dependencies manually then az network vnet delete"],"tags":["azure","go","network","vnet","delete","long-running-operation"],"backgroundTag":"azure-long-running-operation-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}