{"record":{"id":"95300eb9bc76f029","repo":"kubernetes/kops","slug":"error-listing-all-versions-of-file-s-v","errorCode":null,"errorMessage":"error listing all versions of file %s: %v","messagePattern":"error listing all versions of file (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"util/pkg/vfs/s3fs.go","lineNumber":198,"sourceCode":"\tclient, err := p.client(ctx)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tklog.V(8).Infof(\"removing all versions of file %s\", p)\n\n\trequest := &s3.ListObjectVersionsInput{\n\t\tBucket: aws.String(p.bucket),\n\t\tPrefix: aws.String(p.key),\n\t}\n\n\tvar versions []types.ObjectVersion\n\tvar deleteMarkers []types.DeleteMarkerEntry\n\tpaginator := s3.NewListObjectVersionsPaginator(client, request)\n\tfor paginator.HasMorePages() {\n\t\tpage, err := paginator.NextPage(ctx)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error listing all versions of file %s: %v\", p, err)\n\t\t}\n\t\tfor _, version := range page.Versions {\n\t\t\tif aws.ToString(version.Key) == p.key {\n\t\t\t\tversions = append(versions, version)\n\t\t\t}\n\t\t}\n\t\tfor _, marker := range page.DeleteMarkers {\n\t\t\tif aws.ToString(marker.Key) == p.key {\n\t\t\t\tdeleteMarkers = append(deleteMarkers, marker)\n\t\t\t}\n\t\t}\n\t}\n\n\tif len(versions) == 0 && len(deleteMarkers) == 0 {\n\t\treturn os.ErrNotExist\n\t}\n\n\tvar objects []types.ObjectIdentifier","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/util/pkg/vfs/s3fs.go#L180-L216","documentation":"RemoveAllVersions lists every version and delete marker of an object using the ListObjectVersions paginator so it can delete them all. If any page of the pagination fails, the error is wrapped as \"error listing all versions of file <path>\".","triggerScenarios":"Calling RemoveAllVersions on a versioning-enabled S3 bucket when ListObjectVersions fails: IAM policy missing s3:ListBucketVersions; throttling on buckets with very many versions; network failure mid-pagination.","commonSituations":"State-store buckets with versioning enabled (recommended by kOps) and restrictive IAM roles; buckets with huge version history causing slow/paged listing that hits limits.","solutions":["Grant s3:ListBucketVersions (and s3:ListBucket) on the bucket to the operating principal","Retry on transient errors; pagination resumes by rerunning the operation","Reduce version sprawl with lifecycle rules so listings stay small","Check bucket region/client config if the error indicates wrong endpoint"],"exampleFix":"// before\nif err != nil { return fmt.Errorf(\"error listing all versions of file %s: %v\", p, err) }\n// after (caller): pre-check permission/availability\n_, err := s3Client.ListObjectVersions(ctx, &s3.ListObjectVersionsInput{Bucket: bucket, MaxKeys: aws.Int32(1)})\nif err != nil { return fmt.Errorf(\"state store not listable: %w\", err) }","handlingStrategy":"retry","validationCode":"_, err := s3Client.ListObjectVersions(ctx, &s3.ListObjectVersionsInput{Bucket: bucket, MaxKeys: aws.Int32(1)})\nif err != nil { return fmt.Errorf(\"state store not listable (need s3:ListBucketVersions): %w\", err) }","typeGuard":null,"tryCatchPattern":"err := wait.ExponentialBackoff(listBackoff, func() (bool, error) {\n\treturn p.RemoveAllVersions(ctx) == nil, nil\n})","preventionTips":["Grant s3:ListBucket and s3:ListBucketVersions on the bucket","Enable lifecycle rules to cap version history","Retry pagination errors — the operation is safe to re-run (idempotent deletes)"],"tags":["aws","s3","versioning","iam","pagination"],"backgroundTag":"s3-list-versions-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"}