{"record":{"id":"62f29a60351c78ed","repo":"kubernetes/kops","slug":"deleting-public-ip-address-w","errorCode":null,"errorMessage":"deleting public ip address: %w","messagePattern":"deleting public ip address: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/azure/publicipaddress.go","lineNumber":78,"sourceCode":"\tpager := c.c.NewListPager(resourceGroupName, nil)\n\tfor pager.More() {\n\t\tresp, err := pager.NextPage(ctx)\n\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 public ip addresses: %w\", err)\n\t\t}\n\t\tl = append(l, resp.Value...)\n\t}\n\treturn l, nil\n}\n\nfunc (c *publicIPAddressesClientImpl) Delete(ctx context.Context, resourceGroupName, publicIPAddressName string) error {\n\tfuture, err := c.c.BeginDelete(ctx, resourceGroupName, publicIPAddressName, nil)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"deleting public ip address: %w\", err)\n\t}\n\tif _, err := future.PollUntilDone(ctx, nil); err != nil {\n\t\treturn fmt.Errorf(\"waiting for public ip address deletion completion: %w\", err)\n\t}\n\treturn nil\n}\n\nfunc newPublicIPAddressesClientImpl(subscriptionID string, cred *azidentity.DefaultAzureCredential) (*publicIPAddressesClientImpl, error) {\n\tc, err := network.NewPublicIPAddressesClient(subscriptionID, cred, nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"creating public ip addresses client: %w\", err)\n\t}\n\treturn &publicIPAddressesClientImpl{\n\t\tc: c,\n\t}, nil\n}\n","sourceCodeStart":60,"sourceCodeEnd":95,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/azure/publicipaddress.go#L60-L95","documentation":"Wraps the synchronous error from network.PublicIPAddressesClient.BeginDelete. This is the immediate ARM rejection of the delete request — not the asynchronous poll, which produces a separate 'waiting for...' error. The wrapped *azcore.ResponseError carries the ARM error code.","triggerScenarios":"Calling Delete(ctx, resourceGroupName, publicIPAddressName) when c.c.BeginDelete fails immediately: public IP does not exist (ResourceNotFound), name/rg mismatch, RBAC denies Microsoft.Network/publicIPAddresses/delete, or the IP is associated with a NIC/load balancer blocking deletion.","commonSituations":"Deleting a cluster twice (IP already gone); trying to delete a public IP still attached to a load balancer; identity missing Contributor role; typo'd resource group after a region change.","solutions":["Check the wrapped ResponseError: if ResourceNotFound, treat the IP as already deleted and continue","Dissociate the IP from any NIC/load balancer before deleting","Verify the identity has Contributor/Delete permission (Microsoft.Network/publicIPAddresses/delete)","Confirm resourceGroupName and publicIPAddressName match the cluster's tags and Azure naming scheme"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"// verify permissions and existence beforehand\naz group show -n $RG -o none   # ensures group exists and identity can read\naz role assignment list --assignee $PRINCIPAL --include-inherited -o table  # ensure delete rights","typeGuard":"func isNotFound(err error) bool {\n  var re *azcore.ResponseError\n  return errors.As(err, &re) && (re.ErrorCode == \"ResourceNotFound\" || re.StatusCode == 404)\n}","tryCatchPattern":"err := client.Delete(ctx, rg, name)\nvar re *azcore.ResponseError\nif errors.As(err, &re) && re.StatusCode == 404 { return nil /* already deleted */ }\nif err != nil { return fmt.Errorf(\"delete public ip: %w\", err) }","preventionTips":["Treat 404/ResourceNotFound from BeginDelete as success for idempotent teardown","Dissociate IPs from NICs/load balancers before deleting","Ensure Contributor role for the kOps identity","Match names via kOps cluster tags rather than hard-coded strings"],"tags":["azure","delete","public-ip","error-wrapping"],"backgroundTag":"azure-resource-delete-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}