diff --git a/pkg/api/controller.go b/pkg/api/controller.go index 09ca9615..cfd37279 100644 --- a/pkg/api/controller.go +++ b/pkg/api/controller.go @@ -22,6 +22,7 @@ import ( "zotregistry.io/zot/errors" "zotregistry.io/zot/pkg/api/config" ext "zotregistry.io/zot/pkg/extensions" + extconf "zotregistry.io/zot/pkg/extensions/config" "zotregistry.io/zot/pkg/extensions/monitoring" "zotregistry.io/zot/pkg/log" "zotregistry.io/zot/pkg/meta" @@ -286,26 +287,34 @@ func (c *Controller) InitMetaDB(reloadCtx context.Context) error { return nil } -func (c *Controller) LoadNewConfig(reloadCtx context.Context, config *config.Config) { +func (c *Controller) LoadNewConfig(reloadCtx context.Context, newConfig *config.Config) { // reload access control config - c.Config.HTTP.AccessControl = config.HTTP.AccessControl + c.Config.HTTP.AccessControl = newConfig.HTTP.AccessControl - // reload periodical gc interval - c.Config.Storage.GCInterval = config.Storage.GCInterval + // reload periodical gc config + c.Config.Storage.GCInterval = newConfig.Storage.GCInterval + c.Config.Storage.GC = newConfig.Storage.GC + c.Config.Storage.GCDelay = newConfig.Storage.GCDelay + c.Config.Storage.GCReferrers = newConfig.Storage.GCReferrers // reload background tasks - if config.Extensions != nil { + if newConfig.Extensions != nil { + if c.Config.Extensions == nil { + c.Config.Extensions = &extconf.ExtensionConfig{} + } + // reload sync extension - c.Config.Extensions.Sync = config.Extensions.Sync - // reload search cve extension - if c.Config.Extensions.Search != nil { - // reload only if search is enabled and reloaded config has search extension - if *c.Config.Extensions.Search.Enable && config.Extensions.Search != nil { - c.Config.Extensions.Search.CVE = config.Extensions.Search.CVE + c.Config.Extensions.Sync = newConfig.Extensions.Sync + + // reload only if search is enabled and reloaded config has search extension (can't setup routes at this stage) + if c.Config.Extensions.Search != nil && *c.Config.Extensions.Search.Enable { + if newConfig.Extensions.Search != nil { + c.Config.Extensions.Search.CVE = newConfig.Extensions.Search.CVE } } + // reload scrub extension - c.Config.Extensions.Scrub = config.Extensions.Scrub + c.Config.Extensions.Scrub = newConfig.Extensions.Scrub } else { c.Config.Extensions = nil } diff --git a/pkg/extensions/sync/sync_test.go b/pkg/extensions/sync/sync_test.go index 66e74125..f07ac9db 100644 --- a/pkg/extensions/sync/sync_test.go +++ b/pkg/extensions/sync/sync_test.go @@ -1835,9 +1835,6 @@ func TestConfigReloader(t *testing.T) { _, err = cfgfile.WriteString(" ") So(err, ShouldBeNil) - err = cfgfile.Close() - So(err, ShouldBeNil) - time.Sleep(2 * time.Second) data, err := os.ReadFile(logFile.Name()) @@ -1846,6 +1843,64 @@ func TestConfigReloader(t *testing.T) { So(string(data), ShouldContainSubstring, "reloaded params") So(string(data), ShouldContainSubstring, "new configuration settings") So(string(data), ShouldContainSubstring, "\"Extensions\":null") + + // reload config from extensions nil to sync + content = fmt.Sprintf(`{ + "distSpecVersion": "1.1.0-dev", + "storage": { + "rootDirectory": "%s" + }, + "http": { + "address": "127.0.0.1", + "port": "%s" + }, + "log": { + "level": "debug", + "output": "%s" + }, + "extensions": { + "sync": { + "registries": [{ + "urls": ["https://localhost:9999"], + "tlsVerify": true, + "onDemand": true, + "content":[ + { + "prefix": "zot-test", + "tags": { + "regex": ".*", + "semver": true + } + } + ] + }] + } + } + }`, destDir, destPort, logFile.Name()) + + err = cfgfile.Truncate(0) + So(err, ShouldBeNil) + + _, err = cfgfile.Seek(0, 0) + So(err, ShouldBeNil) + + time.Sleep(2 * time.Second) + + _, err = cfgfile.WriteString(content) + So(err, ShouldBeNil) + + err = cfgfile.Close() + So(err, ShouldBeNil) + + time.Sleep(2 * time.Second) + + data, err = os.ReadFile(logFile.Name()) + t.Logf("downstream log: %s", string(data)) + So(err, ShouldBeNil) + So(string(data), ShouldContainSubstring, "reloaded params") + So(string(data), ShouldContainSubstring, "new configuration settings") + So(string(data), ShouldContainSubstring, "\"TLSVerify\":true") + So(string(data), ShouldContainSubstring, "\"OnDemand\":true") }) //nolint: dupl diff --git a/pkg/storage/imagestore/imagestore.go b/pkg/storage/imagestore/imagestore.go index 3b611d2d..b234aa1a 100644 --- a/pkg/storage/imagestore/imagestore.go +++ b/pkg/storage/imagestore/imagestore.go @@ -2040,7 +2040,7 @@ func (is *ImageStore) getOriginalBlob(digest godigest.Digest, duplicateBlobs []s // if we still don't have, search it if originalBlob == "" { - is.log.Warn().Msg("rebuild dedupe: failed to find blob in cache, searching it in s3...") + is.log.Warn().Msg("rebuild dedupe: failed to find blob in cache, searching it in storage...") // a rebuild dedupe was attempted in the past // get original blob, should be found otherwise exit with error