Files
zot/pkg/storage/cache.go
T
Luca Muscariello 2402296e9a fix: migrate to Go module v2 for proper semantic versioning (#3462)
* fix: migrate to Go module v2 for proper semantic versioning

This change updates the module path from 'zotregistry.dev/zot' to
'zotregistry.dev/zot/v2' to comply with Go's semantic versioning rules.

According to Go's module versioning requirements, major version v2+
must include the major version in the module path. The current
module path 'zotregistry.dev/zot' only supports v0.x.x and v1.x.x
versions, making existing v2.x.x tags (like v2.1.8) unusable.

Changes:
- Updated go.mod module path to zotregistry.dev/zot/v2
- Updated all internal import paths across 280+ Go source files
- Updated configuration files (golangcilint.yaml, gqlgen.yml)
- Updated README.md Go reference badge

This fix enables proper use of existing v2.x.x Git tags and allows
external packages to import zot v2+ versions without compatibility
errors.

Resolves: Go module import compatibility for v2+ versions
Fixes: #3071
Signed-off-by: Luca Muscariello <muscariello@ieee.org>

* fix: regenerate GraphQL files with updated v2 import paths

The gqlgen tool needs to regenerate the GraphQL schema files after
the module path change to use the new v2 imports.

Signed-off-by: Luca Muscariello <muscariello@ieee.org>

---------

Signed-off-by: Luca Muscariello <muscariello@ieee.org>
2025-10-16 22:43:47 -07:00

130 lines
3.5 KiB
Go

package storage
import (
"fmt"
zerr "zotregistry.dev/zot/v2/errors"
"zotregistry.dev/zot/v2/pkg/api/config"
rediscfg "zotregistry.dev/zot/v2/pkg/api/config/redis"
zlog "zotregistry.dev/zot/v2/pkg/log"
"zotregistry.dev/zot/v2/pkg/storage/cache"
"zotregistry.dev/zot/v2/pkg/storage/constants"
storageTypes "zotregistry.dev/zot/v2/pkg/storage/types"
)
func CreateCacheDatabaseDriver(storageConfig config.StorageConfig, log zlog.Logger) (storageTypes.Cache, error) {
if !storageConfig.Dedupe && storageConfig.StorageDriver == nil {
return nil, nil //nolint:nilnil
}
// local cache
if !storageConfig.RemoteCache {
params := cache.BoltDBDriverParameters{}
params.RootDir = storageConfig.RootDirectory
params.Name = constants.BoltdbName
params.UseRelPaths = getUseRelPaths(&storageConfig)
return Create("boltdb", params, log)
}
// remote cache
if storageConfig.CacheDriver != nil {
name, ok := storageConfig.CacheDriver["name"].(string)
if !ok {
log.Warn().Msg("remote cache driver name missing!")
return nil, nil //nolint:nilnil
}
if name != constants.DynamoDBDriverName &&
name != constants.RedisDriverName {
log.Warn().Str("driver", name).Msg("remote cache driver unsupported!")
return nil, nil //nolint:nilnil
}
if name == constants.DynamoDBDriverName {
// dynamodb
dynamoParams, err := getDynamoParams(&storageConfig)
if err != nil {
return nil, err
}
return Create(name, dynamoParams, log)
}
if name == constants.RedisDriverName {
// redis
redisParams, err := getRedisParams(&storageConfig, log)
if err != nil {
return nil, err
}
return Create(name, redisParams, log)
}
}
return nil, nil //nolint:nilnil
}
func Create(dbtype string, parameters interface{}, log zlog.Logger) (storageTypes.Cache, error) {
switch dbtype {
case "boltdb":
{
return cache.NewBoltDBCache(parameters, log)
}
case "dynamodb":
{
return cache.NewDynamoDBCache(parameters, log)
}
case "redis":
{
return cache.NewRedisCache(parameters, log)
}
default:
{
return nil, zerr.ErrBadConfig
}
}
}
func getUseRelPaths(storageConfig *config.StorageConfig) bool {
// In case of local storage we use rel paths, in case of S3 we don't
return storageConfig.StorageDriver == nil
}
func getDynamoParams(storageConfig *config.StorageConfig) (cache.DynamoDBDriverParameters, error) {
dynamoParams := cache.DynamoDBDriverParameters{}
dynamoParams.Endpoint, _ = storageConfig.CacheDriver["endpoint"].(string)
dynamoParams.Region, _ = storageConfig.CacheDriver["region"].(string)
dynamoParams.TableName, _ = storageConfig.CacheDriver["cachetablename"].(string)
cachetable, ok := storageConfig.CacheDriver["cachetablename"]
if !ok {
return dynamoParams, fmt.Errorf("%w: cachetablename key is mandatory for dynamodb cache driver", zerr.ErrBadConfig)
}
dynamoParams.TableName, ok = cachetable.(string)
if !ok {
return dynamoParams, fmt.Errorf("%w: failed to cast cachetablename %s to string type", zerr.ErrBadConfig, cachetable)
}
return dynamoParams, nil
}
func getRedisParams(storageConfig *config.StorageConfig, log zlog.Logger) (cache.RedisDriverParameters, error) {
redisParams := cache.RedisDriverParameters{}
client, err := rediscfg.GetRedisClient(storageConfig.CacheDriver, log)
if err != nil {
return redisParams, err
}
redisParams.RootDir = storageConfig.RootDirectory
redisParams.Client = client
redisParams.KeyPrefix, _ = storageConfig.CacheDriver["keyprefix"].(string)
redisParams.UseRelPaths = getUseRelPaths(storageConfig)
return redisParams, nil
}