0
Fork 0
mirror of https://github.com/project-zot/zot.git synced 2024-12-30 22:34:13 -05:00

fix: set GC delay defaults for storage subPaths (#1189)

Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com>
This commit is contained in:
Ramkumar Chinchani 2023-02-14 09:16:37 -08:00 committed by GitHub
parent 0cddb2be3e
commit d79ad863e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 2 deletions

View file

@ -7,7 +7,8 @@
"subPaths": { "subPaths": {
"/infra": { "/infra": {
"rootDirectory": "/tmp/zot1", "rootDirectory": "/tmp/zot1",
"dedupe": true "dedupe": true,
"gc": true
}, },
"/b": { "/b": {
"rootDirectory": "/tmp/zot2", "rootDirectory": "/tmp/zot2",

View file

@ -143,6 +143,7 @@ func newVerifyCmd(conf *config.Config) *cobra.Command {
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
if len(args) > 0 { if len(args) > 0 {
if err := LoadConfiguration(conf, args[0]); err != nil { if err := LoadConfiguration(conf, args[0]); err != nil {
log.Error().Msgf("Config file %s is invalid", args[0])
panic(err) panic(err)
} }
@ -506,7 +507,7 @@ func applyDefaultValues(config *config.Config, viperInstance *viper.Viper) {
config.Storage.GCDelay = 0 config.Storage.GCDelay = 0
} }
// cache // cache settings
// global storage // global storage
@ -549,6 +550,12 @@ func applyDefaultValues(config *config.Config, viperInstance *viper.Viper) {
storageConfig.RemoteCache = false storageConfig.RemoteCache = false
} }
} }
// if gc is enabled and gcDelay is not set, it is set to default value
if storageConfig.GC && !viperInstance.IsSet("storage::subpaths::"+name+"::gcdelay") {
storageConfig.GCDelay = storage.DefaultGCDelay
config.Storage.SubPaths[name] = storageConfig
}
} }
} }
@ -729,6 +736,18 @@ func validateGC(config *config.Config) error {
} }
} }
// subpaths
for name, subPath := range config.Storage.SubPaths {
if subPath.GC && subPath.GCDelay <= 0 {
log.Error().Err(errors.ErrBadConfig).
Str("subPath", name).
Interface("gcDelay", subPath.GCDelay).
Msg("invalid GC delay configuration - cannot be negative or zero")
return errors.ErrBadConfig
}
}
return nil return nil
} }

View file

@ -1053,6 +1053,26 @@ func TestLoadConfig(t *testing.T) {
err = cli.LoadConfiguration(config, tmpfile.Name()) err = cli.LoadConfiguration(config, tmpfile.Name())
So(err, ShouldNotBeNil) So(err, ShouldNotBeNil)
content = []byte(`{"storage":{"rootDirectory":"/tmp/zot",
"subPaths": {"/a": {"rootDirectory": "/zot-a","dedupe":"true","gc":"true","gcDelay":"0s"},
"/b": {"rootDirectory": "/zot-a","dedupe":"true"}}},
"http":{"address":"127.0.0.1","port":"8080","realm":"zot",
"auth":{"htpasswd":{"path":"test/data/htpasswd"},"failDelay":1}}}`)
err = os.WriteFile(tmpfile.Name(), content, 0o0600)
So(err, ShouldBeNil)
err = cli.LoadConfiguration(config, tmpfile.Name())
So(err, ShouldNotBeNil)
content = []byte(`{"storage":{"rootDirectory":"/tmp/zot",
"subPaths": {"/a": {"rootDirectory": "/zot-a","dedupe":"true","gc":"true"},
"/b": {"rootDirectory": "/b","dedupe":"true"}}},
"http":{"address":"127.0.0.1","port":"8080","realm":"zot",
"auth":{"htpasswd":{"path":"test/data/htpasswd"},"failDelay":1}}}`)
err = os.WriteFile(tmpfile.Name(), content, 0o0600)
So(err, ShouldBeNil)
err = cli.LoadConfiguration(config, tmpfile.Name())
So(err, ShouldBeNil)
content = []byte(`{"storage":{"rootDirectory":"/tmp/zot", content = []byte(`{"storage":{"rootDirectory":"/tmp/zot",
"subPaths": {"/a": {"rootDirectory": "/zot-a","dedupe":"true"}, "subPaths": {"/a": {"rootDirectory": "/zot-a","dedupe":"true"},
"/b": {"rootDirectory": "/zot-a","dedupe":"true"}}}, "/b": {"rootDirectory": "/zot-a","dedupe":"true"}}},