mirror of
https://github.com/project-zot/zot.git
synced 2026-06-17 04:48:26 +08:00
feat(sync): sync can include self url in registry.URLs (#1562)
sync now ignores self referencing urls, this will help in clustering mode where we can have the same config for multiple zots closes #1335 Signed-off-by: Petu Eusebiu <peusebiu@cisco.com>
This commit is contained in:
@@ -125,7 +125,7 @@ func (service *BaseService) SetNextAvailableClient() error {
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
continue
|
||||
}
|
||||
|
||||
if !service.client.IsAvailable() {
|
||||
|
||||
@@ -802,6 +802,14 @@ func TestOnDemand(t *testing.T) {
|
||||
regex := ".*"
|
||||
semver := true
|
||||
|
||||
destPort := test.GetFreePort()
|
||||
destConfig := config.New()
|
||||
|
||||
destBaseURL := test.GetBaseURL(destPort)
|
||||
|
||||
hostname, err := os.Hostname()
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
syncRegistryConfig := syncconf.RegistryConfig{
|
||||
Content: []syncconf.Content{
|
||||
{
|
||||
@@ -812,7 +820,11 @@ func TestOnDemand(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
URLs: []string{srcBaseURL},
|
||||
// include self url, should be ignored
|
||||
URLs: []string{
|
||||
fmt.Sprintf("http://%s", hostname), destBaseURL,
|
||||
srcBaseURL, fmt.Sprintf("http://localhost:%s", destPort),
|
||||
},
|
||||
TLSVerify: &tlsVerify,
|
||||
CertDir: "",
|
||||
OnDemand: true,
|
||||
@@ -824,11 +836,6 @@ func TestOnDemand(t *testing.T) {
|
||||
Registries: []syncconf.RegistryConfig{syncRegistryConfig},
|
||||
}
|
||||
|
||||
destPort := test.GetFreePort()
|
||||
destConfig := config.New()
|
||||
|
||||
destBaseURL := test.GetBaseURL(destPort)
|
||||
|
||||
destConfig.HTTP.Port = destPort
|
||||
|
||||
destDir := t.TempDir()
|
||||
@@ -3384,7 +3391,7 @@ func TestMultipleURLs(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
URLs: []string{"badURL", "http://invalid.invalid/invalid/", srcBaseURL},
|
||||
URLs: []string{"badURL", "@!#!$#@%", "http://invalid.invalid/invalid/", srcBaseURL},
|
||||
PollInterval: updateDuration,
|
||||
TLSVerify: &tlsVerify,
|
||||
CertDir: "",
|
||||
@@ -3438,6 +3445,49 @@ func TestMultipleURLs(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestNoURLsLeftInConfig(t *testing.T) {
|
||||
Convey("Verify sync feature", t, func() {
|
||||
updateDuration, _ := time.ParseDuration("30m")
|
||||
|
||||
regex := ".*"
|
||||
semver := true
|
||||
var tlsVerify bool
|
||||
|
||||
syncRegistryConfig := syncconf.RegistryConfig{
|
||||
Content: []syncconf.Content{
|
||||
{
|
||||
Prefix: testImage,
|
||||
Tags: &syncconf.Tags{
|
||||
Regex: ®ex,
|
||||
Semver: &semver,
|
||||
},
|
||||
},
|
||||
},
|
||||
URLs: []string{"@!#!$#@%", "@!#!$#@%"},
|
||||
PollInterval: updateDuration,
|
||||
TLSVerify: &tlsVerify,
|
||||
CertDir: "",
|
||||
}
|
||||
|
||||
defaultVal := true
|
||||
syncConfig := &syncconf.Config{
|
||||
Enable: &defaultVal,
|
||||
Registries: []syncconf.RegistryConfig{syncRegistryConfig},
|
||||
}
|
||||
|
||||
dctlr, destBaseURL, _, destClient := makeDownstreamServer(t, false, syncConfig)
|
||||
|
||||
dcm := test.NewControllerManager(dctlr)
|
||||
dcm.StartAndWait(dctlr.Config.HTTP.Port)
|
||||
defer dcm.StopServer()
|
||||
|
||||
resp, err := destClient.R().Get(destBaseURL + "/v2/" + testImage + "/tags/list")
|
||||
So(err, ShouldBeNil)
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusNotFound)
|
||||
})
|
||||
}
|
||||
|
||||
func TestPeriodicallySignaturesErr(t *testing.T) {
|
||||
Convey("Verify sync periodically signatures errors", t, func() {
|
||||
updateDuration, _ := time.ParseDuration("30m")
|
||||
|
||||
Reference in New Issue
Block a user