Skip to content

Commit

Permalink
fix: update go.mod (vendor) & golangci-lint & mocks (#20070)
Browse files Browse the repository at this point in the history
* fix: update go.mod

Signed-off-by: Shengwen Yu <yshengwen@vmware.com>

* fix: update vendor files

Signed-off-by: Shengwen Yu <yshengwen@vmware.com>

* fix: update code to comply for golangci-lint

Signed-off-by: Shengwen Yu <yshengwen@vmware.com>

* fix: update per "make mocks_check"

Signed-off-by: Shengwen Yu <yshengwen@vmware.com>

---------

Signed-off-by: Shengwen Yu <yshengwen@vmware.com>
  • Loading branch information
zyyw committed Mar 4, 2024
1 parent 2196ba7 commit f65d238
Show file tree
Hide file tree
Showing 910 changed files with 40,723 additions and 26,479 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ misspell:
@find . -type d \( -path ./src/vendor -o -path ./tests \) -prune -o -name '*.go' -print | xargs misspell -error

# golangci-lint binary installation or refer to https://golangci-lint.run/usage/install/#local-installation
# curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.51.2
# curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.56.2
GOLANGCI_LINT := $(shell go env GOPATH)/bin/golangci-lint
lint:
@echo checking lint
Expand Down
2 changes: 1 addition & 1 deletion src/common/rbac/project/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func NewBuilderForUser(user *models.User, ctl project.Controller) RBACUserBuilde
// NewBuilderForPolicies create a builder for the policies
func NewBuilderForPolicies(username string, policies []*types.Policy,
filters ...func(*proModels.Project, []*types.Policy) []*types.Policy) RBACUserBuilder {
return func(ctx context.Context, p *proModels.Project) types.RBACUser {
return func(_ context.Context, p *proModels.Project) types.RBACUser {
for _, filter := range filters {
policies = filter(p, policies)
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/rbac/system/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

// NewEvaluator create evaluator for the system
func NewEvaluator(username string, policies []*types.Policy) evaluator.Evaluator {
return namespace.New(NamespaceKind, func(ctx context.Context, ns types.Namespace) evaluator.Evaluator {
return namespace.New(NamespaceKind, func(_ context.Context, _ types.Namespace) evaluator.Evaluator {
return rbac.New(&rbacUser{
username: username,
policies: policies,
Expand Down
2 changes: 1 addition & 1 deletion src/common/security/secret/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (s *SecurityContext) IsSolutionUser() bool {
// Can returns whether the user can do action on resource
// returns true if the corresponding user of the secret
// is jobservice or core service, otherwise returns false
func (s *SecurityContext) Can(ctx context.Context, action types.Action, resource types.Resource) bool {
func (s *SecurityContext) Can(_ context.Context, _ types.Action, _ types.Resource) bool {
if s.store == nil {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/security/v2token/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (t *tokenSecurityCtx) GetMyProjects() ([]*models.Project, error) {
return []*models.Project{}, nil
}

func (t *tokenSecurityCtx) GetProjectRoles(projectIDOrName interface{}) []int {
func (t *tokenSecurityCtx) GetProjectRoles(_ interface{}) []int {
return []int{}
}

Expand Down
2 changes: 1 addition & 1 deletion src/common/utils/test/registryctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type GCResult struct {
}

// NewRegistryCtl returns a mock registry server
func NewRegistryCtl(config map[string]interface{}) (*httptest.Server, error) {
func NewRegistryCtl(_ map[string]interface{}) (*httptest.Server, error) {
m := []*RequestHandlerMapping{}

gcr := GCResult{true, "hello-world", time.Now(), time.Now()}
Expand Down
2 changes: 1 addition & 1 deletion src/common/utils/uaa/fake_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (fc *FakeClient) GetUserInfo(token string) (*UserInfo, error) {
}

// UpdateConfig ...
func (fc *FakeClient) UpdateConfig(cfg *ClientConfig) error {
func (fc *FakeClient) UpdateConfig(_ *ClientConfig) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion src/controller/artifact/annotation/v1alpha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type v1alpha1Parser struct {
regCli reg.Client
}

func (p *v1alpha1Parser) Parse(ctx context.Context, artifact *artifact.Artifact, manifest []byte) error {
func (p *v1alpha1Parser) Parse(_ context.Context, artifact *artifact.Artifact, manifest []byte) error {
if artifact.ManifestMediaType != v1.MediaTypeImageManifest && artifact.ManifestMediaType != schema2.MediaTypeManifest {
return nil
}
Expand Down
8 changes: 4 additions & 4 deletions src/controller/artifact/processor/base/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@ type IndexProcessor struct {
}

// AbstractMetadata abstracts metadata of artifact
func (m *IndexProcessor) AbstractMetadata(ctx context.Context, artifact *artifact.Artifact, content []byte) error {
func (m *IndexProcessor) AbstractMetadata(_ context.Context, _ *artifact.Artifact, _ []byte) error {
return nil
}

// AbstractAddition abstracts the addition of artifact
func (m *IndexProcessor) AbstractAddition(ctx context.Context, artifact *artifact.Artifact, addition string) (*processor.Addition, error) {
func (m *IndexProcessor) AbstractAddition(_ context.Context, _ *artifact.Artifact, addition string) (*processor.Addition, error) {
return nil, errors.New(nil).WithCode(errors.BadRequestCode).
WithMessage("addition %s isn't supported", addition)
}

// GetArtifactType returns the artifact type
func (m *IndexProcessor) GetArtifactType(ctx context.Context, artifact *artifact.Artifact) string {
func (m *IndexProcessor) GetArtifactType(_ context.Context, _ *artifact.Artifact) string {
return ""
}

// ListAdditionTypes returns the supported addition types
func (m *IndexProcessor) ListAdditionTypes(ctx context.Context, artifact *artifact.Artifact) []string {
func (m *IndexProcessor) ListAdditionTypes(_ context.Context, _ *artifact.Artifact) []string {
return nil
}
8 changes: 4 additions & 4 deletions src/controller/artifact/processor/base/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,23 @@ func (m *ManifestProcessor) AbstractMetadata(ctx context.Context, artifact *arti
}

// AbstractAddition abstracts the addition of artifact
func (m *ManifestProcessor) AbstractAddition(ctx context.Context, artifact *artifact.Artifact, addition string) (*processor.Addition, error) {
func (m *ManifestProcessor) AbstractAddition(_ context.Context, _ *artifact.Artifact, addition string) (*processor.Addition, error) {
return nil, errors.New(nil).WithCode(errors.BadRequestCode).
WithMessage("addition %s isn't supported", addition)
}

// GetArtifactType returns the artifact type
func (m *ManifestProcessor) GetArtifactType(ctx context.Context, artifact *artifact.Artifact) string {
func (m *ManifestProcessor) GetArtifactType(_ context.Context, _ *artifact.Artifact) string {
return ""
}

// ListAdditionTypes returns the supported addition types
func (m *ManifestProcessor) ListAdditionTypes(ctx context.Context, artifact *artifact.Artifact) []string {
func (m *ManifestProcessor) ListAdditionTypes(_ context.Context, _ *artifact.Artifact) []string {
return nil
}

// UnmarshalConfig unmarshal the config blob of the artifact into the specified object "v"
func (m *ManifestProcessor) UnmarshalConfig(ctx context.Context, repository string, manifest []byte, v interface{}) error {
func (m *ManifestProcessor) UnmarshalConfig(_ context.Context, repository string, manifest []byte, v interface{}) error {
// unmarshal manifest
mani := &v1.Manifest{}
if err := json.Unmarshal(manifest, mani); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions src/controller/artifact/processor/chart/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type processor struct {
chartOperator chart.Operator
}

func (p *processor) AbstractAddition(ctx context.Context, artifact *artifact.Artifact, addition string) (*ps.Addition, error) {
func (p *processor) AbstractAddition(_ context.Context, artifact *artifact.Artifact, addition string) (*ps.Addition, error) {
if addition != AdditionTypeValues && addition != AdditionTypeReadme && addition != AdditionTypeDependencies {
return nil, errors.New(nil).WithCode(errors.BadRequestCode).
WithMessage("addition %s isn't supported for %s", addition, ArtifactTypeChart)
Expand Down Expand Up @@ -122,10 +122,10 @@ func (p *processor) AbstractAddition(ctx context.Context, artifact *artifact.Art
return nil, nil
}

func (p *processor) GetArtifactType(ctx context.Context, artifact *artifact.Artifact) string {
func (p *processor) GetArtifactType(_ context.Context, _ *artifact.Artifact) string {
return ArtifactTypeChart
}

func (p *processor) ListAdditionTypes(ctx context.Context, artifact *artifact.Artifact) []string {
func (p *processor) ListAdditionTypes(_ context.Context, _ *artifact.Artifact) []string {
return []string{AdditionTypeValues, AdditionTypeReadme, AdditionTypeDependencies}
}
4 changes: 2 additions & 2 deletions src/controller/artifact/processor/cnab/cnab.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type processor struct {
manifestProcessor *base.ManifestProcessor
}

func (p *processor) AbstractMetadata(ctx context.Context, art *artifact.Artifact, manifest []byte) error {
func (p *processor) AbstractMetadata(ctx context.Context, art *artifact.Artifact, _ []byte) error {
cfgManiDgt := ""
// try to get the digest of the manifest that the config layer is referenced by
for _, reference := range art.References {
Expand All @@ -72,6 +72,6 @@ func (p *processor) AbstractMetadata(ctx context.Context, art *artifact.Artifact
return p.manifestProcessor.AbstractMetadata(ctx, art, payload)
}

func (p *processor) GetArtifactType(ctx context.Context, artifact *artifact.Artifact) string {
func (p *processor) GetArtifactType(_ context.Context, _ *artifact.Artifact) string {
return ArtifactTypeCNAB
}
6 changes: 3 additions & 3 deletions src/controller/artifact/processor/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type defaultProcessor struct {
regCli registry.Client
}

func (d *defaultProcessor) GetArtifactType(ctx context.Context, artifact *artifact.Artifact) string {
func (d *defaultProcessor) GetArtifactType(_ context.Context, artifact *artifact.Artifact) string {
// try to parse the type from the media type
strs := artifactTypeRegExp.FindStringSubmatch(artifact.MediaType)
if len(strs) == 2 {
Expand All @@ -57,7 +57,7 @@ func (d *defaultProcessor) GetArtifactType(ctx context.Context, artifact *artifa
// can not get the artifact type from the media type, return unknown
return ArtifactTypeUnknown
}
func (d *defaultProcessor) ListAdditionTypes(ctx context.Context, artifact *artifact.Artifact) []string {
func (d *defaultProcessor) ListAdditionTypes(_ context.Context, _ *artifact.Artifact) []string {
return nil
}

Expand Down Expand Up @@ -126,7 +126,7 @@ func (d *defaultProcessor) AbstractMetadata(ctx context.Context, artifact *artif
return nil
}

func (d *defaultProcessor) AbstractAddition(ctx context.Context, artifact *artifact.Artifact, addition string) (*Addition, error) {
func (d *defaultProcessor) AbstractAddition(_ context.Context, artifact *artifact.Artifact, _ string) (*Addition, error) {
// Addition not support for user-defined artifact yet.
// It will be support in the future.
// return error directly
Expand Down
2 changes: 1 addition & 1 deletion src/controller/artifact/processor/image/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ type indexProcessor struct {
*base.IndexProcessor
}

func (i *indexProcessor) GetArtifactType(ctx context.Context, artifact *artifact.Artifact) string {
func (i *indexProcessor) GetArtifactType(_ context.Context, _ *artifact.Artifact) string {
return ArtifactTypeImage
}
8 changes: 4 additions & 4 deletions src/controller/artifact/processor/image/manifest_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func init() {
type manifestV1Processor struct {
}

func (m *manifestV1Processor) AbstractMetadata(ctx context.Context, artifact *artifact.Artifact, manifest []byte) error {
func (m *manifestV1Processor) AbstractMetadata(_ context.Context, artifact *artifact.Artifact, manifest []byte) error {
mani := &schema1.Manifest{}
if err := json.Unmarshal(manifest, mani); err != nil {
return err
Expand All @@ -50,15 +50,15 @@ func (m *manifestV1Processor) AbstractMetadata(ctx context.Context, artifact *ar
return nil
}

func (m *manifestV1Processor) AbstractAddition(ctx context.Context, artifact *artifact.Artifact, addition string) (*processor.Addition, error) {
func (m *manifestV1Processor) AbstractAddition(_ context.Context, _ *artifact.Artifact, addition string) (*processor.Addition, error) {
return nil, errors.New(nil).WithCode(errors.BadRequestCode).
WithMessage("addition %s isn't supported for %s(manifest version 1)", addition, ArtifactTypeImage)
}

func (m *manifestV1Processor) GetArtifactType(ctx context.Context, artifact *artifact.Artifact) string {
func (m *manifestV1Processor) GetArtifactType(_ context.Context, _ *artifact.Artifact) string {
return ArtifactTypeImage
}

func (m *manifestV1Processor) ListAdditionTypes(ctx context.Context, artifact *artifact.Artifact) []string {
func (m *manifestV1Processor) ListAdditionTypes(_ context.Context, _ *artifact.Artifact) []string {
return nil
}
4 changes: 2 additions & 2 deletions src/controller/artifact/processor/image/manifest_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ func (m *manifestV2Processor) AbstractAddition(ctx context.Context, artifact *ar
}, nil
}

func (m *manifestV2Processor) GetArtifactType(ctx context.Context, artifact *artifact.Artifact) string {
func (m *manifestV2Processor) GetArtifactType(_ context.Context, _ *artifact.Artifact) string {
return ArtifactTypeImage
}

func (m *manifestV2Processor) ListAdditionTypes(ctx context.Context, artifact *artifact.Artifact) []string {
func (m *manifestV2Processor) ListAdditionTypes(_ context.Context, _ *artifact.Artifact) []string {
return []string{AdditionTypeBuildHistory}
}
4 changes: 2 additions & 2 deletions src/controller/artifact/processor/wasm/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ func (m *Processor) AbstractAddition(ctx context.Context, artifact *artifact.Art
}, nil
}

func (m *Processor) GetArtifactType(ctx context.Context, artifact *artifact.Artifact) string {
func (m *Processor) GetArtifactType(_ context.Context, _ *artifact.Artifact) string {
return ArtifactTypeWASM
}

func (m *Processor) ListAdditionTypes(ctx context.Context, artifact *artifact.Artifact) []string {
func (m *Processor) ListAdditionTypes(_ context.Context, _ *artifact.Artifact) []string {
return []string{AdditionTypeBuildHistory}
}
2 changes: 1 addition & 1 deletion src/controller/config/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func verifySkipAuditLogCfg(ctx context.Context, cfgs map[string]interface{}, mgr
}

// verifyValueLengthCfg verifies the cfgs which need to check the value max length to align with frontend.
func verifyValueLengthCfg(ctx context.Context, cfgs map[string]interface{}) error {
func verifyValueLengthCfg(_ context.Context, cfgs map[string]interface{}) error {
maxValue := maxValueLimitedByLength(common.UIMaxLengthLimitedOfNumber)
validateCfgs := []string{
common.TokenExpiration,
Expand Down
4 changes: 2 additions & 2 deletions src/controller/event/handler/internal/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (a *Handler) onPull(ctx context.Context, event *event.ArtifactEvent) error
return nil
}

func (a *Handler) updatePullTimeInCache(ctx context.Context, event *event.ArtifactEvent) {
func (a *Handler) updatePullTimeInCache(_ context.Context, event *event.ArtifactEvent) {
var tagName string
if len(event.Tags) != 0 {
tagName = event.Tags[0]
Expand All @@ -173,7 +173,7 @@ func (a *Handler) updatePullTimeInCache(ctx context.Context, event *event.Artifa
a.pullTimeStore[key] = time.Now()
}

func (a *Handler) addPullCountInCache(ctx context.Context, event *event.ArtifactEvent) {
func (a *Handler) addPullCountInCache(_ context.Context, event *event.ArtifactEvent) {
a.pullCountLock.Lock()
defer a.pullCountLock.Unlock()

Expand Down
2 changes: 1 addition & 1 deletion src/controller/gc/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func gcCallback(ctx context.Context, p string) error {
return err
}

func gcTaskStatusChange(ctx context.Context, taskID int64, status string) error {
func gcTaskStatusChange(ctx context.Context, _ int64, status string) error {
if status == job.SuccessStatus.String() && config.QuotaPerProjectEnable(ctx) {
go func() {
err := quota.RefreshForProjects(orm.Context())
Expand Down
2 changes: 1 addition & 1 deletion src/controller/health/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type Controller interface {

type controller struct{}

func (c *controller) GetHealth(ctx context.Context) *OverallHealthStatus {
func (c *controller) GetHealth(_ context.Context) *OverallHealthStatus {
var isHealthy healthy = true
components := []*ComponentHealthStatus{}
ch := make(chan *ComponentHealthStatus, len(registry))
Expand Down
2 changes: 1 addition & 1 deletion src/controller/p2p/preheat/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ func (c *controller) ListPoliciesByProject(ctx context.Context, project int64, q
}

// CheckHealth checks the instance health, for test connection
func (c *controller) CheckHealth(ctx context.Context, instance *providerModels.Instance) error {
func (c *controller) CheckHealth(_ context.Context, instance *providerModels.Instance) error {
if instance == nil {
return errors.New("instance can not be nil")
}
Expand Down
3 changes: 1 addition & 2 deletions src/controller/project/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,8 @@ func (c *controller) Exists(ctx context.Context, projectIDOrName interface{}) (b
return true, nil
} else if errors.IsNotFoundErr(err) {
return false, nil
} else {
return false, err
}
return false, err
}

func (c *controller) Get(ctx context.Context, projectIDOrName interface{}, options ...Option) (*models.Project, error) {
Expand Down
19 changes: 11 additions & 8 deletions src/controller/proxy/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,18 @@ func (c *controller) EnsureTag(ctx context.Context, art lib.ArtifactInfo, tagNam
// search the digest in cache and query with trimmed digest
var trimmedDigest string
err := c.cache.Fetch(ctx, TrimmedManifestlist+art.Digest, &trimmedDigest)
if errors.Is(err, cache.ErrNotFound) {
// skip to update digest, continue
} else if err != nil {
// for other error, return
return err
} else {
// found in redis, update the digest
if err == nil {
// it's found in redis, update the digest
art.Digest = trimmedDigest
log.Debugf("Found trimmed digest: %v", trimmedDigest)
} else {
// err != nil
if !errors.Is(err, cache.ErrNotFound) {
// for non-NotFound error return the error
return err
}
// else:
// err is a NotFound error, skip to update digest, continue
}
a, err := c.local.GetManifest(ctx, art)
if err != nil {
Expand Down Expand Up @@ -263,7 +266,7 @@ func (c *controller) ProxyManifest(ctx context.Context, art lib.ArtifactInfo, re
return man, nil
}

func (c *controller) HeadManifest(ctx context.Context, art lib.ArtifactInfo, remote RemoteInterface) (bool, *distribution.Descriptor, error) {
func (c *controller) HeadManifest(_ context.Context, art lib.ArtifactInfo, remote RemoteInterface) (bool, *distribution.Descriptor, error) {
remoteRepo := getRemoteRepo(art)
ref := getReference(art)
return remote.ManifestExist(remoteRepo, ref)
Expand Down
2 changes: 1 addition & 1 deletion src/controller/proxy/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func newLocalHelper() localInterface {
return l
}

func (l *localHelper) BlobExist(ctx context.Context, art lib.ArtifactInfo) (bool, error) {
func (l *localHelper) BlobExist(_ context.Context, art lib.ArtifactInfo) (bool, error) {
return l.registry.BlobExist(art.Repository, art.Digest)
}

Expand Down
4 changes: 2 additions & 2 deletions src/controller/proxy/manifestcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type ManifestListCache struct {
}

// CacheContent ...
func (m *ManifestListCache) CacheContent(ctx context.Context, remoteRepo string, man distribution.Manifest, art lib.ArtifactInfo, r RemoteInterface, contentType string) {
func (m *ManifestListCache) CacheContent(ctx context.Context, _ string, man distribution.Manifest, art lib.ArtifactInfo, _ RemoteInterface, contentType string) {
_, payload, err := man.Payload()
if err != nil {
log.Errorf("failed to get payload, error %v", err)
Expand Down Expand Up @@ -174,7 +174,7 @@ type ManifestCache struct {
}

// CacheContent ...
func (m *ManifestCache) CacheContent(ctx context.Context, remoteRepo string, man distribution.Manifest, art lib.ArtifactInfo, r RemoteInterface, contentType string) {
func (m *ManifestCache) CacheContent(ctx context.Context, remoteRepo string, man distribution.Manifest, art lib.ArtifactInfo, r RemoteInterface, _ string) {
var waitBlobs []distribution.Descriptor
for n := 0; n < maxManifestWait; n++ {
time.Sleep(sleepIntervalSec * time.Second)
Expand Down

0 comments on commit f65d238

Please sign in to comment.