fix(redis) redis sentinel for chart cache

Signed-off-by: Ziming Zhang <zziming@vmware.com>
This commit is contained in:
Ziming Zhang 2020-11-17 22:30:33 +08:00
parent 35a0fc7afd
commit e44d58ee41
3 changed files with 7 additions and 7 deletions

View File

@ -59,11 +59,11 @@ func NewChartCache(config *ChartCacheConfig) *ChartCache {
return chartCache
}
if config.DriverType != cacheDriverMem && config.DriverType != cacheDriverRedis {
if config.DriverType != cacheDriverMem && config.DriverType != cacheDriverRedis && config.DriverType != cacheDriverRedisSentinel {
return chartCache
}
if config.DriverType == cacheDriverRedis {
if config.DriverType == cacheDriverRedis || config.DriverType == cacheDriverRedisSentinel {
if len(config.Config) == 0 {
return chartCache
}
@ -107,7 +107,7 @@ func (chc *ChartCache) PutChart(chart *ChartVersionDetails) {
case cacheDriverMem:
// Directly put object in
err = chc.cache.Put(chart.Metadata.Digest, chart, standardExpireTime)
case cacheDriverRedis:
case cacheDriverRedis, cacheDriverRedisSentinel:
// Marshal to json data before saving
var jsonData []byte
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)
if err != nil {
// Just logged
hlog.Errorf("Failed to initialize redis cache: %s", err)
hlog.Errorf("Failed to initialize redis sentinel cache: %s", err)
if count < maxTry {
<-time.After(time.Duration(backoff(count)) * time.Second)
@ -203,7 +203,7 @@ func initCacheDriver(cacheConfig *ChartCacheConfig) beego_cache.Cache {
return nil
}
hlog.Info("Enable redis cache for chart caching")
hlog.Info("Enable redis sentinel cache for chart caching")
return redisCache
}
default:

View File

@ -175,7 +175,7 @@ func (c *Controller) GetChartVersionDetails(namespace, chartName, version string
chartDetails.Security.Signature.Provenance = provFilePath
} else {
// 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

View File

@ -130,7 +130,7 @@ func getCacheConfig() (*ChartCacheConfig, error) {
return nil, fmt.Errorf("failed to parse redis configurations from '%s' with error: %s", redisCfg, err)
}
if _, isSet := redisCfg["masterName"]; isSet {
driver = "redis_sentinel"
driver = cacheDriverRedisSentinel
}
// Convert config map to string