Pruner fails if there are any unexpected files or directory structure
Currently the pruner simply walks the all the paths in the repositories
tree (see repositories.go) and expects the tree to be well-formed.
In particular, process
simply passes path segments to other parts of the code.
This means that if for example there is a file at a tree level where only folders are expected it can lead to a panic.
Here is an example where there was a regular file in the tags
directory (/var/opt/gitlab/gitlab-rails/shared/registry/docker/registry/v2/repositories/microservices.core/mailserver/_manifests/tags
), where only folders are expected. This causes addTag
to fail.
panic: runtime error: index out of range
goroutine 8 [running]:
main.(*repositoryData).addTag(0xc420340aa0, 0xc4203c53f0, 0x1, 0x1, 0xc420377320, 0x8b, 0x146c, 0x0, 0x0, 0x0, ...)
/root/go/src/gitlab.com/gitlab-org/docker-distribution-pruner/repository.go:286 +0x2e5
main.(*repositoryData).addManifest(0xc420340aa0, 0xc4203c53e0, 0x2, 0x2, 0xc420377320, 0x8b, 0x146c, 0x0, 0x0, 0x0, ...)
/root/go/src/gitlab.com/gitlab-org/docker-distribution-pruner/repository.go:306 +0x19c
main.repositoriesData.process(0xc420328210, 0xc4203c53b0, 0x5, 0x5, 0xc420377320, 0x8b, 0x146c, 0x0, 0x0, 0x0, ...)
/root/go/src/gitlab.com/gitlab-org/docker-distribution-pruner/repositories.go:42 +0x1c8
main.repositoriesData.walkPath.func1.1(0xc400000008, 0x81a230)
/root/go/src/gitlab.com/gitlab-org/docker-distribution-pruner/repositories.go:56 +0xe6
main.(*jobGroup).dispatch.func1()
/root/go/src/gitlab.com/gitlab-org/docker-distribution-pruner/job_group.go:27 +0xa6
main.jobsData.run.func1(0xc4201f0d20)
/root/go/src/gitlab.com/gitlab-org/docker-distribution-pruner/jobs.go:13 +0x66
created by main.jobsData.run
/root/go/src/gitlab.com/gitlab-org/docker-distribution-pruner/jobs.go:15 +0x4e
The pruner should handle such failures more gracefully, or at the very least give a clue as to what path was at fault.