mirror of
https://github.com/goharbor/harbor
synced 2025-04-19 17:33:59 +00:00
Merge pull request #396 from ywk253100/bug_fix_for_access_log
create a new registry client when refreshing cache
This commit is contained in:
commit
79b7c78f46
26
service/cache/cache.go
vendored
26
service/cache/cache.go
vendored
|
@ -16,7 +16,6 @@
|
||||||
package cache
|
package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -29,11 +28,9 @@ import (
|
||||||
|
|
||||||
var (
|
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"
|
||||||
|
@ -46,26 +43,19 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoint = os.Getenv("REGISTRY_URL")
|
endpoint = os.Getenv("REGISTRY_URL")
|
||||||
// TODO read variable from config file
|
|
||||||
insecure = true
|
|
||||||
username = "admin"
|
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.
|
// 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...")
|
||||||
|
|
||||||
if registryClient == nil {
|
registryClient, err := NewRegistryClient(endpoint, true, username,
|
||||||
return errors.New("registry client is nil")
|
"registry", "catalog", "*")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
|
||||||
rs, err := registryClient.Catalog()
|
rs, err := registryClient.Catalog()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -74,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)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user