mirror of
https://github.com/project-zot/zot.git
synced 2025-02-17 23:45:36 -05:00
fix(config): fix config reloader panic (#1806)
reloading config from one without extensions to one with extensions caused a panic Signed-off-by: Petu Eusebiu <peusebiu@cisco.com>
This commit is contained in:
parent
3dbaf2b3ff
commit
3d8d47d601
3 changed files with 80 additions and 16 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue