From 7c3bf86a6b2dfb66c93c9f46933f861798e3a6ee Mon Sep 17 00:00:00 2001 From: Bogdan Bivolaru <104334+bogdanbiv@users.noreply.github.com> Date: Thu, 16 Feb 2023 08:20:28 +0200 Subject: [PATCH] refactor: Centralise extensions config entries (#1177) Except for registry sync config Signed-off-by: Bogdan BIVOLARU <104334+bogdanbiv@users.noreply.github.com> --- pkg/extensions/config/config.go | 2 +- pkg/extensions/config/sync/config.go | 43 ++ pkg/extensions/extensions_test.go | 6 +- pkg/extensions/sync/on_demand.go | 10 +- pkg/extensions/sync/signatures.go | 6 +- pkg/extensions/sync/sync.go | 59 +-- pkg/extensions/sync/sync_disabled_test.go | 4 +- pkg/extensions/sync/sync_internal_test.go | 76 ++-- pkg/extensions/sync/sync_test.go | 485 +++++++++++----------- pkg/extensions/sync/utils.go | 13 +- 10 files changed, 360 insertions(+), 344 deletions(-) create mode 100644 pkg/extensions/config/sync/config.go diff --git a/pkg/extensions/config/config.go b/pkg/extensions/config/config.go index 043b5832..fc06f342 100644 --- a/pkg/extensions/config/config.go +++ b/pkg/extensions/config/config.go @@ -3,7 +3,7 @@ package config import ( "time" - "zotregistry.io/zot/pkg/extensions/sync" + "zotregistry.io/zot/pkg/extensions/config/sync" ) // BaseConfig has params applicable to all extensions. diff --git a/pkg/extensions/config/sync/config.go b/pkg/extensions/config/sync/config.go new file mode 100644 index 00000000..96c1361d --- /dev/null +++ b/pkg/extensions/config/sync/config.go @@ -0,0 +1,43 @@ +package sync + +import ( + "time" +) + +// key is registry address. +type CredentialsFile map[string]Credentials + +type Credentials struct { + Username string + Password string +} + +type Config struct { + Enable *bool + CredentialsFile string + Registries []RegistryConfig +} + +type RegistryConfig struct { + URLs []string + PollInterval time.Duration + Content []Content + TLSVerify *bool + OnDemand bool + CertDir string + MaxRetries *int + RetryDelay *time.Duration + OnlySigned *bool +} + +type Content struct { + Prefix string + Tags *Tags + Destination string `mapstructure:",omitempty"` + StripPrefix bool +} + +type Tags struct { + Regex *string + Semver *bool +} diff --git a/pkg/extensions/extensions_test.go b/pkg/extensions/extensions_test.go index eca93b96..098192df 100644 --- a/pkg/extensions/extensions_test.go +++ b/pkg/extensions/extensions_test.go @@ -12,7 +12,7 @@ import ( "zotregistry.io/zot/pkg/api" "zotregistry.io/zot/pkg/api/config" extconf "zotregistry.io/zot/pkg/extensions/config" - "zotregistry.io/zot/pkg/extensions/sync" + syncconf "zotregistry.io/zot/pkg/extensions/config/sync" "zotregistry.io/zot/pkg/test" ) @@ -23,9 +23,9 @@ func TestEnableExtension(t *testing.T) { conf := config.New() falseValue := false - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &falseValue, - Registries: []sync.RegistryConfig{}, + Registries: []syncconf.RegistryConfig{}, } // conf.Extensions.Sync.Enable = &falseValue diff --git a/pkg/extensions/sync/on_demand.go b/pkg/extensions/sync/on_demand.go index 59c5ce43..fb9fbb8a 100644 --- a/pkg/extensions/sync/on_demand.go +++ b/pkg/extensions/sync/on_demand.go @@ -16,6 +16,7 @@ import ( ispec "github.com/opencontainers/image-spec/specs-go/v1" "zotregistry.io/zot/pkg/common" + syncconf "zotregistry.io/zot/pkg/extensions/config/sync" "zotregistry.io/zot/pkg/log" "zotregistry.io/zot/pkg/storage" ) @@ -58,7 +59,7 @@ func (di *demandedImages) delete(key string) { di.syncedMap.Delete(key) } -func OneImage(ctx context.Context, cfg Config, storeController storage.StoreController, +func OneImage(ctx context.Context, cfg syncconf.Config, storeController storage.StoreController, repo, reference string, artifactType string, log log.Logger, ) error { // guard against multiple parallel requests @@ -91,10 +92,11 @@ func OneImage(ctx context.Context, cfg Config, storeController storage.StoreCont return err } -func syncOneImage(ctx context.Context, imageChannel chan error, cfg Config, storeController storage.StoreController, +func syncOneImage(ctx context.Context, imageChannel chan error, + cfg syncconf.Config, storeController storage.StoreController, localRepo, reference string, artifactType string, log log.Logger, ) { - var credentialsFile CredentialsFile + var credentialsFile syncconf.CredentialsFile if cfg.CredentialsFile != "" { var err error @@ -258,7 +260,7 @@ func syncOneImage(ctx context.Context, imageChannel chan error, cfg Config, stor imageChannel <- nil } -func syncRun(regCfg RegistryConfig, +func syncRun(regCfg syncconf.RegistryConfig, localRepo, upstreamRepo, reference string, utils syncContextUtils, sig *signaturesCopier, log log.Logger, ) (bool, error) { diff --git a/pkg/extensions/sync/signatures.go b/pkg/extensions/sync/signatures.go index 33908fe7..095e1310 100644 --- a/pkg/extensions/sync/signatures.go +++ b/pkg/extensions/sync/signatures.go @@ -18,6 +18,7 @@ import ( zerr "zotregistry.io/zot/errors" "zotregistry.io/zot/pkg/api/constants" "zotregistry.io/zot/pkg/common" + syncconf "zotregistry.io/zot/pkg/extensions/config/sync" "zotregistry.io/zot/pkg/log" "zotregistry.io/zot/pkg/storage" ) @@ -26,11 +27,12 @@ type signaturesCopier struct { client *http.Client upstreamURL url.URL storeController storage.StoreController - credentials Credentials + credentials syncconf.Credentials log log.Logger } -func newSignaturesCopier(httpClient *http.Client, credentials Credentials, upstreamURL url.URL, +func newSignaturesCopier(httpClient *http.Client, credentials syncconf.Credentials, + upstreamURL url.URL, storeController storage.StoreController, log log.Logger, ) *signaturesCopier { return &signaturesCopier{ diff --git a/pkg/extensions/sync/sync.go b/pkg/extensions/sync/sync.go index f04cd890..3bfb7a36 100644 --- a/pkg/extensions/sync/sync.go +++ b/pkg/extensions/sync/sync.go @@ -23,6 +23,7 @@ import ( zerr "zotregistry.io/zot/errors" "zotregistry.io/zot/pkg/api/constants" "zotregistry.io/zot/pkg/common" + syncconf "zotregistry.io/zot/pkg/extensions/config/sync" "zotregistry.io/zot/pkg/log" "zotregistry.io/zot/pkg/storage" "zotregistry.io/zot/pkg/test" @@ -38,44 +39,6 @@ type catalog struct { Repositories []string `json:"repositories"` } -// key is registry address. -type CredentialsFile map[string]Credentials - -type Credentials struct { - Username string - Password string -} - -type Config struct { - Enable *bool - CredentialsFile string - Registries []RegistryConfig -} - -type RegistryConfig struct { - URLs []string - PollInterval time.Duration - Content []Content - TLSVerify *bool - OnDemand bool - CertDir string - MaxRetries *int - RetryDelay *time.Duration - OnlySigned *bool -} - -type Content struct { - Prefix string - Tags *Tags - Destination string `mapstructure:",omitempty"` - StripPrefix bool -} - -type Tags struct { - Regex *string - Semver *bool -} - type RepoReferences struct { contentID int // matched registry config content name string // repo name @@ -103,7 +66,7 @@ func GetUpstreamCatalog(client *http.Client, upstreamURL, username, password str // imagesToCopyFromRepos lists all images given a registry name and its repos. func imagesToCopyFromUpstream(ctx context.Context, registryName string, repoName string, - upstreamCtx *types.SystemContext, content Content, log log.Logger, + upstreamCtx *types.SystemContext, content syncconf.Content, log log.Logger, ) ([]types.ImageReference, error) { imageRefs := []types.ImageReference{} @@ -179,7 +142,7 @@ func getCopyOptions(upstreamCtx, localCtx *types.SystemContext) copy.Options { return options } -func getUpstreamContext(regCfg *RegistryConfig, credentials Credentials) *types.SystemContext { +func getUpstreamContext(regCfg *syncconf.RegistryConfig, credentials syncconf.Credentials) *types.SystemContext { upstreamCtx := &types.SystemContext{} upstreamCtx.DockerCertPath = regCfg.CertDir upstreamCtx.DockerDaemonCertPath = regCfg.CertDir @@ -192,7 +155,7 @@ func getUpstreamContext(regCfg *RegistryConfig, credentials Credentials) *types. upstreamCtx.DockerInsecureSkipTLSVerify = types.NewOptionalBool(true) } - if credentials != (Credentials{}) { + if credentials != (syncconf.Credentials{}) { upstreamCtx.DockerAuthConfig = &types.DockerAuthConfig{ Username: credentials.Username, Password: credentials.Password, @@ -203,10 +166,10 @@ func getUpstreamContext(regCfg *RegistryConfig, credentials Credentials) *types. } //nolint:gocyclo // offloading some of the functionalities from here would make the code harder to follow -func syncRegistry(ctx context.Context, regCfg RegistryConfig, +func syncRegistry(ctx context.Context, regCfg syncconf.RegistryConfig, upstreamURL string, storeController storage.StoreController, localCtx *types.SystemContext, - policyCtx *signature.PolicyContext, credentials Credentials, + policyCtx *signature.PolicyContext, credentials syncconf.Credentials, retryOptions *retry.RetryOptions, log log.Logger, ) error { log.Info().Msgf("syncing registry: %s", upstreamURL) @@ -266,8 +229,8 @@ func syncRegistry(ctx context.Context, regCfg RegistryConfig, var imageReferences []types.ImageReference if err = retry.RetryIfNecessary(ctx, func() error { - imageReferences, err = imagesToCopyFromUpstream(ctx, upstreamAddr, repoName, upstreamCtx, - regCfg.Content[contentID], log) + imageReferences, err = imagesToCopyFromUpstream(ctx, upstreamAddr, + repoName, upstreamCtx, regCfg.Content[contentID], log) return err }, retryOptions); err != nil { @@ -458,11 +421,11 @@ func getLocalContexts(log log.Logger) (*types.SystemContext, *signature.PolicyCo return localCtx, policyContext, nil } -func Run(ctx context.Context, cfg Config, +func Run(ctx context.Context, cfg syncconf.Config, storeController storage.StoreController, wtgrp *goSync.WaitGroup, logger log.Logger, ) error { - var credentialsFile CredentialsFile + var credentialsFile syncconf.CredentialsFile var err error @@ -509,7 +472,7 @@ func Run(ctx context.Context, cfg Config, } // schedule each registry sync - go func(ctx context.Context, regCfg RegistryConfig, logger log.Logger) { + go func(ctx context.Context, regCfg syncconf.RegistryConfig, logger log.Logger) { for { // increment reference since will be busy, so shutdown has to wait wtgrp.Add(1) diff --git a/pkg/extensions/sync/sync_disabled_test.go b/pkg/extensions/sync/sync_disabled_test.go index 11c63fc1..e506b786 100644 --- a/pkg/extensions/sync/sync_disabled_test.go +++ b/pkg/extensions/sync/sync_disabled_test.go @@ -13,7 +13,7 @@ import ( "zotregistry.io/zot/pkg/api" "zotregistry.io/zot/pkg/api/config" extconf "zotregistry.io/zot/pkg/extensions/config" - "zotregistry.io/zot/pkg/extensions/sync" + syncconf "zotregistry.io/zot/pkg/extensions/config/sync" "zotregistry.io/zot/pkg/test" ) @@ -34,7 +34,7 @@ func TestSyncExtension(t *testing.T) { conf.Storage.RootDirectory = globalDir conf.Storage.Commit = true conf.Extensions = &extconf.ExtensionConfig{} - conf.Extensions.Sync = &sync.Config{ + conf.Extensions.Sync = &syncconf.Config{ Enable: &defaultValue, } conf.Log.Level = "warn" diff --git a/pkg/extensions/sync/sync_internal_test.go b/pkg/extensions/sync/sync_internal_test.go index 836d4ea6..6d6fd24d 100644 --- a/pkg/extensions/sync/sync_internal_test.go +++ b/pkg/extensions/sync/sync_internal_test.go @@ -24,6 +24,7 @@ import ( "zotregistry.io/zot/errors" . "zotregistry.io/zot/pkg/common" + syncconf "zotregistry.io/zot/pkg/extensions/config/sync" "zotregistry.io/zot/pkg/extensions/monitoring" "zotregistry.io/zot/pkg/log" "zotregistry.io/zot/pkg/storage" @@ -133,8 +134,8 @@ func TestSyncInternal(t *testing.T) { updateDuration := time.Microsecond port := test.GetFreePort() baseURL := test.GetBaseURL(port) - syncRegistryConfig := RegistryConfig{ - Content: []Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: testImage, }, @@ -146,8 +147,8 @@ func TestSyncInternal(t *testing.T) { } defaultValue := true - cfg := Config{ - Registries: []RegistryConfig{syncRegistryConfig}, + cfg := syncconf.Config{ + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, Enable: &defaultValue, CredentialsFile: "/invalid/path/to/file", } @@ -165,8 +166,8 @@ func TestSyncInternal(t *testing.T) { updateDuration := time.Microsecond port := test.GetFreePort() baseURL := test.GetBaseURL(port) - syncRegistryConfig := RegistryConfig{ - Content: []Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: testImage, }, @@ -190,7 +191,8 @@ func TestSyncInternal(t *testing.T) { So(err, ShouldBeNil) err = syncRegistry(ctx, syncRegistryConfig, "randomUpstreamURL", - storage.StoreController{DefaultStore: imageStore}, localCtx, policyCtx, Credentials{}, nil, log) + storage.StoreController{DefaultStore: imageStore}, localCtx, policyCtx, + syncconf.Credentials{}, nil, log) So(err, ShouldNotBeNil) }) @@ -240,8 +242,8 @@ func TestSyncInternal(t *testing.T) { Convey("Test getUpstreamCatalog() with missing certs", t, func() { var tlsVerify bool updateDuration := time.Microsecond - syncRegistryConfig := RegistryConfig{ - Content: []Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: testImage, }, @@ -276,8 +278,8 @@ func TestSyncInternal(t *testing.T) { baseURL := test.GetBaseURL(port) baseSecureURL := test.GetSecureBaseURL(port) - syncRegistryConfig := RegistryConfig{ - Content: []Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: testImage, }, @@ -340,12 +342,12 @@ func TestSyncInternal(t *testing.T) { Convey("Test imagesToCopyFromUpstream()", t, func() { upstreamCtx := &types.SystemContext{} - _, err := imagesToCopyFromUpstream(context.Background(), "localhost:4566", "repo1", upstreamCtx, - Content{}, log.NewLogger("debug", "")) + _, err := imagesToCopyFromUpstream(context.Background(), "localhost:4566", "repo1", + upstreamCtx, syncconf.Content{}, log.NewLogger("debug", "")) So(err, ShouldNotBeNil) - _, err = imagesToCopyFromUpstream(context.Background(), "docker://localhost:4566", "repo1", upstreamCtx, - Content{}, log.NewLogger("debug", "")) + _, err = imagesToCopyFromUpstream(context.Background(), "docker://localhost:4566", "repo1", + upstreamCtx, syncconf.Content{}, log.NewLogger("debug", "")) So(err, ShouldNotBeNil) }) @@ -377,7 +379,8 @@ func TestSyncInternal(t *testing.T) { false, false, log, metrics, nil, nil, ) - sig := newSignaturesCopier(client, Credentials{}, *regURL, storage.StoreController{DefaultStore: imageStore}, log) + sig := newSignaturesCopier(client, syncconf.Credentials{}, + *regURL, storage.StoreController{DefaultStore: imageStore}, log) err = sig.syncCosignSignature(testImage, testImage, testImageTag, &ispec.Manifest{}) So(err, ShouldNotBeNil) @@ -427,7 +430,8 @@ func TestSyncInternal(t *testing.T) { So(regURL, ShouldNotBeNil) client := &http.Client{} - sig := newSignaturesCopier(client, Credentials{}, *regURL, storage.StoreController{DefaultStore: imageStore}, log) + sig := newSignaturesCopier(client, syncconf.Credentials{}, + *regURL, storage.StoreController{DefaultStore: imageStore}, log) canBeSkipped, err = sig.canSkipOCIRefs(testImage, testImageManifestDigest.String(), refs) So(err, ShouldBeNil) @@ -544,7 +548,7 @@ func TestSyncInternal(t *testing.T) { Convey("Test filterRepos()", t, func() { repos := []string{"repo", "repo1", "repo2", "repo/repo2", "repo/repo2/repo3/repo4"} - contents := []Content{ + contents := []syncconf.Content{ { Prefix: "repo", }, @@ -560,7 +564,7 @@ func TestSyncInternal(t *testing.T) { So(filteredRepos[1], ShouldResemble, []string{"repo/repo2", "repo/repo2/repo3/repo4"}) So(filteredRepos[2], ShouldResemble, []string{"repo1", "repo2"}) - contents = []Content{ + contents = []syncconf.Content{ { Prefix: "[repo%#@", }, @@ -833,52 +837,52 @@ func TestSyncInternal(t *testing.T) { func TestURLHelperFunctions(t *testing.T) { testCases := []struct { repo string - content Content + content syncconf.Content expected string }{ { repo: "alpine/zot-fold/alpine", - content: Content{Prefix: "zot-fold/alpine", Destination: "/alpine", StripPrefix: false}, + content: syncconf.Content{Prefix: "zot-fold/alpine", Destination: "/alpine", StripPrefix: false}, expected: "zot-fold/alpine", }, { repo: "zot-fold/alpine", - content: Content{Prefix: "zot-fold/alpine", Destination: "/", StripPrefix: false}, + content: syncconf.Content{Prefix: "zot-fold/alpine", Destination: "/", StripPrefix: false}, expected: "zot-fold/alpine", }, { repo: "alpine", - content: Content{Prefix: "zot-fold/alpine", Destination: "/alpine", StripPrefix: true}, + content: syncconf.Content{Prefix: "zot-fold/alpine", Destination: "/alpine", StripPrefix: true}, expected: "zot-fold/alpine", }, { repo: "/", - content: Content{Prefix: "zot-fold/alpine", Destination: "/", StripPrefix: true}, + content: syncconf.Content{Prefix: "zot-fold/alpine", Destination: "/", StripPrefix: true}, expected: "zot-fold/alpine", }, { repo: "/", - content: Content{Prefix: "/", Destination: "/", StripPrefix: true}, + content: syncconf.Content{Prefix: "/", Destination: "/", StripPrefix: true}, expected: "/", }, { repo: "alpine", - content: Content{Prefix: "zot-fold/alpine", Destination: "/alpine", StripPrefix: true}, + content: syncconf.Content{Prefix: "zot-fold/alpine", Destination: "/alpine", StripPrefix: true}, expected: "zot-fold/alpine", }, { repo: "alpine", - content: Content{Prefix: "zot-fold/*", Destination: "/", StripPrefix: true}, + content: syncconf.Content{Prefix: "zot-fold/*", Destination: "/", StripPrefix: true}, expected: "zot-fold/alpine", }, { repo: "alpine", - content: Content{Prefix: "zot-fold/**", Destination: "/", StripPrefix: true}, + content: syncconf.Content{Prefix: "zot-fold/**", Destination: "/", StripPrefix: true}, expected: "zot-fold/alpine", }, { repo: "zot-fold/alpine", - content: Content{Prefix: "zot-fold/**", Destination: "/", StripPrefix: false}, + content: syncconf.Content{Prefix: "zot-fold/**", Destination: "/", StripPrefix: false}, expected: "zot-fold/alpine", }, } @@ -902,7 +906,7 @@ func TestURLHelperFunctions(t *testing.T) { func TestFindRepoMatchingContentID(t *testing.T) { testCases := []struct { repo string - content []Content + content []syncconf.Content expected struct { contentID int err error @@ -910,7 +914,7 @@ func TestFindRepoMatchingContentID(t *testing.T) { }{ { repo: "alpine/zot-fold/alpine", - content: []Content{ + content: []syncconf.Content{ {Prefix: "zot-fold/alpine/", Destination: "/alpine", StripPrefix: true}, {Prefix: "zot-fold/alpine", Destination: "/alpine", StripPrefix: false}, }, @@ -921,7 +925,7 @@ func TestFindRepoMatchingContentID(t *testing.T) { }, { repo: "alpine/zot-fold/alpine", - content: []Content{ + content: []syncconf.Content{ {Prefix: "zot-fold/*", Destination: "/alpine", StripPrefix: false}, {Prefix: "zot-fold/alpine", Destination: "/alpine", StripPrefix: true}, }, @@ -932,7 +936,7 @@ func TestFindRepoMatchingContentID(t *testing.T) { }, { repo: "myFold/zot-fold/internal/alpine", - content: []Content{ + content: []syncconf.Content{ {Prefix: "zot-fold/alpine", Destination: "/alpine", StripPrefix: true}, {Prefix: "zot-fold/**", Destination: "/myFold", StripPrefix: false}, }, @@ -943,7 +947,7 @@ func TestFindRepoMatchingContentID(t *testing.T) { }, { repo: "alpine", - content: []Content{ + content: []syncconf.Content{ {Prefix: "zot-fold/*", Destination: "/alpine", StripPrefix: true}, {Prefix: "zot-fold/alpine", Destination: "/", StripPrefix: true}, }, @@ -954,7 +958,7 @@ func TestFindRepoMatchingContentID(t *testing.T) { }, { repo: "alpine", - content: []Content{ + content: []syncconf.Content{ {Prefix: "zot-fold/*", Destination: "/alpine", StripPrefix: true}, {Prefix: "zot-fold/*", Destination: "/", StripPrefix: true}, }, @@ -965,7 +969,7 @@ func TestFindRepoMatchingContentID(t *testing.T) { }, { repo: "alpine/alpine", - content: []Content{ + content: []syncconf.Content{ {Prefix: "zot-fold/*", Destination: "/alpine", StripPrefix: true}, {Prefix: "zot-fold/*", Destination: "/", StripPrefix: true}, }, diff --git a/pkg/extensions/sync/sync_test.go b/pkg/extensions/sync/sync_test.go index 3e1a5412..d3971717 100644 --- a/pkg/extensions/sync/sync_test.go +++ b/pkg/extensions/sync/sync_test.go @@ -40,6 +40,7 @@ import ( "zotregistry.io/zot/pkg/cli" "zotregistry.io/zot/pkg/common" extconf "zotregistry.io/zot/pkg/extensions/config" + syncconf "zotregistry.io/zot/pkg/extensions/config/sync" "zotregistry.io/zot/pkg/extensions/sync" logger "zotregistry.io/zot/pkg/log" "zotregistry.io/zot/pkg/storage" @@ -145,7 +146,7 @@ func startUpstreamServer( } func startDownstreamServer( - t *testing.T, secure bool, syncConfig *sync.Config, + t *testing.T, secure bool, syncConfig *syncconf.Config, ) (*api.Controller, string, string, *resty.Client) { t.Helper() @@ -250,11 +251,11 @@ func TestORAS(t *testing.T) { regex := ".*" - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: "oras-artifact", - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Regex: ®ex, }, }, @@ -266,9 +267,9 @@ func TestORAS(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, _, destClient := startDownstreamServer(t, false, syncConfig) @@ -320,11 +321,11 @@ func TestORAS(t *testing.T) { var semver bool var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: repoName, - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Regex: ®ex, Semver: &semver, }, @@ -338,9 +339,9 @@ func TestORAS(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, destDir, destClient := startDownstreamServer(t, false, syncConfig) @@ -491,11 +492,11 @@ func TestOnDemand(t *testing.T) { regex := ".*" semver := true - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: testImage, - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Regex: ®ex, Semver: &semver, }, @@ -508,9 +509,9 @@ func TestOnDemand(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, destDir, destClient := startDownstreamServer(t, false, syncConfig) @@ -623,11 +624,11 @@ func TestPeriodically(t *testing.T) { maxRetries := 1 delay := 1 * time.Second - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: testImage, - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Regex: ®ex, Semver: &semver, }, @@ -642,9 +643,9 @@ func TestPeriodically(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, _, destClient := startDownstreamServer(t, false, syncConfig) @@ -693,18 +694,18 @@ func TestPeriodically(t *testing.T) { var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: testImage, - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Regex: ®ex, Semver: &semver, }, }, { Prefix: testCveImage, - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Regex: &invalidRegex, Semver: &semver, }, @@ -716,9 +717,9 @@ func TestPeriodically(t *testing.T) { CertDir: "", } - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, _, destClient := startDownstreamServer(t, false, syncConfig) @@ -793,11 +794,11 @@ func TestOnDemandPermsDenied(t *testing.T) { semver := true var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: testImage, - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Regex: ®ex, Semver: &semver, }, @@ -811,9 +812,9 @@ func TestOnDemandPermsDenied(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } destPort := test.GetFreePort() @@ -869,8 +870,8 @@ func TestConfigReloader(t *testing.T) { var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: testImage, }, @@ -883,9 +884,9 @@ func TestConfigReloader(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } destPort := test.GetFreePort() @@ -990,11 +991,11 @@ func TestMandatoryAnnotations(t *testing.T) { var semver bool tlsVerify := false - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: testImage, - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Regex: ®ex, Semver: &semver, }, @@ -1007,9 +1008,9 @@ func TestMandatoryAnnotations(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } destPort := test.GetFreePort() @@ -1075,11 +1076,11 @@ func TestBadTLS(t *testing.T) { var semver bool tlsVerify := true - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: testImage, - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Regex: ®ex, Semver: &semver, }, @@ -1092,9 +1093,9 @@ func TestBadTLS(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, _, destClient := startDownstreamServer(t, true, syncConfig) @@ -1167,11 +1168,11 @@ func TestTLS(t *testing.T) { var semver bool tlsVerify := true - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: testImage, - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Regex: ®ex, Semver: &semver, }, @@ -1184,9 +1185,9 @@ func TestTLS(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, _, destDir, _ := startDownstreamServer(t, true, syncConfig) @@ -1235,8 +1236,8 @@ func TestBasicAuth(t *testing.T) { var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: testImage, }, @@ -1248,10 +1249,10 @@ func TestBasicAuth(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, CredentialsFile: credentialsFile, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, _, destClient := startDownstreamServer(t, false, syncConfig) @@ -1332,11 +1333,11 @@ func TestBasicAuth(t *testing.T) { var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: testImage, - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Regex: ®ex, Semver: &semver, }, @@ -1351,10 +1352,10 @@ func TestBasicAuth(t *testing.T) { destConfig.Extensions = &extconf.ExtensionConfig{} defaultVal := true - destConfig.Extensions.Sync = &sync.Config{ + destConfig.Extensions.Sync = &syncconf.Config{ Enable: &defaultVal, CredentialsFile: credentialsFile, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr := api.NewController(destConfig) @@ -1394,11 +1395,11 @@ func TestBasicAuth(t *testing.T) { var semver bool var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: testImage, - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Regex: ®ex, Semver: &semver, }, @@ -1411,10 +1412,10 @@ func TestBasicAuth(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, CredentialsFile: credentialsFile, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, _, destClient := startDownstreamServer(t, false, syncConfig) @@ -1441,27 +1442,27 @@ func TestBasicAuth(t *testing.T) { registryName := sync.StripRegistryTransport(srcBaseURL) credentialsFile := makeCredentialsFile(fmt.Sprintf(`{"%s":{"username": "test", "password": "test"}}`, registryName)) - syncRegistryConfig := sync.RegistryConfig{ + syncRegistryConfig := syncconf.RegistryConfig{ URLs: []string{srcBaseURL}, OnDemand: true, } - unreacheableSyncRegistryConfig1 := sync.RegistryConfig{ + unreacheableSyncRegistryConfig1 := syncconf.RegistryConfig{ URLs: []string{"localhost:9999"}, OnDemand: true, } - unreacheableSyncRegistryConfig2 := sync.RegistryConfig{ + unreacheableSyncRegistryConfig2 := syncconf.RegistryConfig{ URLs: []string{"localhost:9999"}, OnDemand: false, } defaultVal := true // add file path to the credentials - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, CredentialsFile: credentialsFile, - Registries: []sync.RegistryConfig{ + Registries: []syncconf.RegistryConfig{ unreacheableSyncRegistryConfig1, unreacheableSyncRegistryConfig2, syncRegistryConfig, @@ -1536,11 +1537,11 @@ func TestBadURL(t *testing.T) { var semver bool var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: testImage, - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Regex: ®ex, Semver: &semver, }, @@ -1554,9 +1555,9 @@ func TestBadURL(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, _, destClient := startDownstreamServer(t, false, syncConfig) @@ -1584,11 +1585,11 @@ func TestNoImagesByRegex(t *testing.T) { regex := "9.9.9" var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: testImage, - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Regex: ®ex, }, }, @@ -1600,9 +1601,9 @@ func TestNoImagesByRegex(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, _, destClient := startDownstreamServer(t, false, syncConfig) @@ -1643,11 +1644,11 @@ func TestInvalidRegex(t *testing.T) { regex := "[" var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: testImage, - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Regex: ®ex, }, }, @@ -1660,9 +1661,9 @@ func TestInvalidRegex(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, _, _, _ := startDownstreamServer(t, false, syncConfig) @@ -1701,11 +1702,11 @@ func TestNotSemver(t *testing.T) { semver := true var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: testImage, - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Semver: &semver, }, }, @@ -1717,9 +1718,9 @@ func TestNotSemver(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, _, destClient := startDownstreamServer(t, false, syncConfig) @@ -1766,8 +1767,8 @@ func TestErrorOnCatalog(t *testing.T) { tlsVerify := false - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: testImage, }, @@ -1779,9 +1780,9 @@ func TestErrorOnCatalog(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, _, _, _ := startDownstreamServer(t, false, syncConfig) @@ -1846,8 +1847,8 @@ func TestInvalidCerts(t *testing.T) { tlsVerify := true - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: testImage, }, @@ -1860,9 +1861,9 @@ func TestInvalidCerts(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, _, destClient := startDownstreamServer(t, false, syncConfig) @@ -1913,8 +1914,8 @@ func TestCertsWithWrongPerms(t *testing.T) { tlsVerify := true - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: testImage, }, @@ -1927,9 +1928,9 @@ func TestCertsWithWrongPerms(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, _, destClient := startDownstreamServer(t, false, syncConfig) @@ -1965,12 +1966,12 @@ func TestInvalidUrl(t *testing.T) { var semver bool var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { // won't match any image on source registry, we will sync on demand Prefix: "dummy", - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Regex: ®ex, Semver: &semver, }, @@ -1984,9 +1985,9 @@ func TestInvalidUrl(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, _, destClient := startDownstreamServer(t, false, syncConfig) @@ -2015,12 +2016,12 @@ func TestInvalidTags(t *testing.T) { var semver bool var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { // won't match any image on source registry, we will sync on demand Prefix: "dummy", - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Regex: ®ex, Semver: &semver, }, @@ -2034,9 +2035,9 @@ func TestInvalidTags(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, _, destClient := startDownstreamServer(t, false, syncConfig) @@ -2079,11 +2080,11 @@ func TestSubPaths(t *testing.T) { var semver bool var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: path.Join(subpath, testImage), - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Regex: ®ex, Semver: &semver, }, @@ -2097,9 +2098,9 @@ func TestSubPaths(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } destPort := test.GetFreePort() @@ -2168,8 +2169,8 @@ func TestSubPaths(t *testing.T) { func TestOnDemandRepoErr(t *testing.T) { Convey("Verify sync on demand parseRepositoryReference error", t, func() { tlsVerify := false - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { // will sync on demand, should not be filtered out Prefix: testImage, @@ -2182,9 +2183,9 @@ func TestOnDemandRepoErr(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, _, _ := startDownstreamServer(t, false, syncConfig) @@ -2212,12 +2213,12 @@ func TestOnDemandContentFiltering(t *testing.T) { var semver bool var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { // should be filtered out Prefix: "dummy", - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Regex: ®ex, Semver: &semver, }, @@ -2230,9 +2231,9 @@ func TestOnDemandContentFiltering(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, _, _ := startDownstreamServer(t, false, syncConfig) @@ -2251,12 +2252,12 @@ func TestOnDemandContentFiltering(t *testing.T) { semver := true var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { // will sync on demand, should not be filtered out Prefix: testImage, - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Regex: ®ex, Semver: &semver, }, @@ -2269,9 +2270,9 @@ func TestOnDemandContentFiltering(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, _, _ := startDownstreamServer(t, false, syncConfig) @@ -2300,11 +2301,11 @@ func TestConfigRules(t *testing.T) { var semver bool var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: testImage, - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Regex: ®ex, Semver: &semver, }, @@ -2317,9 +2318,9 @@ func TestConfigRules(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, _, _ := startDownstreamServer(t, false, syncConfig) @@ -2338,7 +2339,7 @@ func TestConfigRules(t *testing.T) { var tlsVerify bool updateDuration, _ := time.ParseDuration("30m") - syncRegistryConfig := sync.RegistryConfig{ + syncRegistryConfig := syncconf.RegistryConfig{ PollInterval: updateDuration, URLs: []string{srcBaseURL}, TLSVerify: &tlsVerify, @@ -2347,9 +2348,9 @@ func TestConfigRules(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, _, _ := startDownstreamServer(t, false, syncConfig) @@ -2366,7 +2367,7 @@ func TestConfigRules(t *testing.T) { Convey("Test ondemand sync is disabled when ondemand is false", func() { var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ + syncRegistryConfig := syncconf.RegistryConfig{ URLs: []string{srcBaseURL}, TLSVerify: &tlsVerify, CertDir: "", @@ -2374,9 +2375,9 @@ func TestConfigRules(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, _, _ := startDownstreamServer(t, false, syncConfig) @@ -2406,11 +2407,11 @@ func TestMultipleURLs(t *testing.T) { semver := true var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: testImage, - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Regex: ®ex, Semver: &semver, }, @@ -2423,9 +2424,9 @@ func TestMultipleURLs(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, destDir, destClient := startDownstreamServer(t, false, syncConfig) @@ -2502,11 +2503,11 @@ func TestPeriodicallySignaturesErr(t *testing.T) { var semver bool var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: repoName, - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Regex: ®ex, Semver: &semver, }, @@ -2520,9 +2521,9 @@ func TestPeriodicallySignaturesErr(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } // trigger permission denied on upstream manifest @@ -2768,11 +2769,11 @@ func TestSignatures(t *testing.T) { var semver bool var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: repoName, - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Regex: ®ex, Semver: &semver, }, @@ -2786,9 +2787,9 @@ func TestSignatures(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, destDir, destClient := startDownstreamServer(t, false, syncConfig) @@ -3178,11 +3179,11 @@ func TestOnDemandRetryGoroutine(t *testing.T) { semver := true var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: testImage, - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Regex: ®ex, Semver: &semver, }, @@ -3200,9 +3201,9 @@ func TestOnDemandRetryGoroutine(t *testing.T) { syncRegistryConfig.RetryDelay = &delay defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, destDir, destClient := startDownstreamServer(t, false, syncConfig) @@ -3243,11 +3244,11 @@ func TestOnDemandWithDigest(t *testing.T) { semver := true var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: testImage, - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Regex: ®ex, Semver: &semver, }, @@ -3260,9 +3261,9 @@ func TestOnDemandWithDigest(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, destDir, destClient := startDownstreamServer(t, false, syncConfig) @@ -3291,11 +3292,11 @@ func TestOnDemandRetryGoroutineErr(t *testing.T) { semver := true var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: testImage, - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Regex: ®ex, Semver: &semver, }, @@ -3313,9 +3314,9 @@ func TestOnDemandRetryGoroutineErr(t *testing.T) { syncRegistryConfig.RetryDelay = &delay defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, destDir, destClient := startDownstreamServer(t, false, syncConfig) @@ -3357,7 +3358,7 @@ func TestOnDemandMultipleRetries(t *testing.T) { var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ + syncRegistryConfig := syncconf.RegistryConfig{ URLs: []string{srcBaseURL}, OnDemand: true, TLSVerify: &tlsVerify, @@ -3370,9 +3371,9 @@ func TestOnDemandMultipleRetries(t *testing.T) { syncRegistryConfig.RetryDelay = &delay defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, destDir, destClient := startDownstreamServer(t, false, syncConfig) @@ -3449,11 +3450,11 @@ func TestOnDemandPullsOnce(t *testing.T) { semver := true var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: testImage, - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Regex: ®ex, Semver: &semver, }, @@ -3466,9 +3467,9 @@ func TestOnDemandPullsOnce(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, destDir, _ := startDownstreamServer(t, false, syncConfig) @@ -3548,11 +3549,11 @@ func TestError(t *testing.T) { semver := true var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: testImage, - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Regex: ®ex, Semver: &semver, }, @@ -3565,9 +3566,9 @@ func TestError(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, destDir, client := startDownstreamServer(t, false, syncConfig) @@ -3619,7 +3620,7 @@ func TestSignaturesOnDemand(t *testing.T) { var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ + syncRegistryConfig := syncconf.RegistryConfig{ URLs: []string{srcBaseURL}, TLSVerify: &tlsVerify, CertDir: "", @@ -3627,9 +3628,9 @@ func TestSignaturesOnDemand(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, destDir, _ := startDownstreamServer(t, false, syncConfig) @@ -3749,7 +3750,7 @@ func TestSignaturesOnDemand(t *testing.T) { var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ + syncRegistryConfig := syncconf.RegistryConfig{ URLs: []string{srcBaseURL}, TLSVerify: &tlsVerify, CertDir: "", @@ -3757,9 +3758,9 @@ func TestSignaturesOnDemand(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } destPort := test.GetFreePort() @@ -3848,14 +3849,14 @@ func TestOnlySignaturesOnDemand(t *testing.T) { var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ + syncRegistryConfig := syncconf.RegistryConfig{ URLs: []string{srcBaseURL}, TLSVerify: &tlsVerify, CertDir: "", OnDemand: true, } - syncBadRegistryConfig := sync.RegistryConfig{ + syncBadRegistryConfig := syncconf.RegistryConfig{ URLs: []string{"http://invalid.invalid:9999"}, TLSVerify: &tlsVerify, CertDir: "", @@ -3863,9 +3864,9 @@ func TestOnlySignaturesOnDemand(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncBadRegistryConfig, syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncBadRegistryConfig, syncRegistryConfig}, } dctlr, destBaseURL, _, _ := startDownstreamServer(t, false, syncConfig) @@ -3952,8 +3953,8 @@ func TestSyncOnlyDiff(t *testing.T) { var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: "**", }, @@ -3966,9 +3967,9 @@ func TestSyncOnlyDiff(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } destPort := test.GetFreePort() @@ -4024,8 +4025,8 @@ func TestSyncWithDiffDigest(t *testing.T) { var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: "**", }, @@ -4038,9 +4039,9 @@ func TestSyncWithDiffDigest(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } destPort := test.GetFreePort() @@ -4186,11 +4187,11 @@ func TestSyncSignaturesDiff(t *testing.T) { var semver bool var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: repoName, - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Regex: ®ex, Semver: &semver, }, @@ -4204,9 +4205,9 @@ func TestSyncSignaturesDiff(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, destDir, destClient := startDownstreamServer(t, false, syncConfig) @@ -4376,11 +4377,11 @@ func TestOnlySignedFlag(t *testing.T) { var tlsVerify bool - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: testImage, - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Regex: ®ex, Semver: &semver, }, @@ -4397,9 +4398,9 @@ func TestOnlySignedFlag(t *testing.T) { Convey("Verify sync revokes unsigned images", t, func() { syncRegistryConfig.OnDemand = false - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, destDir, client := startDownstreamServer(t, false, syncConfig) @@ -4418,9 +4419,9 @@ func TestOnlySignedFlag(t *testing.T) { Convey("Verify sync ondemand revokes unsigned images", t, func() { syncRegistryConfig.OnDemand = true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, destDir, client := startDownstreamServer(t, false, syncConfig) @@ -4439,48 +4440,48 @@ func TestOnlySignedFlag(t *testing.T) { func TestSyncWithDestination(t *testing.T) { Convey("Test sync computes destination option correctly", t, func() { testCases := []struct { - content sync.Content + content syncconf.Content expected string repo string }{ { expected: "zot-test/zot-fold/zot-test", - content: sync.Content{Prefix: "zot-fold/zot-test", Destination: "/zot-test", StripPrefix: false}, + content: syncconf.Content{Prefix: "zot-fold/zot-test", Destination: "/zot-test", StripPrefix: false}, repo: "zot-fold/zot-test", }, { expected: "zot-fold/zot-test", - content: sync.Content{Prefix: "zot-fold/zot-test", Destination: "/", StripPrefix: false}, + content: syncconf.Content{Prefix: "zot-fold/zot-test", Destination: "/", StripPrefix: false}, repo: "zot-fold/zot-test", }, { expected: "zot-test", - content: sync.Content{Prefix: "zot-fold/zot-test", Destination: "/zot-test", StripPrefix: true}, + content: syncconf.Content{Prefix: "zot-fold/zot-test", Destination: "/zot-test", StripPrefix: true}, repo: "zot-fold/zot-test", }, { expected: "zot-test", - content: sync.Content{Prefix: "zot-fold/*", Destination: "/", StripPrefix: true}, + content: syncconf.Content{Prefix: "zot-fold/*", Destination: "/", StripPrefix: true}, repo: "zot-fold/zot-test", }, { expected: "zot-test", - content: sync.Content{Prefix: "zot-fold/zot-test", Destination: "/zot-test", StripPrefix: true}, + content: syncconf.Content{Prefix: "zot-fold/zot-test", Destination: "/zot-test", StripPrefix: true}, repo: "zot-fold/zot-test", }, { expected: "zot-test", - content: sync.Content{Prefix: "zot-fold/*", Destination: "/", StripPrefix: true}, + content: syncconf.Content{Prefix: "zot-fold/*", Destination: "/", StripPrefix: true}, repo: "zot-fold/zot-test", }, { expected: "zot-test", - content: sync.Content{Prefix: "zot-fold/**", Destination: "/", StripPrefix: true}, + content: syncconf.Content{Prefix: "zot-fold/**", Destination: "/", StripPrefix: true}, repo: "zot-fold/zot-test", }, { expected: "zot-fold/zot-test", - content: sync.Content{Prefix: "zot-fold/**", Destination: "/", StripPrefix: false}, + content: syncconf.Content{Prefix: "zot-fold/**", Destination: "/", StripPrefix: false}, repo: "zot-fold/zot-test", }, } @@ -4506,8 +4507,8 @@ func TestSyncWithDestination(t *testing.T) { for _, testCase := range testCases { updateDuration, _ := time.ParseDuration("30m") tlsVerify := false - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{testCase.content}, + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{testCase.content}, URLs: []string{srcBaseURL}, OnDemand: false, PollInterval: updateDuration, @@ -4515,9 +4516,9 @@ func TestSyncWithDestination(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, _, destClient := startDownstreamServer(t, false, syncConfig) @@ -4541,17 +4542,17 @@ func TestSyncWithDestination(t *testing.T) { Convey("Test ondemand sync", func() { for _, testCase := range testCases { tlsVerify := false - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{testCase.content}, + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{testCase.content}, URLs: []string{srcBaseURL}, OnDemand: true, TLSVerify: &tlsVerify, } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } dctlr, destBaseURL, _, destClient := startDownstreamServer(t, false, syncConfig) @@ -4584,11 +4585,11 @@ func TestSyncImageIndex(t *testing.T) { var semver bool tlsVerify := false - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: "index", - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Regex: ®ex, Semver: &semver, }, @@ -4601,9 +4602,9 @@ func TestSyncImageIndex(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } // create an image index on upstream @@ -4723,11 +4724,11 @@ func TestSyncOCIArtifactsWithTag(t *testing.T) { repoName := "artifact" - syncRegistryConfig := sync.RegistryConfig{ - Content: []sync.Content{ + syncRegistryConfig := syncconf.RegistryConfig{ + Content: []syncconf.Content{ { Prefix: repoName, - Tags: &sync.Tags{ + Tags: &syncconf.Tags{ Regex: ®ex, Semver: &semver, }, @@ -4740,9 +4741,9 @@ func TestSyncOCIArtifactsWithTag(t *testing.T) { } defaultVal := true - syncConfig := &sync.Config{ + syncConfig := &syncconf.Config{ Enable: &defaultVal, - Registries: []sync.RegistryConfig{syncRegistryConfig}, + Registries: []syncconf.RegistryConfig{syncRegistryConfig}, } // create artifact blob diff --git a/pkg/extensions/sync/utils.go b/pkg/extensions/sync/utils.go index 572028fd..ecf32584 100644 --- a/pkg/extensions/sync/utils.go +++ b/pkg/extensions/sync/utils.go @@ -26,6 +26,7 @@ import ( zerr "zotregistry.io/zot/errors" "zotregistry.io/zot/pkg/common" + syncconf "zotregistry.io/zot/pkg/extensions/config/sync" "zotregistry.io/zot/pkg/extensions/monitoring" "zotregistry.io/zot/pkg/log" "zotregistry.io/zot/pkg/storage" @@ -121,7 +122,7 @@ func parseRepositoryReference(input string) (reference.Named, error) { } // filterRepos filters repos based on prefix given in the config. -func filterRepos(repos []string, contentList []Content, log log.Logger) map[int][]string { +func filterRepos(repos []string, contentList []syncconf.Content, log log.Logger) map[int][]string { filtered := make(map[int][]string) for _, repo := range repos { @@ -155,7 +156,7 @@ func filterRepos(repos []string, contentList []Content, log log.Logger) map[int] } // findRepoContentID return the contentID that maches the localRepo path for a given RegistryConfig in the config file. -func findRepoMatchingContentID(localRepo string, contentList []Content) (int, error) { +func findRepoMatchingContentID(localRepo string, contentList []syncconf.Content) (int, error) { contentID := -1 localRepo = strings.Trim(localRepo, "/") @@ -194,7 +195,7 @@ func findRepoMatchingContentID(localRepo string, contentList []Content) (int, er return contentID, nil } -func getRepoSource(localRepo string, content Content) string { +func getRepoSource(localRepo string, content syncconf.Content) string { localRepo = strings.Trim(localRepo, "/") destination := strings.Trim(content.Destination, "/") prefix := strings.Trim(content.Prefix, "/*") @@ -219,7 +220,7 @@ func getRepoSource(localRepo string, content Content) string { } // getRepoDestination returns the local storage path of the synced repo based on the specified destination. -func getRepoDestination(remoteRepo string, content Content) string { +func getRepoDestination(remoteRepo string, content syncconf.Content) string { remoteRepo = strings.Trim(remoteRepo, "/") destination := strings.Trim(content.Destination, "/") prefix := strings.Trim(content.Prefix, "/*") @@ -244,13 +245,13 @@ func getRepoDestination(remoteRepo string, content Content) string { } // Get sync.FileCredentials from file. -func getFileCredentials(filepath string) (CredentialsFile, error) { +func getFileCredentials(filepath string) (syncconf.CredentialsFile, error) { credsFile, err := os.ReadFile(filepath) if err != nil { return nil, err } - var creds CredentialsFile + var creds syncconf.CredentialsFile err = json.Unmarshal(credsFile, &creds) if err != nil {