chore: update golangci-lint and fix all issues (#3575)

* chore: Update golangci-lint

Signed-off-by: Lars Francke <git@lars-francke.de>

* chore: fix all golangci-lint issues

- Remove deprecated `// +build` tags
- Fix godoclint, modernize, wsl_v5, govet, lll, gci, noctx issues
- Update linter configuration
- Modernize code to use Go 1.22+ features (for range N, slices.Contains, etc.)
- Update make check lint the privileged tests

Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>

---------

Signed-off-by: Lars Francke <git@lars-francke.de>
Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>
Co-authored-by: Lars Francke <git@lars-francke.de>
This commit is contained in:
Andrei Aaron
2025-11-22 23:36:48 +02:00
committed by GitHub
parent 566286ae42
commit da426850e7
242 changed files with 811 additions and 1010 deletions
+1 -1
View File
@@ -67,7 +67,7 @@ func CreateCacheDatabaseDriver(storageConfig config.StorageConfig, log zlog.Logg
return nil, nil //nolint:nilnil
}
func Create(dbtype string, parameters interface{}, log zlog.Logger) (storageTypes.Cache, error) {
func Create(dbtype string, parameters any, log zlog.Logger) (storageTypes.Cache, error) {
switch dbtype {
case "boltdb":
{
+1 -1
View File
@@ -28,7 +28,7 @@ type BoltDBDriverParameters struct {
UseRelPaths bool
}
func NewBoltDBCache(parameters interface{}, log zlog.Logger) (*BoltDBDriver, error) {
func NewBoltDBCache(parameters any, log zlog.Logger) (*BoltDBDriver, error) {
properParameters, ok := parameters.(BoltDBDriverParameters)
if !ok {
log.Error().Err(zerr.ErrTypeAssertionFailed).Msgf("failed to cast type, expected type '%T' but got '%T'",
+8 -9
View File
@@ -2,6 +2,7 @@ package cache
import (
"context"
"slices"
"strings"
"github.com/aws/aws-sdk-go-v2/aws"
@@ -61,7 +62,7 @@ func (d *DynamoDBDriver) NewTable(tableName string) error {
return nil
}
func NewDynamoDBCache(parameters interface{}, log zlog.Logger) (*DynamoDBDriver, error) {
func NewDynamoDBCache(parameters any, log zlog.Logger) (*DynamoDBDriver, error) {
properParameters, ok := parameters.(DynamoDBDriverParameters)
if !ok {
log.Error().Err(zerr.ErrTypeAssertionFailed).Msgf("failed to cast type, expected type '%T' but got '%T'",
@@ -72,7 +73,7 @@ func NewDynamoDBCache(parameters interface{}, log zlog.Logger) (*DynamoDBDriver,
// custom endpoint resolver to point to localhost
customResolver := aws.EndpointResolverWithOptionsFunc( //nolint: staticcheck
func(service, region string, options ...interface{}) (aws.Endpoint, error) {
func(service, region string, options ...any) (aws.Endpoint, error) {
return aws.Endpoint{ //nolint: staticcheck
PartitionID: "aws",
URL: properParameters.Endpoint,
@@ -116,7 +117,7 @@ func (d *DynamoDBDriver) Name() string {
return "dynamodb"
}
// Returns the original blob.
// GetBlob returns the original blob.
func (d *DynamoDBDriver) GetBlob(digest godigest.Digest) (string, error) {
resp, err := d.client.GetItem(context.TODO(), &dynamodb.GetItemInput{
TableName: aws.String(d.tableName),
@@ -231,10 +232,8 @@ func (d *DynamoDBDriver) HasBlob(digest godigest.Digest, path string) bool {
return true
}
for _, item := range out.DuplicateBlobPath {
if item == path {
return true
}
if slices.Contains(out.DuplicateBlobPath, path) {
return true
}
d.log.Debug().Err(zerr.ErrCacheMiss).Str("digest", string(digest)).Msg("failed to find blob in cache")
@@ -243,7 +242,7 @@ func (d *DynamoDBDriver) HasBlob(digest godigest.Digest, path string) bool {
}
func (d *DynamoDBDriver) DeleteBlob(digest godigest.Digest, path string) error {
marshaledKey, _ := attributevalue.MarshalMap(map[string]interface{}{"Digest": digest.String()})
marshaledKey, _ := attributevalue.MarshalMap(map[string]any{"Digest": digest.String()})
expression := "DELETE DuplicateBlobPath :i"
attrPath := types.AttributeValueMemberSS{Value: []string{path}}
@@ -322,7 +321,7 @@ func (d *DynamoDBDriver) putOriginBlob(digest godigest.Digest, path string) erro
func (d *DynamoDBDriver) updateItem(digest godigest.Digest, expression string,
expressionAttVals map[string]types.AttributeValue,
) error {
marshaledKey, _ := attributevalue.MarshalMap(map[string]interface{}{"Digest": digest.String()})
marshaledKey, _ := attributevalue.MarshalMap(map[string]any{"Digest": digest.String()})
_, err := d.client.UpdateItem(context.TODO(), &dynamodb.UpdateItemInput{
Key: marshaledKey,
+1 -1
View File
@@ -32,7 +32,7 @@ type RedisDriverParameters struct {
KeyPrefix string
}
func NewRedisCache(parameters interface{}, log zlog.Logger) (*RedisDriver, error) {
func NewRedisCache(parameters any, log zlog.Logger) (*RedisDriver, error) {
properParameters, ok := parameters.(RedisDriverParameters)
if !ok {
log.Error().Err(zerr.ErrTypeAssertionFailed).Msgf("failed to cast type, expected type '%T' but got '%T'",
+30 -14
View File
@@ -3,6 +3,7 @@ package storage_test
import (
"math/rand"
"os/exec"
"strings"
"testing"
"time"
@@ -27,16 +28,21 @@ func generateData() map[godigest.Digest]string {
//nolint: gosec
seededRand := rand.New(rand.NewSource(time.Now().UnixNano()))
for i := 0; i < datasetSize; i++ {
for range datasetSize {
randomString, _ := test.GenerateRandomString()
counter := 0
var randomStringBuilder strings.Builder
randomStringBuilder.WriteString(randomString)
for seededRand.Float32() < 0.5 && counter < 5 {
counter++
randomString += "/"
randomStringBuilder.WriteString("/")
rs, _ := test.GenerateRandomString()
randomString += rs
randomStringBuilder.WriteString(rs)
}
randomString = randomStringBuilder.String()
digest := godigest.FromString(randomString)
dataMap[digest] = randomString
@@ -71,7 +77,7 @@ func helperGetAll(cache storageTypes.Cache, testData map[godigest.Digest]string)
func helperMix(cache storageTypes.Cache, testData map[godigest.Digest]string, digestSlice []godigest.Digest) {
// The test data contains datasetSize entries by default, and each set of operations uses 5 entries
for i := 0; i < 1000; i++ {
for i := range 1000 {
_ = cache.PutBlob(digestSlice[i*5], testData[digestSlice[i*5]])
_ = cache.PutBlob(digestSlice[i*5+1], testData[digestSlice[i*5+1]])
_ = cache.PutBlob(digestSlice[i*5+2], testData[digestSlice[i*5+2]])
@@ -204,7 +210,8 @@ func BenchmarkPutLocalstack(b *testing.B) {
log.Info().Int64("seed", seed).Msg("random seed for tableName")
// Create Table
_, err := exec.Command("aws", "dynamodb", "--region", region, "--endpoint-url", localEndpoint, "create-table",
_, err := exec.Command( //nolint: noctx
"aws", "dynamodb", "--region", region, "--endpoint-url", localEndpoint, "create-table",
"--table-name", tableName, "--attribute-definitions", "AttributeName=Digest,AttributeType=S",
"--key-schema", "AttributeName=Digest,KeyType=HASH",
"--billing-mode", "PAY_PER_REQUEST").Output()
@@ -230,7 +237,8 @@ func BenchmarkDeleteLocalstack(b *testing.B) {
log.Info().Int64("seed", seed).Msg("random seed for tableName")
// Create Table
_, err := exec.Command("aws", "dynamodb", "--region", region, "--endpoint-url", localEndpoint, "create-table",
_, err := exec.Command( //nolint: noctx
"aws", "dynamodb", "--region", region, "--endpoint-url", localEndpoint, "create-table",
"--table-name", tableName, "--attribute-definitions", "AttributeName=Digest,AttributeType=S",
"--key-schema", "AttributeName=Digest,KeyType=HASH",
"--billing-mode", "PAY_PER_REQUEST").Output()
@@ -260,7 +268,8 @@ func BenchmarkHasLocalstack(b *testing.B) {
log.Info().Int64("seed", seed).Msg("random seed for tableName")
// Create Table
_, err := exec.Command("aws", "dynamodb", "--region", region, "--endpoint-url", localEndpoint, "create-table",
_, err := exec.Command( //nolint: noctx
"aws", "dynamodb", "--region", region, "--endpoint-url", localEndpoint, "create-table",
"--table-name", tableName, "--attribute-definitions", "AttributeName=Digest,AttributeType=S",
"--key-schema", "AttributeName=Digest,KeyType=HASH",
"--billing-mode", "PAY_PER_REQUEST").Output()
@@ -290,7 +299,8 @@ func BenchmarkGetLocalstack(b *testing.B) {
log.Info().Int64("seed", seed).Msg("random seed for tableName")
// Create Table
_, err := exec.Command("aws", "dynamodb", "--region", region, "--endpoint-url", localEndpoint, "create-table",
_, err := exec.Command( //nolint: noctx
"aws", "dynamodb", "--region", region, "--endpoint-url", localEndpoint, "create-table",
"--table-name", tableName, "--attribute-definitions", "AttributeName=Digest,AttributeType=S",
"--key-schema", "AttributeName=Digest,KeyType=HASH",
"--billing-mode", "PAY_PER_REQUEST").Output()
@@ -330,7 +340,8 @@ func BenchmarkMixLocalstack(b *testing.B) {
log.Info().Int64("seed", seed).Msg("random seed for tableName")
// Create Table
_, err := exec.Command("aws", "dynamodb", "--region", region, "--endpoint-url", localEndpoint, "create-table",
_, err := exec.Command( //nolint: noctx
"aws", "dynamodb", "--region", region, "--endpoint-url", localEndpoint, "create-table",
"--table-name", tableName, "--attribute-definitions", "AttributeName=Digest,AttributeType=S",
"--key-schema", "AttributeName=Digest,KeyType=HASH",
"--billing-mode", "PAY_PER_REQUEST").Output()
@@ -367,7 +378,8 @@ func BenchmarkPutAWS(b *testing.B) {
log.Info().Int64("seed", seed).Msg("random seed for tableName")
// Create Table
_, err := exec.Command("aws", "dynamodb", "--region", region, "--endpoint-url", awsEndpoint, "create-table",
_, err := exec.Command( //nolint: noctx
"aws", "dynamodb", "--region", region, "--endpoint-url", awsEndpoint, "create-table",
"--table-name", tableName, "--attribute-definitions", "AttributeName=Digest,AttributeType=S",
"--key-schema", "AttributeName=Digest,KeyType=HASH",
"--billing-mode", "PAY_PER_REQUEST").Output()
@@ -393,7 +405,8 @@ func BenchmarkDeleteAWS(b *testing.B) {
log.Info().Int64("seed", seed).Msg("random seed for tableName")
// Create Table
_, err := exec.Command("aws", "dynamodb", "--region", region, "--endpoint-url", awsEndpoint, "create-table",
_, err := exec.Command( //nolint: noctx
"aws", "dynamodb", "--region", region, "--endpoint-url", awsEndpoint, "create-table",
"--table-name", tableName, "--attribute-definitions", "AttributeName=Digest,AttributeType=S",
"--key-schema", "AttributeName=Digest,KeyType=HASH",
"--billing-mode", "PAY_PER_REQUEST").Output()
@@ -423,7 +436,8 @@ func BenchmarkHasAWS(b *testing.B) {
log.Info().Int64("seed", seed).Msg("random seed for tableName")
// Create Table
_, err := exec.Command("aws", "dynamodb", "--region", region, "--endpoint-url", awsEndpoint, "create-table",
_, err := exec.Command( //nolint: noctx
"aws", "dynamodb", "--region", region, "--endpoint-url", awsEndpoint, "create-table",
"--table-name", tableName, "--attribute-definitions", "AttributeName=Digest,AttributeType=S",
"--key-schema", "AttributeName=Digest,KeyType=HASH",
"--billing-mode", "PAY_PER_REQUEST").Output()
@@ -453,7 +467,8 @@ func BenchmarkGetAWS(b *testing.B) {
log.Info().Int64("seed", seed).Msg("random seed for tableName")
// Create Table
_, err := exec.Command("aws", "dynamodb", "--region", region, "--endpoint-url", awsEndpoint, "create-table",
_, err := exec.Command( //nolint: noctx
"aws", "dynamodb", "--region", region, "--endpoint-url", awsEndpoint, "create-table",
"--table-name", tableName, "--attribute-definitions", "AttributeName=Digest,AttributeType=S",
"--key-schema", "AttributeName=Digest,KeyType=HASH",
"--billing-mode", "PAY_PER_REQUEST").Output()
@@ -493,7 +508,8 @@ func BenchmarkMixAWS(b *testing.B) {
log.Info().Int64("seed", seed).Msg("random seed for tableName")
// Create Table
_, err := exec.Command("aws", "dynamodb", "--region", region, "--endpoint-url", awsEndpoint, "create-table",
_, err := exec.Command( //nolint: noctx
"aws", "dynamodb", "--region", region, "--endpoint-url", awsEndpoint, "create-table",
"--table-name", tableName, "--attribute-definitions", "AttributeName=Digest,AttributeType=S",
"--key-schema", "AttributeName=Digest,KeyType=HASH",
"--billing-mode", "PAY_PER_REQUEST").Output()
+1 -1
View File
@@ -77,7 +77,7 @@ func TestCache(t *testing.T) {
log := log.NewTestLogger()
So(log, ShouldNotBeNil)
cacheDriver, err := storage.Create("sometype", map[string]interface{}{}, log)
cacheDriver, err := storage.Create("sometype", map[string]any{}, log)
So(err, ShouldEqual, errors.ErrBadConfig)
So(cacheDriver, ShouldBeNil)
})
+17 -24
View File
@@ -8,6 +8,7 @@ import (
"fmt"
"math/rand"
"path"
"slices"
"strings"
"time"
@@ -174,7 +175,7 @@ func ValidateManifest(imgStore storageTypes.ImageStore, repo, reference, mediaTy
return nil
}
// Returns the canonical digest or the digest provided by the reference if any
// GetAndValidateRequestDigest returns the canonical digest or the digest provided by the reference if any.
// Per spec, the canonical digest would always be returned to the client in
// request headers, but that does not make sense if the client requested a different digest algorithm
// See https://github.com/opencontainers/distribution-spec/issues/494
@@ -221,7 +222,6 @@ func CheckIfIndexNeedsUpdate(index *ispec.Index, desc *ispec.Descriptor,
updateIndex := true
for midx, manifest := range index.Manifests {
manifest := manifest
if reference == manifest.Digest.String() {
// nothing changed, so don't update
updateIndex = false
@@ -398,11 +398,9 @@ func RemoveManifestDescByReference(index *ispec.Index, reference string, detectC
return removedManifest, nil
}
/*
Unmarshal an image index and for all manifests in that
index, ensure that they do not have a name or they are not in other
manifest indexes else GC can never clean them.
*/
// UpdateIndexWithPrunedImageManifests unmarshals an image index and for all manifests in that
// index, ensures that they do not have a name or they are not in other
// manifest indexes else GC can never clean them.
func UpdateIndexWithPrunedImageManifests(imgStore storageTypes.ImageStore, index *ispec.Index, repo string,
desc ispec.Descriptor, oldDgst godigest.Digest, log zlog.Logger,
) error {
@@ -428,14 +426,11 @@ func UpdateIndexWithPrunedImageManifests(imgStore storageTypes.ImageStore, index
return nil
}
/*
Before an image index manifest is pushed to a repo, its constituent manifests
are pushed first, so when updating/removing this image index manifest, we also
need to determine if there are other image index manifests which refer to the
same constitutent manifests so that they can be garbage-collected correctly
PruneImageManifestsFromIndex is a helper routine to achieve this.
*/
// PruneImageManifestsFromIndex is a helper routine that prunes image manifests from an index.
// Before an image index manifest is pushed to a repo, its constituent manifests
// are pushed first, so when updating/removing this image index manifest, we also
// need to determine if there are other image index manifests which refer to the
// same constitutent manifests so that they can be garbage-collected correctly.
func PruneImageManifestsFromIndex(imgStore storageTypes.ImageStore, repo string, digest godigest.Digest, //nolint:gocyclo,lll
outIndex ispec.Index, otherImgIndexes []ispec.Descriptor, log zlog.Logger,
) ([]ispec.Descriptor, error) {
@@ -736,7 +731,7 @@ func GetReferrers(imgStore storageTypes.ImageStore, repo string, gdigest godiges
// filter by artifact type
manifestArtifactType := zcommon.GetManifestArtifactType(manifestContent)
if len(artifactTypes) > 0 && !zcommon.Contains(artifactTypes, manifestArtifactType) {
if len(artifactTypes) > 0 && !slices.Contains(artifactTypes, manifestArtifactType) {
continue
}
@@ -762,7 +757,7 @@ func GetReferrers(imgStore storageTypes.ImageStore, repo string, gdigest godiges
indexArtifactType := zcommon.GetIndexArtifactType(indexContent)
if len(artifactTypes) > 0 && !zcommon.Contains(artifactTypes, indexArtifactType) {
if len(artifactTypes) > 0 && !slices.Contains(artifactTypes, indexArtifactType) {
continue
}
@@ -786,7 +781,8 @@ func GetReferrers(imgStore storageTypes.ImageStore, repo string, gdigest godiges
return index, nil
}
// Get blob descriptor from it's manifest contents, if blob can not be found it will return error.
// GetBlobDescriptorFromRepo gets blob descriptor from it's manifest contents,
// if blob can not be found it will return error.
func GetBlobDescriptorFromRepo(imgStore storageTypes.ImageStore, repo string, blobDigest godigest.Digest,
log zlog.Logger,
) (ispec.Descriptor, error) {
@@ -906,12 +902,9 @@ func IsEmptyLayersError(err error) bool {
return false
}
/*
DedupeTaskGenerator takes all blobs paths found in the storage.imagestore and groups them by digest
for each digest and based on the dedupe value it will dedupe or restore deduped blobs to the original state(undeduped)\
by creating a task for each digest and pushing it to the task scheduler.
*/
// DedupeTaskGenerator takes all blobs paths found in the storage.imagestore and groups them by digest.
// For each digest and based on the dedupe value it will dedupe or restore deduped blobs
// to the original state(undeduped) by creating a task for each digest and pushing it to the task scheduler.
type DedupeTaskGenerator struct {
ImgStore storageTypes.ImageStore
// storage dedupe value
+5 -7
View File
@@ -6,6 +6,7 @@ import (
"fmt"
"math/rand"
"path"
"slices"
"strconv"
"strings"
"time"
@@ -418,7 +419,7 @@ func (gc GarbageCollect) removeTagsPerRetentionPolicy(ctx context.Context, repo
// check tag
tag, ok := getDescriptorTag(desc)
if ok && !zcommon.Contains(retainTags, tag) {
if ok && !slices.Contains(retainTags, tag) {
// remove tags which should not be retained
_, err := gc.removeManifest(repo, index, desc, tag, "", "")
if err != nil && !errors.Is(err, zerr.ErrManifestNotFound) {
@@ -859,12 +860,9 @@ func getDescriptorTag(desc ispec.Descriptor) (string, bool) {
return tag, ok
}
/*
GCTaskGenerator takes all repositories found in the storage.imagestore
and it will execute garbage collection for each repository by creating a task
for each repository and pushing it to the task scheduler.
*/
// GCTaskGenerator takes all repositories found in the storage.imagestore
// and it will execute garbage collection for each repository by creating a task
// for each repository and pushing it to the task scheduler.
type GCTaskGenerator struct {
imgStore types.ImageStore
gc GarbageCollect
+4 -7
View File
@@ -68,7 +68,6 @@ func TestGarbageCollectAndRetentionMetaDB(t *testing.T) {
trueVal := true
for _, testcase := range testCases {
testcase := testcase
t.Run(testcase.testCaseName, func(t *testing.T) {
var imgStore storageTypes.ImageStore
@@ -89,7 +88,7 @@ func TestGarbageCollectAndRetentionMetaDB(t *testing.T) {
bucket := "zot-storage-test"
storageDriverParams := map[string]interface{}{
storageDriverParams := map[string]any{
"rootDir": rootDir,
"name": "s3",
"region": region,
@@ -1762,7 +1761,6 @@ func TestGarbageCollectAndRetentionNoMetaDB(t *testing.T) {
trueVal := true
for _, testcase := range testCases {
testcase := testcase
t.Run(testcase.testCaseName, func(t *testing.T) {
var imgStore storageTypes.ImageStore
@@ -1783,7 +1781,7 @@ func TestGarbageCollectAndRetentionNoMetaDB(t *testing.T) {
bucket := "zot-storage-test"
storageDriverParams := map[string]interface{}{
storageDriverParams := map[string]any{
"rootDir": rootDir,
"name": "s3",
"region": region,
@@ -2197,13 +2195,12 @@ func TestGarbageCollectAndRetentionNoMetaDB(t *testing.T) {
t.Logf("index %d, repo '%s'", i, repo)
So(err, ShouldBeNil)
if i >= 5 {
if i >= len(expectedRepos) {
So(repo, ShouldEqual, "")
continue
} else {
So(repo, ShouldEqual, expectedRepos[i])
}
So(repo, ShouldEqual, expectedRepos[i])
processedRepos[repo] = struct{}{}
+6 -8
View File
@@ -9,6 +9,7 @@ import (
"io"
"path"
"path/filepath"
"slices"
"strings"
"sync"
"time"
@@ -1315,11 +1316,8 @@ func (is *ImageStore) GetAllDedupeReposCandidates(digest godigest.Digest) ([]str
return repos, nil
}
/*
CheckBlob verifies a blob and returns true if the blob is correct
If the blob is not found but it's found in cache then it will be copied over.
*/
// CheckBlob verifies a blob and returns true if the blob is correct.
// If the blob is not found but it's found in cache then it will be copied over.
func (is *ImageStore) CheckBlob(repo string, digest godigest.Digest) (bool, int64, error) {
var lockLatency time.Time
@@ -1918,7 +1916,7 @@ func (is *ImageStore) GetNextDigestWithBlobPaths(repos []string, lastDigests []g
if fileInfo.IsDir() {
// skip repositories not found in repos
baseName := path.Base(fileInfo.Path())
if zcommon.Contains(repos, baseName) || baseName == ispec.ImageBlobsDir {
if slices.Contains(repos, baseName) || baseName == ispec.ImageBlobsDir {
return nil
}
@@ -1934,7 +1932,7 @@ func (is *ImageStore) GetNextDigestWithBlobPaths(repos []string, lastDigests []g
baseName := path.Base(fileInfo.Path())
skippedFiles := []string{ispec.ImageLayoutFile, ispec.ImageIndexFile, "meta.db", "cache.db"}
if zcommon.Contains(skippedFiles, baseName) {
if slices.Contains(skippedFiles, baseName) {
return nil
}
@@ -1950,7 +1948,7 @@ func (is *ImageStore) GetNextDigestWithBlobPaths(repos []string, lastDigests []g
return nil //nolint: nilerr // ignore files which are not blobs
}
if digest == "" && !zcommon.Contains(lastDigests, blobDigest) {
if digest == "" && !slices.Contains(lastDigests, blobDigest) {
digest = blobDigest
}
+1
View File
@@ -319,6 +319,7 @@ func (driver *Driver) formatErr(err error) error {
type fileInfo struct {
os.FileInfo
path string
}
+1
View File
@@ -700,6 +700,7 @@ var (
// mockFile implements FileInterface for testing sync behavior.
type mockFile struct {
*os.File
syncCalled bool
syncError error
closeError error
+2 -1
View File
@@ -1,5 +1,4 @@
//go:build needprivileges
// +build needprivileges
package local_test
@@ -81,6 +80,7 @@ func TestElevatedPrivilegesInvalidDedupe(t *testing.T) {
So(err, ShouldBeNil)
So(blob, ShouldEqual, buflen)
//nolint: noctx // old code, no context available
cmd := exec.Command("chattr", "+i", path.Join(dir, "dedupe2", "blobs/sha256", blobDigest1)) //nolint: gosec
_, err = cmd.Output()
@@ -92,6 +92,7 @@ func TestElevatedPrivilegesInvalidDedupe(t *testing.T) {
So(err, ShouldNotBeNil)
So(blob, ShouldEqual, buflen)
//nolint: noctx // old code, no context available
cmd = exec.Command("chattr", "-i", path.Join(dir, "dedupe2", "blobs/sha256", blobDigest1)) //nolint: gosec
_, err = cmd.Output()
+3 -3
View File
@@ -1297,7 +1297,7 @@ func TestDedupeLinks(t *testing.T) {
})
Convey("Intrerrupt rebuilding and restart, checking idempotency", func() {
for i := 0; i < 10; i++ {
for i := range 10 {
taskScheduler := runAndGetScheduler()
defer taskScheduler.Shutdown()
@@ -1860,7 +1860,7 @@ func TestNegativeCases(t *testing.T) {
Convey("DirExists call with name too long as argument", t, func(c C) {
var builder strings.Builder
for i := 0; i < 1025; i++ {
for range 1025 {
_, err := builder.WriteString("0")
if err != nil {
t.Fatal(err)
@@ -2444,7 +2444,7 @@ func TestGarbageCollectErrors(t *testing.T) {
index.SchemaVersion = 2
index.MediaType = ispec.MediaTypeImageIndex
for i := 0; i < 4; i++ {
for range 4 {
// upload image config blob
upload, err = imgStore.NewBlobUpload(repoName)
So(err, ShouldBeNil)
+3 -6
View File
@@ -104,12 +104,9 @@ func (driver *Driver) SameFile(path1, path2 string) bool {
return false
}
/*
Link put an empty file that will act like a link between the original file and deduped one
because s3 doesn't support symlinks, wherever the storage will encounter an empty file, it will get the original one
from cache.
*/
// Link puts an empty file that will act like a link between the original file and deduped one.
// Because s3 doesn't support symlinks, wherever the storage will encounter an empty file, it will get the original one
// from cache.
func (driver *Driver) Link(src, dest string) error {
return driver.store.PutContent(context.Background(), dest, []byte{})
}
+1 -1
View File
@@ -15,7 +15,7 @@ import (
storageTypes "zotregistry.dev/zot/v2/pkg/storage/types"
)
// NewObjectStorage returns a new image store backed by cloud storages.
// NewImageStore returns a new image store backed by cloud storages.
// see https://github.com/docker/docker.github.io/tree/master/registry/storage-drivers
// Use the last argument to properly set a cache database, or it will default to boltDB local storage.
func NewImageStore(rootDir string, cacheDir string, dedupe, commit bool, log zlog.Logger,
+5 -5
View File
@@ -93,7 +93,7 @@ func createMockStorageWithMockCache(rootDir string, dedupe bool, store driver.St
func createStoreDriver(rootDir string) driver.StorageDriver {
bucket := zotStorageTest
endpoint := os.Getenv("S3MOCK_ENDPOINT")
storageDriverParams := map[string]interface{}{
storageDriverParams := map[string]any{
"rootDir": rootDir,
"name": "s3",
"region": s3Region,
@@ -368,7 +368,7 @@ func (s *StorageDriverMock) Delete(ctx context.Context, path string) error {
return nil
}
func (s *StorageDriverMock) URLFor(ctx context.Context, path string, options map[string]interface{}) (string, error) {
func (s *StorageDriverMock) URLFor(ctx context.Context, path string, options map[string]any) (string, error) {
return "", nil
}
@@ -683,7 +683,7 @@ func TestNegativeCasesObjectsStorage(t *testing.T) {
"/a": {
Dedupe: true,
RootDirectory: t.TempDir(),
StorageDriver: map[string]interface{}{
StorageDriver: map[string]any{
"rootDir": "/a",
"name": "s3",
"region": s3Region,
@@ -2018,7 +2018,7 @@ func TestRebuildDedupeIndex(t *testing.T) {
So(configFi2.Size(), ShouldEqual, 0)
Convey("Intrerrupt rebuilding and restart, checking idempotency", func() {
for i := 0; i < 10; i++ {
for i := range 10 {
log := log.NewTestLogger()
metrics := monitoring.NewMetricsServer(false, log)
taskScheduler := scheduler.NewScheduler(config.New(), metrics, log)
@@ -2060,7 +2060,7 @@ func TestRebuildDedupeIndex(t *testing.T) {
So(configFi2.Size(), ShouldEqual, configFi1.Size())
// now from dedupe false to true
for i := 0; i < 10; i++ {
for i := range 10 {
log := log.NewTestLogger()
metrics := monitoring.NewMetricsServer(false, log)
taskScheduler := scheduler.NewScheduler(config.New(), metrics, log)
+2
View File
@@ -26,7 +26,9 @@ const (
colStatusIndex
colAffectedBlobIndex
colErrorIndex
)
const (
imageNameWidth = 32
tagWidth = 24
statusWidth = 8
+1 -1
View File
@@ -68,7 +68,7 @@ func TestRedisCheckAllBlobsIntegrity(t *testing.T) {
metrics := monitoring.NewMetricsServer(false, log)
client, _ := rediscfg.GetRedisClient(map[string]interface{}{"url": "redis://" + miniRedis.Addr()}, log)
client, _ := rediscfg.GetRedisClient(map[string]any{"url": "redis://" + miniRedis.Addr()}, log)
cacheDriver, _ := storage.Create("redis", cache.RedisDriverParameters{
Client: client,
+10 -19
View File
@@ -87,7 +87,7 @@ func createObjectsStore(options createObjectStoreOpts) (
}
if options.cacheType == storageConstants.RedisDriverName {
client, _ := rediscfg.GetRedisClient(map[string]interface{}{"url": options.miniRedisAddr}, log)
client, _ := rediscfg.GetRedisClient(map[string]any{"url": options.miniRedisAddr}, log)
cacheDriver, _ = storage.Create("redis", cache.RedisDriverParameters{
Client: client,
@@ -115,7 +115,7 @@ func createObjectsStore(options createObjectStoreOpts) (
bucket := "zot-storage-test"
endpoint := os.Getenv("S3MOCK_ENDPOINT")
storageDriverParams := map[string]interface{}{
storageDriverParams := map[string]any{
"rootDir": options.rootDir,
"name": "s3",
"region": "us-east-2",
@@ -180,7 +180,7 @@ func TestStorageNew(t *testing.T) {
// store name is wrong
conf := config.New()
conf.Storage.RootDirectory = "dir"
conf.Storage.StorageDriver = map[string]interface{}{}
conf.Storage.StorageDriver = map[string]any{}
_, err := storage.New(conf, nil, nil, zlog.NewTestLogger(), nil)
So(err, ShouldNotBeNil)
@@ -189,7 +189,6 @@ func TestStorageNew(t *testing.T) {
func TestGetAllDedupeReposCandidates(t *testing.T) {
for _, testcase := range testCases {
testcase := testcase
t.Run(testcase.testCaseName, func(t *testing.T) {
var imgStore storageTypes.ImageStore
@@ -262,7 +261,6 @@ func TestGetAllDedupeReposCandidates(t *testing.T) {
func TestStorageAPIs(t *testing.T) {
for _, testcase := range testCases {
testcase := testcase
t.Run(testcase.testCaseName, func(t *testing.T) {
var imgStore storageTypes.ImageStore
@@ -975,7 +973,7 @@ func TestStorageAPIs(t *testing.T) {
Convey("Locks", func() {
// in parallel, a mix of read and write locks - mainly for coverage
var wg sync.WaitGroup
for i := 0; i < 1000; i++ {
for range 1000 {
wg.Add(2)
go func() {
@@ -1005,7 +1003,6 @@ func TestStorageAPIs(t *testing.T) {
func TestMandatoryAnnotations(t *testing.T) {
for _, testcase := range testCases {
testcase := testcase
t.Run(testcase.testCaseName, func(t *testing.T) {
var (
imgStore storageTypes.ImageStore
@@ -1163,7 +1160,7 @@ func TestStorageSubpaths(t *testing.T) {
"a/": {
RootDirectory: tmpDirSubpath,
RemoteCache: true,
StorageDriver: map[string]interface{}{},
StorageDriver: map[string]any{},
Dedupe: true,
},
},
@@ -1191,7 +1188,7 @@ func TestStorageSubpaths(t *testing.T) {
"a/": {
RootDirectory: tmpDirSubpath,
RemoteCache: true,
StorageDriver: map[string]interface{}{
StorageDriver: map[string]any{
"name": "bad-name",
},
},
@@ -1206,7 +1203,6 @@ func TestStorageSubpaths(t *testing.T) {
func TestDeleteBlobsInUse(t *testing.T) {
for _, testcase := range testCases {
testcase := testcase
t.Run(testcase.testCaseName, func(t *testing.T) {
var imgStore storageTypes.ImageStore
@@ -1379,7 +1375,7 @@ func TestDeleteBlobsInUse(t *testing.T) {
var cblob []byte
//nolint: dupl
for i := 0; i < 4; i++ {
for range 4 {
// upload image config blob
upload, err = imgStore.NewBlobUpload(repoName)
So(err, ShouldBeNil)
@@ -1515,7 +1511,6 @@ func TestDeleteBlobsInUse(t *testing.T) {
func TestReuploadCorruptedBlob(t *testing.T) {
for _, testcase := range testCases {
testcase := testcase
t.Run(testcase.testCaseName, func(t *testing.T) {
var (
imgStore storageTypes.ImageStore
@@ -1650,7 +1645,6 @@ func TestReuploadCorruptedBlob(t *testing.T) {
func TestStorageHandler(t *testing.T) {
for _, testcase := range testCases {
testcase := testcase
t.Run(testcase.testCaseName, func(t *testing.T) {
var (
firstStore storageTypes.ImageStore
@@ -1764,7 +1758,6 @@ func TestRoutePrefix(t *testing.T) {
func TestGarbageCollectImageManifest(t *testing.T) {
for _, testcase := range testCases {
testcase := testcase
t.Run(testcase.testCaseName, func(t *testing.T) {
log := zlog.NewTestLogger()
audit := zlog.NewAuditLogger("debug", "")
@@ -2448,7 +2441,6 @@ func TestGarbageCollectImageManifest(t *testing.T) {
func TestGarbageCollectImageIndex(t *testing.T) {
for _, testcase := range testCases {
testcase := testcase
t.Run(testcase.testCaseName, func(t *testing.T) {
log := zlog.NewTestLogger()
audit := zlog.NewAuditLogger("debug", "")
@@ -2856,7 +2848,6 @@ func TestGarbageCollectImageIndex(t *testing.T) {
func TestGarbageCollectChainedImageIndexes(t *testing.T) {
for _, testcase := range testCases {
testcase := testcase
t.Run(testcase.testCaseName, func(t *testing.T) {
log := zlog.NewTestLogger()
audit := zlog.NewAuditLogger("debug", "")
@@ -2960,7 +2951,7 @@ func TestGarbageCollectChainedImageIndexes(t *testing.T) {
var digest godigest.Digest
for i := 0; i < 4; i++ { //nolint: dupl
for range 4 { //nolint: dupl
// upload image config blob
upload, err := imgStore.NewBlobUpload(repoName)
So(err, ShouldBeNil)
@@ -3043,7 +3034,7 @@ func TestGarbageCollectChainedImageIndexes(t *testing.T) {
innerIndex.SchemaVersion = 2
innerIndex.MediaType = ispec.MediaTypeImageIndex
for i := 0; i < 3; i++ { //nolint: dupl
for range 3 { //nolint: dupl
// upload image config blob
upload, err := imgStore.NewBlobUpload(repoName)
So(err, ShouldBeNil)
@@ -3349,7 +3340,7 @@ func pushRandomImageIndex(imgStore storageTypes.ImageStore, repoName string,
var digest godigest.Digest
for i := 0; i < 4; i++ { //nolint: dupl
for range 4 { //nolint: dupl
// upload image config blob
upload, err := imgStore.NewBlobUpload(repoName)
So(err, ShouldBeNil)