{"record":{"id":"6fc44effd9b71006","repo":"kubernetes/kops","slug":"error-deleting-dhcpoptions-q-v","errorCode":null,"errorMessage":"error deleting DhcpOptions %q: %v","messagePattern":"error deleting DhcpOptions %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/resources/aws/aws.go","lineNumber":949,"sourceCode":"func DeleteDhcpOptions(cloud fi.Cloud, r *resources.Resource) error {\n\tctx := context.TODO()\n\tc := cloud.(awsup.AWSCloud)\n\n\tid := r.ID\n\n\tklog.V(2).Infof(\"Deleting EC2 DhcpOptions %q\", id)\n\trequest := &ec2.DeleteDhcpOptionsInput{\n\t\tDhcpOptionsId: &id,\n\t}\n\t_, err := c.EC2().DeleteDhcpOptions(ctx, request)\n\tif err != nil {\n\t\tif awsup.AWSErrorCode(err) == \"InvalidDhcpOptionsID.NotFound\" {\n\t\t\tklog.V(2).Infof(\"Got InvalidDhcpOptionsID.NotFound error deleting DhcpOptions %q; will treat as already-deleted\", id)\n\t\t\treturn nil\n\t\t} else if IsDependencyViolation(err) {\n\t\t\treturn err\n\t\t}\n\t\treturn fmt.Errorf(\"error deleting DhcpOptions %q: %v\", id, err)\n\t}\n\treturn nil\n}\n\nfunc ListDhcpOptions(cloud fi.Cloud, vpcID, clusterName string) ([]*resources.Resource, error) {\n\tdhcpOptions, err := DescribeDhcpOptions(cloud)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tvar resourceTrackers []*resources.Resource\n\n\tfor _, o := range dhcpOptions {\n\t\tresourceTracker := &resources.Resource{\n\t\t\tName:    FindName(o.Tags),\n\t\t\tID:      aws.ToString(o.DhcpOptionsId),\n\t\t\tType:    \"dhcp-options\",\n\t\t\tDeleter: DeleteDhcpOptions,","sourceCodeStart":931,"sourceCodeEnd":967,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/resources/aws/aws.go#L931-L967","documentation":"kOps wraps failures from the EC2 DeleteDhcpOptions API. NotFound is treated as already-deleted and dependency violations are returned bare for retry; anything else is wrapped with the DHCP options set ID. The DHCP options set could not be deleted for another reason.","triggerScenarios":"EC2 DeleteDhcpOptions returns an error that is neither InvalidDhcpOptionsID.NotFound nor a dependency violation: throttling, auth failure, or an invalid options-set ID format.","commonSituations":"Bulk cluster teardown hitting EC2 rate limits; IAM policy missing ec2:DeleteDhcpOptions; stale resource trackers referencing a set already removed by another cleanup run.","solutions":["Confirm current state with `aws ec2 describe-dhcp-options --dhcp-options-ids <id>`; if absent, treat as deleted and continue","Wait for retry — if the real cause is a dependency violation, kOps' caller retries until the VPC is deleted","Grant the identity ec2:DeleteDhcpOptions in IAM","Retry the whole kOps delete; the flow is idempotent"],"exampleFix":"// before\nreturn fmt.Errorf(\"error deleting DhcpOptions %q: %v\", id, err)\n// after (caller side)\nif strings.Contains(err.Error(), \"Throttling\") {\n\ttime.Sleep(backoff)\n\treturn retry()\n}","handlingStrategy":"retry","validationCode":"// check existence before delete\nout, err := c.EC2().DescribeDhcpOptions(ctx, &ec2.DescribeDhcpOptionsInput{\n\tDhcpOptionsIds: []string{id},\n})\nif err != nil { return err }\nif len(out.DhcpOptions) == 0 { return nil } // already gone","typeGuard":"func dhcpOptionsExists(out *ec2.DescribeDhcpOptionsOutput) bool {\n\treturn out != nil && len(out.DhcpOptions) > 0\n}","tryCatchPattern":"if err != nil {\n\tswitch {\n\tcase awsup.AWSErrorCode(err) == \"InvalidDhcpOptionsID.NotFound\":\n\t\treturn nil\n\tcase awserrors.IsDependencyViolation(err):\n\t\treturn backoff.Retry(func() error { return retryDelete() }, expBackoff)\n\tdefault:\n\t\treturn fmt.Errorf(\"error deleting DhcpOptions %q: %v\", id, err)\n\t}\n}","preventionTips":["Re-run kops delete after transient failures; DHCP options cleanup is idempotent","Ensure IAM grants ec2:DeleteDhcpOptions","Never delete a DHCP options set manually while kOps teardown is in progress","Wait for dependent VPC deletions to finish before forcing cleanup"],"tags":["aws","ec2","dhcp-options","delete"],"backgroundTag":"aws-api-request-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"}