mirror of
https://github.com/project-zot/zot.git
synced 2026-06-17 21:17:58 +08:00
dfb5d1df54
* fix: make config read/write thread safe and fix some other similar issues 1. The config config has a lock, and safe methods to update and read the attributes 2. The config has methods to retrieve copies of specific attributes, such as the extyensions config, the auth config, and the authz config. These are needed, as the config object may mutate in the middle of an auth/authz requests, and we avoid partial configuration being applied for that request. 3. Fix an issue with the monitoring server not stopping when the controller is shut down. 4. Fix an issue with the HTPasswdWatcher not stopping when the background tasks are supposed to finish. 5. Fix some tests using hardcoded ports. Moved some of the methods which were on the main config to the auth, access control and extension configs Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>
94 lines
2.2 KiB
Go
94 lines
2.2 KiB
Go
//go:build scrub
|
|
// +build scrub
|
|
|
|
package extensions
|
|
|
|
import (
|
|
"zotregistry.dev/zot/v2/pkg/api/config"
|
|
"zotregistry.dev/zot/v2/pkg/extensions/scrub"
|
|
"zotregistry.dev/zot/v2/pkg/log"
|
|
"zotregistry.dev/zot/v2/pkg/scheduler"
|
|
"zotregistry.dev/zot/v2/pkg/storage"
|
|
storageTypes "zotregistry.dev/zot/v2/pkg/storage/types"
|
|
)
|
|
|
|
// EnableScrubExtension enables scrub extension.
|
|
func EnableScrubExtension(config *config.Config, log log.Logger, storeController storage.StoreController,
|
|
sch *scheduler.Scheduler,
|
|
) {
|
|
// Get extensions config safely
|
|
extensionsConfig := config.CopyExtensionsConfig()
|
|
if extensionsConfig.IsScrubEnabled() {
|
|
scrubInterval := extensionsConfig.GetScrubInterval()
|
|
|
|
processedRepos := make(map[string]struct{})
|
|
|
|
generator := &taskGenerator{
|
|
imgStore: storeController.DefaultStore,
|
|
log: log,
|
|
processedRepos: processedRepos,
|
|
}
|
|
|
|
sch.SubmitGenerator(generator, scrubInterval, scheduler.LowPriority)
|
|
|
|
// Get storage config safely
|
|
storageConfig := config.CopyStorageConfig()
|
|
if storageConfig.SubPaths != nil {
|
|
for route := range storageConfig.SubPaths {
|
|
processedRepos := make(map[string]struct{})
|
|
|
|
generator := &taskGenerator{
|
|
imgStore: storeController.SubStore[route],
|
|
log: log,
|
|
processedRepos: processedRepos,
|
|
}
|
|
|
|
sch.SubmitGenerator(generator, scrubInterval, scheduler.LowPriority)
|
|
}
|
|
}
|
|
} else {
|
|
log.Info().Msg("scrub config not provided, skipping scrub")
|
|
}
|
|
}
|
|
|
|
type taskGenerator struct {
|
|
imgStore storageTypes.ImageStore
|
|
log log.Logger
|
|
processedRepos map[string]struct{}
|
|
done bool
|
|
}
|
|
|
|
func (gen *taskGenerator) Name() string {
|
|
return "ScrubGenerator"
|
|
}
|
|
|
|
func (gen *taskGenerator) Next() (scheduler.Task, error) {
|
|
repo, err := gen.imgStore.GetNextRepository(gen.processedRepos)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if repo == "" {
|
|
gen.done = true
|
|
|
|
return nil, nil //nolint:nilnil
|
|
}
|
|
|
|
gen.processedRepos[repo] = struct{}{}
|
|
|
|
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.processedRepos = make(map[string]struct{})
|
|
gen.done = false
|
|
}
|