mirror of
https://github.com/project-zot/zot.git
synced 2024-12-16 21:56:37 -05:00
b80deb9927
unified both local and s3 ImageStore logic into a single ImageStore added a new driver interface for common file/dirs manipulations to be implemented by different storage types refactor(gc): drop umoci dependency, implemented internal gc added retentionDelay config option that specifies the garbage collect delay for images without tags this will also clean manifests which are part of an index image (multiarch) that no longer exist. fix(dedupe): skip blobs under .sync/ directory if startup dedupe is running while also syncing is running ignore blobs under sync's temporary storage fix(storage): do not allow image indexes modifications when deleting a manifest verify that it is not part of a multiarch image and throw a MethodNotAllowed error to the client if it is. we don't want to modify multiarch images Signed-off-by: Petu Eusebiu <peusebiu@cisco.com>
92 lines
2.3 KiB
Go
92 lines
2.3 KiB
Go
//go:build scrub
|
|
// +build scrub
|
|
|
|
package extensions
|
|
|
|
import (
|
|
"time"
|
|
|
|
"zotregistry.io/zot/pkg/api/config"
|
|
"zotregistry.io/zot/pkg/extensions/scrub"
|
|
"zotregistry.io/zot/pkg/log"
|
|
"zotregistry.io/zot/pkg/scheduler"
|
|
"zotregistry.io/zot/pkg/storage"
|
|
storageTypes "zotregistry.io/zot/pkg/storage/types"
|
|
)
|
|
|
|
// EnableScrubExtension enables scrub extension.
|
|
func EnableScrubExtension(config *config.Config, log log.Logger, storeController storage.StoreController,
|
|
sch *scheduler.Scheduler,
|
|
) {
|
|
if config.Extensions.Scrub != nil &&
|
|
*config.Extensions.Scrub.Enable {
|
|
minScrubInterval, _ := time.ParseDuration("2h")
|
|
|
|
if config.Extensions.Scrub.Interval < minScrubInterval {
|
|
config.Extensions.Scrub.Interval = minScrubInterval
|
|
|
|
log.Warn().Msg("Scrub interval set to too-short interval < 2h, changing scrub duration to 2 hours and continuing.") //nolint:lll // gofumpt conflicts with lll
|
|
}
|
|
|
|
// is local imagestore (because of umoci dependency which works only locally)
|
|
if config.Storage.StorageDriver == nil {
|
|
generator := &taskGenerator{
|
|
imgStore: storeController.DefaultStore,
|
|
log: log,
|
|
}
|
|
sch.SubmitGenerator(generator, config.Extensions.Scrub.Interval, scheduler.LowPriority)
|
|
}
|
|
|
|
if config.Storage.SubPaths != nil {
|
|
for route := range config.Storage.SubPaths {
|
|
// is local imagestore (because of umoci dependency which works only locally)
|
|
if config.Storage.SubPaths[route].StorageDriver == nil {
|
|
generator := &taskGenerator{
|
|
imgStore: storeController.SubStore[route],
|
|
log: log,
|
|
}
|
|
sch.SubmitGenerator(generator, config.Extensions.Scrub.Interval, scheduler.LowPriority)
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
log.Info().Msg("Scrub config not provided, skipping scrub")
|
|
}
|
|
}
|
|
|
|
type taskGenerator struct {
|
|
imgStore storageTypes.ImageStore
|
|
log log.Logger
|
|
lastRepo string
|
|
done bool
|
|
}
|
|
|
|
func (gen *taskGenerator) Next() (scheduler.Task, error) {
|
|
repo, err := gen.imgStore.GetNextRepository(gen.lastRepo)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if repo == "" {
|
|
gen.done = true
|
|
|
|
return nil, nil
|
|
}
|
|
|
|
gen.lastRepo = repo
|
|
|
|
return scrub.NewTask(gen.imgStore, repo, gen.log), nil
|
|
}
|
|
|
|
func (gen *taskGenerator) IsDone() bool {
|
|
return gen.done
|
|
}
|
|
|
|
func (gen *taskGenerator) IsReady() bool {
|
|
return true
|
|
}
|
|
|
|
func (gen *taskGenerator) Reset() {
|
|
gen.lastRepo = ""
|
|
gen.done = false
|
|
}
|