mirror of
https://github.com/project-zot/zot.git
synced 2026-06-15 20:07:55 +08:00
gc: add a gcDelay param
Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com>
This commit is contained in:
committed by
Ramkumar Chinchani
parent
35eeedb22a
commit
38a110314b
@@ -221,6 +221,18 @@ func NewCliRootCmd() *cobra.Command {
|
||||
}
|
||||
|
||||
func validateConfiguration(config *config.Config) {
|
||||
// enforce GC params
|
||||
if config.Storage.GCDelay < 0 {
|
||||
log.Error().Err(errors.ErrBadConfig).
|
||||
Msgf("invalid garbage-collect delay %v specified", config.Storage.GCDelay)
|
||||
panic(errors.ErrBadConfig)
|
||||
}
|
||||
|
||||
if !config.Storage.GC && config.Storage.GCDelay != 0 {
|
||||
log.Warn().Err(errors.ErrBadConfig).
|
||||
Msg("garbage-collect delay specified without enabling garbage-collect, will be ignored")
|
||||
}
|
||||
|
||||
// check authorization config, it should have basic auth enabled or ldap
|
||||
if config.HTTP.RawAccessControl != nil {
|
||||
if config.HTTP.Auth == nil || (config.HTTP.Auth.HTPasswd.Path == "" && config.HTTP.Auth.LDAP == nil) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package cli_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@@ -14,6 +15,7 @@ import (
|
||||
"zotregistry.io/zot/pkg/api"
|
||||
"zotregistry.io/zot/pkg/api/config"
|
||||
"zotregistry.io/zot/pkg/cli"
|
||||
"zotregistry.io/zot/pkg/storage"
|
||||
. "zotregistry.io/zot/pkg/test"
|
||||
)
|
||||
|
||||
@@ -300,6 +302,55 @@ func TestLoadConfig(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestGC(t *testing.T) {
|
||||
Convey("Test GC config", t, func(c C) {
|
||||
config := config.New()
|
||||
So(func() { cli.LoadConfiguration(config, "../../examples/config-multiple.json") }, ShouldNotPanic)
|
||||
So(config.Storage.GCDelay, ShouldEqual, storage.DefaultGCDelay)
|
||||
So(func() { cli.LoadConfiguration(config, "../../examples/config-gc.json") }, ShouldNotPanic)
|
||||
So(config.Storage.GCDelay, ShouldNotEqual, storage.DefaultGCDelay)
|
||||
})
|
||||
|
||||
Convey("Test GC config corner cases", t, func(c C) {
|
||||
contents, err := ioutil.ReadFile("../../examples/config-gc.json")
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
Convey("GC delay without GC", func() {
|
||||
config := config.New()
|
||||
err = json.Unmarshal(contents, config)
|
||||
config.Storage.GC = false
|
||||
|
||||
file, err := ioutil.TempFile("", "gc-config-*.json")
|
||||
So(err, ShouldBeNil)
|
||||
defer os.Remove(file.Name())
|
||||
|
||||
contents, err = json.MarshalIndent(config, "", " ")
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = ioutil.WriteFile(file.Name(), contents, 0o600)
|
||||
So(err, ShouldBeNil)
|
||||
So(func() { cli.LoadConfiguration(config, file.Name()) }, ShouldNotPanic)
|
||||
})
|
||||
|
||||
Convey("Negative GC delay", func() {
|
||||
config := config.New()
|
||||
err = json.Unmarshal(contents, config)
|
||||
config.Storage.GCDelay = -1 * time.Second
|
||||
|
||||
file, err := ioutil.TempFile("", "gc-config-*.json")
|
||||
So(err, ShouldBeNil)
|
||||
defer os.Remove(file.Name())
|
||||
|
||||
contents, err = json.MarshalIndent(config, "", " ")
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = ioutil.WriteFile(file.Name(), contents, 0o600)
|
||||
So(err, ShouldBeNil)
|
||||
So(func() { cli.LoadConfiguration(config, file.Name()) }, ShouldPanic)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestScrub(t *testing.T) {
|
||||
oldArgs := os.Args
|
||||
|
||||
|
||||
Reference in New Issue
Block a user