From a8cbcfbfe69587d8354e6e52982132aec505991e Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Thu, 23 Jun 2016 15:07:05 +0800 Subject: [PATCH 1/2] create a new registry client if it is nil in cache --- service/cache/cache.go | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/service/cache/cache.go b/service/cache/cache.go index ff15c72e1..d7b91c0dd 100644 --- a/service/cache/cache.go +++ b/service/cache/cache.go @@ -16,7 +16,6 @@ package cache import ( - "errors" "os" "time" @@ -46,26 +45,23 @@ func init() { } endpoint = os.Getenv("REGISTRY_URL") - // TODO read variable from config file - insecure = true - username = "admin" - registryClient, err = NewRegistryClient(endpoint, insecure, username, - "registry", "catalog", "*") - if err != nil { - log.Errorf("failed to create registry client: %v", err) - return - } } // RefreshCatalogCache calls registry's API to get repository list and write it to cache. func RefreshCatalogCache() error { log.Debug("refreshing catalog cache...") + var err error + if registryClient == nil { - return errors.New("registry client is nil") + + registryClient, err = NewRegistryClient(endpoint, true, username, + "registry", "catalog", "*") + if err != nil { + return err + } } - var err error rs, err := registryClient.Catalog() if err != nil { return err From 841018e2d8e7d68b873c5ccbd08ed38eba71519f Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Thu, 23 Jun 2016 15:18:32 +0800 Subject: [PATCH 2/2] create a new registry client when refreshing cache --- service/cache/cache.go | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/service/cache/cache.go b/service/cache/cache.go index d7b91c0dd..c7b2c005d 100644 --- a/service/cache/cache.go +++ b/service/cache/cache.go @@ -28,11 +28,9 @@ import ( var ( // Cache is the global cache in system. - Cache cache.Cache - endpoint string - insecure bool - username string - registryClient *registry.Registry + Cache cache.Cache + endpoint string + username string ) const catalogKey string = "catalog" @@ -45,21 +43,17 @@ func init() { } endpoint = os.Getenv("REGISTRY_URL") + username = "admin" } // RefreshCatalogCache calls registry's API to get repository list and write it to cache. func RefreshCatalogCache() error { log.Debug("refreshing catalog cache...") - var err error - - if registryClient == nil { - - registryClient, err = NewRegistryClient(endpoint, true, username, - "registry", "catalog", "*") - if err != nil { - return err - } + registryClient, err := NewRegistryClient(endpoint, true, username, + "registry", "catalog", "*") + if err != nil { + return err } rs, err := registryClient.Catalog() @@ -70,7 +64,7 @@ func RefreshCatalogCache() error { repos := []string{} for _, repo := range rs { - rc, err := NewRepositoryClient(endpoint, insecure, username, + rc, err := NewRepositoryClient(endpoint, true, username, repo, "repository", repo, "pull", "push", "*") if err != nil { log.Errorf("error occurred while initializing repository client used by cache: %s %v", repo, err)