create a new registry client when refreshing cache

This commit is contained in:
Wenkai Yin 2016-06-23 15:18:32 +08:00
parent a8cbcfbfe6
commit 841018e2d8

View File

@ -30,9 +30,7 @@ var (
// Cache is the global cache in system. // Cache is the global cache in system.
Cache cache.Cache Cache cache.Cache
endpoint string endpoint string
insecure bool
username string username string
registryClient *registry.Registry
) )
const catalogKey string = "catalog" const catalogKey string = "catalog"
@ -45,22 +43,18 @@ func init() {
} }
endpoint = os.Getenv("REGISTRY_URL") endpoint = os.Getenv("REGISTRY_URL")
username = "admin"
} }
// RefreshCatalogCache calls registry's API to get repository list and write it to cache. // RefreshCatalogCache calls registry's API to get repository list and write it to cache.
func RefreshCatalogCache() error { func RefreshCatalogCache() error {
log.Debug("refreshing catalog cache...") log.Debug("refreshing catalog cache...")
var err error registryClient, err := NewRegistryClient(endpoint, true, username,
if registryClient == nil {
registryClient, err = NewRegistryClient(endpoint, true, username,
"registry", "catalog", "*") "registry", "catalog", "*")
if err != nil { if err != nil {
return err return err
} }
}
rs, err := registryClient.Catalog() rs, err := registryClient.Catalog()
if err != nil { if err != nil {
@ -70,7 +64,7 @@ func RefreshCatalogCache() error {
repos := []string{} repos := []string{}
for _, repo := range rs { for _, repo := range rs {
rc, err := NewRepositoryClient(endpoint, insecure, username, rc, err := NewRepositoryClient(endpoint, true, username,
repo, "repository", repo, "pull", "push", "*") repo, "repository", repo, "pull", "push", "*")
if err != nil { if err != nil {
log.Errorf("error occurred while initializing repository client used by cache: %s %v", repo, err) log.Errorf("error occurred while initializing repository client used by cache: %s %v", repo, err)