mirror of
https://github.com/goharbor/harbor.git
synced 2025-02-09 00:12:03 +01:00
fix(redis) redis sentinel for chart cache
Signed-off-by: Ziming Zhang <zziming@vmware.com>
This commit is contained in:
parent
35a0fc7afd
commit
e44d58ee41
@ -59,11 +59,11 @@ func NewChartCache(config *ChartCacheConfig) *ChartCache {
|
|||||||
return chartCache
|
return chartCache
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.DriverType != cacheDriverMem && config.DriverType != cacheDriverRedis {
|
if config.DriverType != cacheDriverMem && config.DriverType != cacheDriverRedis && config.DriverType != cacheDriverRedisSentinel {
|
||||||
return chartCache
|
return chartCache
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.DriverType == cacheDriverRedis {
|
if config.DriverType == cacheDriverRedis || config.DriverType == cacheDriverRedisSentinel {
|
||||||
if len(config.Config) == 0 {
|
if len(config.Config) == 0 {
|
||||||
return chartCache
|
return chartCache
|
||||||
}
|
}
|
||||||
@ -107,7 +107,7 @@ func (chc *ChartCache) PutChart(chart *ChartVersionDetails) {
|
|||||||
case cacheDriverMem:
|
case cacheDriverMem:
|
||||||
// Directly put object in
|
// Directly put object in
|
||||||
err = chc.cache.Put(chart.Metadata.Digest, chart, standardExpireTime)
|
err = chc.cache.Put(chart.Metadata.Digest, chart, standardExpireTime)
|
||||||
case cacheDriverRedis:
|
case cacheDriverRedis, cacheDriverRedisSentinel:
|
||||||
// Marshal to json data before saving
|
// Marshal to json data before saving
|
||||||
var jsonData []byte
|
var jsonData []byte
|
||||||
if jsonData, err = json.Marshal(chart); err == nil {
|
if jsonData, err = json.Marshal(chart); err == nil {
|
||||||
@ -193,7 +193,7 @@ func initCacheDriver(cacheConfig *ChartCacheConfig) beego_cache.Cache {
|
|||||||
redisCache, err := beego_cache.NewCache(cacheDriverRedisSentinel, cacheConfig.Config)
|
redisCache, err := beego_cache.NewCache(cacheDriverRedisSentinel, cacheConfig.Config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Just logged
|
// Just logged
|
||||||
hlog.Errorf("Failed to initialize redis cache: %s", err)
|
hlog.Errorf("Failed to initialize redis sentinel cache: %s", err)
|
||||||
|
|
||||||
if count < maxTry {
|
if count < maxTry {
|
||||||
<-time.After(time.Duration(backoff(count)) * time.Second)
|
<-time.After(time.Duration(backoff(count)) * time.Second)
|
||||||
@ -203,7 +203,7 @@ func initCacheDriver(cacheConfig *ChartCacheConfig) beego_cache.Cache {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
hlog.Info("Enable redis cache for chart caching")
|
hlog.Info("Enable redis sentinel cache for chart caching")
|
||||||
return redisCache
|
return redisCache
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -175,7 +175,7 @@ func (c *Controller) GetChartVersionDetails(namespace, chartName, version string
|
|||||||
chartDetails.Security.Signature.Provenance = provFilePath
|
chartDetails.Security.Signature.Provenance = provFilePath
|
||||||
} else {
|
} else {
|
||||||
// Just log it
|
// Just log it
|
||||||
hlog.Errorf("Failed to get prov file for chart %s with error: %s, got %d bytes", chartV.Name, err.Error(), len(provBytes))
|
hlog.Debugf("Failed to get prov file for chart %s with error: %s, got %d bytes", chartV.Name, err.Error(), len(provBytes))
|
||||||
}
|
}
|
||||||
|
|
||||||
return chartDetails, nil
|
return chartDetails, nil
|
||||||
|
@ -130,7 +130,7 @@ func getCacheConfig() (*ChartCacheConfig, error) {
|
|||||||
return nil, fmt.Errorf("failed to parse redis configurations from '%s' with error: %s", redisCfg, err)
|
return nil, fmt.Errorf("failed to parse redis configurations from '%s' with error: %s", redisCfg, err)
|
||||||
}
|
}
|
||||||
if _, isSet := redisCfg["masterName"]; isSet {
|
if _, isSet := redisCfg["masterName"]; isSet {
|
||||||
driver = "redis_sentinel"
|
driver = cacheDriverRedisSentinel
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert config map to string
|
// Convert config map to string
|
||||||
|
Loading…
Reference in New Issue
Block a user