{"record":{"id":"fa6245cfdf7aefb4","repo":"kubernetes/kops","slug":"error-deleting-volume-q-v","errorCode":null,"errorMessage":"error deleting Volume %q: %v","messagePattern":"error deleting Volume %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/resources/aws/aws.go","lineNumber":570,"sourceCode":"\tctx := context.TODO()\n\tc := cloud.(awsup.AWSCloud)\n\n\tid := r.ID\n\n\tklog.V(2).Infof(\"Deleting EC2 Volume %q\", id)\n\trequest := &ec2.DeleteVolumeInput{\n\t\tVolumeId: &id,\n\t}\n\t_, err := c.EC2().DeleteVolume(ctx, request)\n\tif err != nil {\n\t\tif awsup.AWSErrorCode(err) == \"InvalidVolume.NotFound\" {\n\t\t\tklog.V(2).Infof(\"Got InvalidVolume.NotFound error deleting Volume %q; will treat as already-deleted\", id)\n\t\t\treturn nil\n\t\t}\n\t\tif IsDependencyViolation(err) {\n\t\t\treturn err\n\t\t}\n\t\treturn fmt.Errorf(\"error deleting Volume %q: %v\", id, err)\n\t}\n\treturn nil\n}\n\nfunc ListVolumes(cloud fi.Cloud, vpcID, clusterName string) ([]*resources.Resource, error) {\n\tctx := context.TODO()\n\tc := cloud.(awsup.AWSCloud)\n\n\tvolumes, err := DescribeVolumes(cloud)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tvar resourceTrackers []*resources.Resource\n\n\telasticIPs := make(map[string]bool)\n\tfor _, volume := range volumes {\n\t\tid := aws.ToString(volume.VolumeId)\n","sourceCodeStart":552,"sourceCodeEnd":588,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/resources/aws/aws.go#L552-L588","documentation":"DeleteVolume wraps any error from the EC2 DeleteVolume API call (other than InvalidVolume.NotFound, which is treated as already-deleted) into a formatted error identifying the volume ID. It propagates dependency violations unchanged via IsDependencyViolation so callers can retry. This error means the AWS API rejected the volume deletion for a reason other than 'volume does not exist'.","triggerScenarios":"EC2 DeleteVolume returns an error for a real volume ID: the volume is attached to an instance, is in a transitional state (creating/deleting), is encrypted with a key the caller cannot use, or a transient AWS/throttling failure occurs.","commonSituations":"Cluster teardown racing with instance termination that still has the EBS volume attached; deleting a volume that is in 'creating' state; IAM policies denying ec2:DeleteVolume; EC2 API throttling during large deletions.","solutions":["Detach the volume from its instance first (or wait for the instance to terminate), then retry the delete.","Wait until the volume leaves a transitional state (creating/deleting) before retrying.","Check IAM permissions for ec2:DeleteVolume on the volume/CMK, and fix the policy.","Retry after backoff if the cause is throttling or a transient AWS error."],"exampleFix":"// before\nerr := DeleteVolume(cloud, id)\nif err != nil { return err }\n// after\nvol, _ := FindVolume(cloud, id)\nfor _, a := range vol.Attachments { DetachVolume(cloud, *a.VolumeId) }\nWaitUntilVolumeAvailable(cloud, id)\nerr := DeleteVolume(cloud, id)","handlingStrategy":"retry","validationCode":"vol, err := ec2Client.DescribeVolumes(ctx, &ec2.DescribeVolumesInput{VolumeIds: []string{id}})\nif err != nil || len(vol.Volumes) == 0 { return nil }\nfor _, a := range vol.Volumes[0].Attachments {\n  if aws.ToString(a.State) != \"detached\" { return fmt.Errorf(\"volume %s still attached\", id) }\n}","typeGuard":"func isDependencyViolation(err error) bool { var ae smithy.APIError; return errors.As(err, &ae) && ae.ErrorCode() == \"VolumeInUse\" }","tryCatchPattern":"err := DeleteVolume(cloud, id)\nvar ae smithy.APIError\nif errors.As(err, &ae) && ae.ErrorCode() == \"VolumeInUse\" {\n  // detach then retry with backoff\n} else if err != nil {\n  return err\n}","preventionTips":["Ensure instances referencing the volume are terminated before cluster teardown.","Poll volume state until 'available' before calling DeleteVolume.","Use eksctl-style orphan-resource sweeps for leftover ENIs/attachments.","Confirm IAM allows ec2:DeleteVolume and the KMS key policy permits use."],"tags":["aws","ec2","ebs","volume-deletion"],"backgroundTag":"aws-dependency-violation","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"}