mirror of
https://github.com/project-zot/zot.git
synced 2026-06-17 21:17:58 +08:00
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:
@@ -1,5 +1,4 @@
|
||||
//go:build sync
|
||||
// +build sync
|
||||
|
||||
package sync
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
//go:build sync
|
||||
// +build sync
|
||||
|
||||
package sync_test //nolint: testpackage
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
//go:build sync
|
||||
// +build sync
|
||||
|
||||
package sync
|
||||
|
||||
@@ -10,6 +9,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/distribution/distribution/v3/registry/storage/driver"
|
||||
@@ -53,7 +53,7 @@ func NewDestinationRegistry(
|
||||
}
|
||||
}
|
||||
|
||||
// Check if image is already synced.
|
||||
// CanSkipImage checks if image is already synced.
|
||||
func (registry *DestinationRegistry) CanSkipImage(repo, tag string, digest godigest.Digest) (bool, error) {
|
||||
// check image already synced
|
||||
imageStore := registry.storeController.GetImageStore(repo)
|
||||
@@ -86,7 +86,7 @@ func (registry *DestinationRegistry) GetImageReference(repo, reference string) (
|
||||
return registry.tempStorage.GetImageReference(repo, reference)
|
||||
}
|
||||
|
||||
// finalize a syncing image.
|
||||
// CommitAll finalizes a syncing image.
|
||||
func (registry *DestinationRegistry) CommitAll(repo string, imageReference ref.Ref) error {
|
||||
tempImageStore := getImageStoreFromImageReference(repo, imageReference, registry.log)
|
||||
|
||||
@@ -145,7 +145,7 @@ func (registry *DestinationRegistry) copyManifest(repo string, desc ispec.Descri
|
||||
var err error
|
||||
|
||||
// seen
|
||||
if common.Contains(*seen, desc.Digest) {
|
||||
if slices.Contains(*seen, desc.Digest) {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
//go:build sync
|
||||
// +build sync
|
||||
|
||||
package sync
|
||||
|
||||
@@ -73,7 +72,7 @@ func extractAccountAndRegion(url string) (string, string, error) {
|
||||
return accountID, region, nil
|
||||
}
|
||||
|
||||
// getMockECRCredentials provides mock credentials for testing purposes.
|
||||
// GetMockECRCredentials provides mock credentials for testing purposes.
|
||||
func GetMockECRCredentials(remoteAddress string) (ecrCredential, error) {
|
||||
// Extract account ID and region from the URL.
|
||||
accountID, region, err := extractAccountAndRegion(remoteAddress)
|
||||
@@ -91,7 +90,7 @@ func GetMockECRCredentials(remoteAddress string) (ecrCredential, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// getECRCredentials retrieves actual ECR credentials using AWS SDK.
|
||||
// GetECRCredentials retrieves actual ECR credentials using AWS SDK.
|
||||
func GetECRCredentials(remoteAddress string) (ecrCredential, error) {
|
||||
// Extract account ID and region from the URL.
|
||||
accountID, region, err := extractAccountAndRegion(remoteAddress)
|
||||
@@ -137,7 +136,7 @@ func GetECRCredentials(remoteAddress string) (ecrCredential, error) {
|
||||
return ecrCredential{username: username, password: password, expiry: expiry, account: accountID, region: region}, nil
|
||||
}
|
||||
|
||||
// GetECRCredentials retrieves the ECR credentials (username and password) from AWS ECR.
|
||||
// GetCredentials retrieves the ECR credentials (username and password) from AWS ECR.
|
||||
func (credHelper *ecrCredentialsHelper) GetCredentials(urls []string) (syncconf.CredentialsFile, error) {
|
||||
ecrCredentials := make(syncconf.CredentialsFile)
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
//go:build sync
|
||||
// +build sync
|
||||
|
||||
package sync
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
//go:build sync
|
||||
// +build sync
|
||||
|
||||
package sync
|
||||
|
||||
@@ -23,9 +22,9 @@ type request struct {
|
||||
}
|
||||
|
||||
/*
|
||||
a request can be an image/signature/sbom
|
||||
BaseOnDemand tracks requests that can be an image/signature/sbom.
|
||||
|
||||
keep track of all parallel requests, if two requests of same image/signature/sbom comes at the same time,
|
||||
It keeps track of all parallel requests, if two requests of same image/signature/sbom comes at the same time,
|
||||
process just the first one, also keep track of all background retrying routines.
|
||||
*/
|
||||
type BaseOnDemand struct {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
//go:build !sync
|
||||
// +build !sync
|
||||
|
||||
package sync
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
//go:build sync
|
||||
// +build sync
|
||||
|
||||
package sync
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
//go:build sync
|
||||
// +build sync
|
||||
|
||||
package sync
|
||||
|
||||
@@ -195,7 +194,7 @@ func (registry *RemoteRegistry) GetDigest(ctx context.Context, repo, tag string,
|
||||
return man.GetDescriptor().Digest, err
|
||||
}
|
||||
|
||||
// returns OCI remote digest, original remote digest (unconverted), if it was converted.
|
||||
// GetOCIDigest returns OCI remote digest, original remote digest (unconverted), if it was converted.
|
||||
func (registry *RemoteRegistry) GetOCIDigest(ctx context.Context, repo, tag string,
|
||||
) (godigest.Digest, godigest.Digest, bool, error) {
|
||||
var isConverted bool
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
//go:build sync
|
||||
// +build sync
|
||||
|
||||
package sync
|
||||
|
||||
@@ -27,7 +26,7 @@ func newTagsCache(expireAfter time.Duration) *tagsCache {
|
||||
}
|
||||
}
|
||||
|
||||
// returns true if still valid (not expired) and tags list.
|
||||
// Get returns true if still valid (not expired) and tags list.
|
||||
func (c *tagsCache) Get(repo string) (bool, []string) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
//go:build sync
|
||||
// +build sync
|
||||
|
||||
package sync
|
||||
|
||||
@@ -9,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -397,7 +397,7 @@ func (service *BaseService) SyncReferrers(ctx context.Context, repo string,
|
||||
return nil
|
||||
}
|
||||
|
||||
// sync repo periodically.
|
||||
// SyncRepo syncs repo periodically.
|
||||
func (service *BaseService) SyncRepo(ctx context.Context, repo string) error {
|
||||
service.log.Info().Str("repo", repo).Str("registry", service.remote.GetHostName()).
|
||||
Msg("sync: syncing repo")
|
||||
@@ -590,7 +590,7 @@ func (service *BaseService) syncImage(ctx context.Context, localRepo, remoteRepo
|
||||
}
|
||||
|
||||
// verify repo contains a cosign signature for this manifest
|
||||
hasCosignSignature := common.Contains(repoTags, fmt.Sprintf("%s-%s.sig", remoteDigest.Algorithm(),
|
||||
hasCosignSignature := slices.Contains(repoTags, fmt.Sprintf("%s-%s.sig", remoteDigest.Algorithm(),
|
||||
remoteDigest.Encoded()))
|
||||
|
||||
isSigned := hasSignatureReferrers(referrers) || hasCosignSignature
|
||||
@@ -721,7 +721,7 @@ func (service *BaseService) syncReferrers(ctx context.Context, tags []string, lo
|
||||
}
|
||||
|
||||
// is seen
|
||||
if common.Contains(seen, remoteDigest.String()) {
|
||||
if slices.Contains(seen, remoteDigest.String()) {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
//go:build sync
|
||||
// +build sync
|
||||
|
||||
package sync
|
||||
|
||||
@@ -20,7 +19,7 @@ import (
|
||||
// below types are used by regclient to copy images
|
||||
// ref.Ref- describes a registry/repo:tag
|
||||
|
||||
// Sync general functionalities, one service per registry config.
|
||||
// Service provides sync general functionalities, one service per registry config.
|
||||
type Service interface {
|
||||
// Get next repo from remote /v2/_catalog, will return empty string when there is no repo left.
|
||||
GetNextRepo(lastRepo string) (string, error) // used by task scheduler
|
||||
@@ -39,7 +38,7 @@ type Service interface {
|
||||
GetSyncTimeout() time.Duration
|
||||
}
|
||||
|
||||
// Local and remote registries must implement this interface.
|
||||
// Registry interface must be implemented by local and remote registries.
|
||||
type Registry interface {
|
||||
// Get temporary ImageReference, is used by functions in regclient package
|
||||
GetImageReference(repo string, tag string) (ref.Ref, error)
|
||||
@@ -62,7 +61,7 @@ type CredentialHelper interface {
|
||||
}
|
||||
|
||||
/*
|
||||
Temporary oci layout, sync first pulls an image to this oci layout (using oci:// transport)
|
||||
OciLayoutStorage is a temporary oci layout, sync first pulls an image to this oci layout (using oci:// transport)
|
||||
then moves them into ImageStore.
|
||||
*/
|
||||
type OciLayoutStorage interface {
|
||||
@@ -85,7 +84,7 @@ type Remote interface {
|
||||
GetDigest(ctx context.Context, repo, tag string) (godigest.Digest, error)
|
||||
}
|
||||
|
||||
// Local registry.
|
||||
// Destination is a local registry.
|
||||
type Destination interface {
|
||||
Registry
|
||||
// Check if descriptors are already synced
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
//go:build !sync
|
||||
// +build !sync
|
||||
|
||||
package sync_test
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
//go:build sync
|
||||
// +build sync
|
||||
|
||||
package sync
|
||||
|
||||
@@ -225,7 +224,7 @@ func TestService(t *testing.T) {
|
||||
|
||||
// Step 1: Verify empty requestStore initially
|
||||
initialImageCount := 0
|
||||
onDemand.requestStore.Range(func(key, value interface{}) bool {
|
||||
onDemand.requestStore.Range(func(key, value any) bool {
|
||||
initialImageCount++
|
||||
return true
|
||||
})
|
||||
@@ -242,7 +241,7 @@ func TestService(t *testing.T) {
|
||||
|
||||
// Step 3: Verify we now have 1 request
|
||||
preImageCount := 0
|
||||
onDemand.requestStore.Range(func(key, value interface{}) bool {
|
||||
onDemand.requestStore.Range(func(key, value any) bool {
|
||||
preImageCount++
|
||||
return true
|
||||
})
|
||||
@@ -254,7 +253,7 @@ func TestService(t *testing.T) {
|
||||
|
||||
// Step 5: Verify CONTINUE PATH EXECUTED - no new requests created
|
||||
postImageCount := 0
|
||||
onDemand.requestStore.Range(func(key, value interface{}) bool {
|
||||
onDemand.requestStore.Range(func(key, value any) bool {
|
||||
postImageCount++
|
||||
return true
|
||||
})
|
||||
@@ -267,7 +266,7 @@ func TestService(t *testing.T) {
|
||||
|
||||
// Step 7: Verify current state before referrer test - we should have 1 request
|
||||
initialReferrerCount := 0
|
||||
onDemand.requestStore.Range(func(key, value interface{}) bool {
|
||||
onDemand.requestStore.Range(func(key, value any) bool {
|
||||
initialReferrerCount++
|
||||
return true
|
||||
})
|
||||
@@ -284,7 +283,7 @@ func TestService(t *testing.T) {
|
||||
|
||||
// Step 9: Verify we now have 2 requests (image + referrer)
|
||||
preReferrerCount := 0
|
||||
onDemand.requestStore.Range(func(key, value interface{}) bool {
|
||||
onDemand.requestStore.Range(func(key, value any) bool {
|
||||
preReferrerCount++
|
||||
return true
|
||||
})
|
||||
@@ -296,7 +295,7 @@ func TestService(t *testing.T) {
|
||||
|
||||
// Step 11: Verify CONTINUE PATH EXECUTED - no new referrer requests created
|
||||
postReferrerCount := 0
|
||||
onDemand.requestStore.Range(func(key, value interface{}) bool {
|
||||
onDemand.requestStore.Range(func(key, value any) bool {
|
||||
postReferrerCount++
|
||||
return true
|
||||
})
|
||||
@@ -309,7 +308,7 @@ func TestService(t *testing.T) {
|
||||
|
||||
// Step 13: Final verification - exactly 2 requests total (both pre-populated, none deleted)
|
||||
finalCount := 0
|
||||
onDemand.requestStore.Range(func(key, value interface{}) bool {
|
||||
onDemand.requestStore.Range(func(key, value any) bool {
|
||||
finalCount++
|
||||
return true
|
||||
})
|
||||
@@ -434,7 +433,7 @@ func TestService(t *testing.T) {
|
||||
|
||||
// Verify initial requestStore is empty
|
||||
initialCount := 0
|
||||
onDemand.requestStore.Range(func(key, value interface{}) bool {
|
||||
onDemand.requestStore.Range(func(key, value any) bool {
|
||||
initialCount++
|
||||
return true
|
||||
})
|
||||
@@ -475,7 +474,7 @@ func TestService(t *testing.T) {
|
||||
|
||||
// Verify initial requestStore is empty
|
||||
initialCount := 0
|
||||
onDemand.requestStore.Range(func(key, value interface{}) bool {
|
||||
onDemand.requestStore.Range(func(key, value any) bool {
|
||||
initialCount++
|
||||
return true
|
||||
})
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
//go:build sync
|
||||
// +build sync
|
||||
|
||||
package sync_test
|
||||
|
||||
@@ -5638,7 +5637,7 @@ func TestOnDemandMultipleImage(t *testing.T) {
|
||||
defer dcm.StopServer()
|
||||
|
||||
callsNo := 5
|
||||
for i := 0; i < callsNo; i++ {
|
||||
for range callsNo {
|
||||
_, _ = destClient.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
||||
}
|
||||
|
||||
@@ -5801,7 +5800,7 @@ func TestOnDemandPullsReferrersOnce(t *testing.T) {
|
||||
|
||||
targetURL := destBaseURL + "/v2/" + testImage + "/referrers/" + digest
|
||||
|
||||
for i := 0; i < numConcurrentRequests; i++ {
|
||||
for i := range numConcurrentRequests {
|
||||
go func(routineID int) {
|
||||
defer wg.Done()
|
||||
t.Logf("Goroutine %d: Sending request to %s", routineID, targetURL)
|
||||
@@ -5928,7 +5927,7 @@ func TestOnDemandPullsOnce(t *testing.T) {
|
||||
|
||||
targetURL := destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag
|
||||
|
||||
for i := 0; i < numConcurrentRequests; i++ {
|
||||
for i := range numConcurrentRequests {
|
||||
go func(routineID int) {
|
||||
defer wg.Done()
|
||||
t.Logf("Goroutine %d: Sending request to %s", routineID, targetURL)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
//go:build sync
|
||||
// +build sync
|
||||
|
||||
package sync
|
||||
|
||||
|
||||
Reference in New Issue
Block a user