pkg/storage/manager/storage_manager.go

Summary

Maintainability
F
5 days
Test Coverage
F
38%

File storage_manager.go has 851 lines of code (exceeds 500 allowed). Consider refactoring.
Open

package manager

import (
    "context"
    "errors"
Severity: Major
Found in pkg/storage/manager/storage_manager.go - About 1 day to fix

    Method StorageManager.FetchStage has a Cognitive Complexity of 55 (exceeds 20 allowed). Consider refactoring.
    Open

    func (m *StorageManager) FetchStage(ctx context.Context, containerBackend container_backend.ContainerBackend, stg stage.Interface) error {
        logboek.Context(ctx).Debug().LogF("-- StagesManager.FetchStage %s\n", stg.LogDetailedName())
    
        if err := m.LockStageImage(ctx, stg.GetStageImage().Image.Name()); err != nil {
            return fmt.Errorf("error locking stage image %q: %w", stg.GetStageImage().Image.Name(), err)
    Severity: Minor
    Found in pkg/storage/manager/storage_manager.go - About 6 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    StorageManager has 40 methods (exceeds 20 allowed). Consider refactoring.
    Open

    type StorageManager struct {
        parallel           bool
        parallelTasksLimit int
    
        ProjectName string
    Severity: Minor
    Found in pkg/storage/manager/storage_manager.go - About 5 hrs to fix

      Method StorageManager.FetchStage has 129 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (m *StorageManager) FetchStage(ctx context.Context, containerBackend container_backend.ContainerBackend, stg stage.Interface) error {
          logboek.Context(ctx).Debug().LogF("-- StagesManager.FetchStage %s\n", stg.LogDetailedName())
      
          if err := m.LockStageImage(ctx, stg.GetStageImage().Image.Name()); err != nil {
              return fmt.Errorf("error locking stage image %q: %w", stg.GetStageImage().Image.Name(), err)
      Severity: Major
      Found in pkg/storage/manager/storage_manager.go - About 4 hrs to fix

        Function getStageDescription has a Cognitive Complexity of 31 (exceeds 20 allowed). Consider refactoring.
        Open

        func getStageDescription(ctx context.Context, projectName string, stageID image.StageID, stagesStorage storage.StagesStorage, cacheStagesStorageList []storage.StagesStorage, opts getStageDescriptionOptions) (*image.StageDescription, error) {
            if opts.WithLocalManifestCache {
                stageDesc, err := getStageDescriptionFromLocalManifestCache(ctx, projectName, stageID, stagesStorage)
                if err != nil {
                    return nil, fmt.Errorf("error getting stage %s description from %s: %w", stageID.String(), stagesStorage.String(), err)
        Severity: Minor
        Found in pkg/storage/manager/storage_manager.go - About 2 hrs to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Method StorageManager.FetchStage has 23 return statements (exceeds 4 allowed).
        Open

        func (m *StorageManager) FetchStage(ctx context.Context, containerBackend container_backend.ContainerBackend, stg stage.Interface) error {
            logboek.Context(ctx).Debug().LogF("-- StagesManager.FetchStage %s\n", stg.LogDetailedName())
        
            if err := m.LockStageImage(ctx, stg.GetStageImage().Image.Name()); err != nil {
                return fmt.Errorf("error locking stage image %q: %w", stg.GetStageImage().Image.Name(), err)
        Severity: Major
        Found in pkg/storage/manager/storage_manager.go - About 2 hrs to fix

          Function getStageDescription has 57 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func getStageDescription(ctx context.Context, projectName string, stageID image.StageID, stagesStorage storage.StagesStorage, cacheStagesStorageList []storage.StagesStorage, opts getStageDescriptionOptions) (*image.StageDescription, error) {
              if opts.WithLocalManifestCache {
                  stageDesc, err := getStageDescriptionFromLocalManifestCache(ctx, projectName, stageID, stagesStorage)
                  if err != nil {
                      return nil, fmt.Errorf("error getting stage %s description from %s: %w", stageID.String(), stagesStorage.String(), err)
          Severity: Minor
          Found in pkg/storage/manager/storage_manager.go - About 1 hr to fix

            Function getStageDescription has 9 return statements (exceeds 4 allowed).
            Open

            func getStageDescription(ctx context.Context, projectName string, stageID image.StageID, stagesStorage storage.StagesStorage, cacheStagesStorageList []storage.StagesStorage, opts getStageDescriptionOptions) (*image.StageDescription, error) {
                if opts.WithLocalManifestCache {
                    stageDesc, err := getStageDescriptionFromLocalManifestCache(ctx, projectName, stageID, stagesStorage)
                    if err != nil {
                        return nil, fmt.Errorf("error getting stage %s description from %s: %w", stageID.String(), stagesStorage.String(), err)
            Severity: Major
            Found in pkg/storage/manager/storage_manager.go - About 55 mins to fix

              Method StorageManager.CopyStageIntoFinalStorage has 8 return statements (exceeds 4 allowed).
              Open

              func (m *StorageManager) CopyStageIntoFinalStorage(ctx context.Context, stageID image.StageID, finalStagesStorage storage.StagesStorage, opts CopyStageIntoStorageOptions) (*image.StageDescription, error) {
                  existingStagesListCache, err := m.getOrCreateFinalStagesListCache(ctx)
                  if err != nil {
                      return nil, fmt.Errorf("error getting existing stages list of final repo %s: %w", finalStagesStorage.String(), err)
                  }
              Severity: Major
              Found in pkg/storage/manager/storage_manager.go - About 50 mins to fix

                Function getStageDescription has 6 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                func getStageDescription(ctx context.Context, projectName string, stageID image.StageID, stagesStorage storage.StagesStorage, cacheStagesStorageList []storage.StagesStorage, opts getStageDescriptionOptions) (*image.StageDescription, error) {
                Severity: Minor
                Found in pkg/storage/manager/storage_manager.go - About 45 mins to fix

                  Method StorageManager.getStageDescriptionList has 6 return statements (exceeds 4 allowed).
                  Open

                  func (m *StorageManager) getStageDescriptionList(ctx context.Context, opts ...storage.Option) ([]*image.StageDescription, error) {
                      stageIDs, err := m.StagesStorage.GetStagesIDs(ctx, m.ProjectName, opts...)
                      if err != nil {
                          return nil, fmt.Errorf("error getting stages ids from %s: %w", m.StagesStorage, err)
                      }
                  Severity: Major
                  Found in pkg/storage/manager/storage_manager.go - About 40 mins to fix

                    Method StorageManager.GetFinalStageDescriptionList has 6 return statements (exceeds 4 allowed).
                    Open

                    func (m *StorageManager) GetFinalStageDescriptionList(ctx context.Context) ([]*image.StageDescription, error) {
                        existingStagesListCache, err := m.getOrCreateFinalStagesListCache(ctx)
                        if err != nil {
                            return nil, fmt.Errorf("error getting existing stages list of final repo %s: %w", m.FinalStagesStorage.String(), err)
                        }
                    Severity: Major
                    Found in pkg/storage/manager/storage_manager.go - About 40 mins to fix

                      Function NewStorageManager has 5 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                      func NewStorageManager(projectName string, stagesStorage storage.PrimaryStagesStorage, finalStagesStorage storage.StagesStorage, secondaryStagesStorageList, cacheStagesStorageList []storage.StagesStorage, storageLockManager storage.LockManager) *StorageManager {
                      Severity: Minor
                      Found in pkg/storage/manager/storage_manager.go - About 35 mins to fix

                        Function doFetchStage has 5 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                        func doFetchStage(ctx context.Context, projectName string, stagesStorage storage.StagesStorage, stageID image.StageID, img container_backend.LegacyImageInterface) error {
                        Severity: Minor
                        Found in pkg/storage/manager/storage_manager.go - About 35 mins to fix

                          Method StorageManager.CopySuitableByDigestStage has 5 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                          func (m *StorageManager) CopySuitableByDigestStage(ctx context.Context, stageDesc *image.StageDescription, sourceStagesStorage, destinationStagesStorage storage.StagesStorage, containerBackend container_backend.ContainerBackend, targetPlatform string) (*image.StageDescription, error) {
                          Severity: Minor
                          Found in pkg/storage/manager/storage_manager.go - About 35 mins to fix

                            Method StorageManager.SelectSuitableStage has 5 return statements (exceeds 4 allowed).
                            Open

                            func (m *StorageManager) SelectSuitableStage(ctx context.Context, c stage.Conveyor, stg stage.Interface, stages []*image.StageDescription) (*image.StageDescription, error) {
                                if len(stages) == 0 {
                                    return nil, nil
                                }
                            
                            
                            Severity: Major
                            Found in pkg/storage/manager/storage_manager.go - About 35 mins to fix

                              Function doFetchStage has 5 return statements (exceeds 4 allowed).
                              Open

                              func doFetchStage(ctx context.Context, projectName string, stagesStorage storage.StagesStorage, stageID image.StageID, img container_backend.LegacyImageInterface) error {
                                  err := logboek.Context(ctx).Info().LogProcess("Check manifest availability").DoError(func() error {
                                      freshStageDescription, err := stagesStorage.GetStageDescription(ctx, projectName, stageID)
                                      if err != nil {
                                          return fmt.Errorf("unable to get stage description: %w", err)
                              Severity: Major
                              Found in pkg/storage/manager/storage_manager.go - About 35 mins to fix

                                Method StorageManager.CopySuitableByDigestStage has 5 return statements (exceeds 4 allowed).
                                Open

                                func (m *StorageManager) CopySuitableByDigestStage(ctx context.Context, stageDesc *image.StageDescription, sourceStagesStorage, destinationStagesStorage storage.StagesStorage, containerBackend container_backend.ContainerBackend, targetPlatform string) (*image.StageDescription, error) {
                                    img := container_backend.NewLegacyStageImage(nil, stageDesc.Info.Name, containerBackend, targetPlatform)
                                
                                    logboek.Context(ctx).Info().LogF("Fetching %s\n", img.Name())
                                    if err := sourceStagesStorage.FetchImage(ctx, img); err != nil {
                                Severity: Major
                                Found in pkg/storage/manager/storage_manager.go - About 35 mins to fix

                                  Similar blocks of code found in 2 locations. Consider refactoring.
                                  Open

                                  func (m *StorageManager) ForEachRmImportMetadata(ctx context.Context, projectName string, ids []string, f func(ctx context.Context, id string, err error) error) error {
                                      return parallel.DoTasks(ctx, len(ids), parallel.DoTasksOptions{
                                          MaxNumberOfWorkers: m.MaxNumberOfWorkers(),
                                      }, func(ctx context.Context, taskId int) error {
                                          id := ids[taskId]
                                  Severity: Major
                                  Found in pkg/storage/manager/storage_manager.go and 1 other location - About 1 hr to fix
                                  pkg/storage/manager/storage_manager.go on lines 1015..1023

                                  Duplicated Code

                                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                  Tuning

                                  This issue has a mass of 182.

                                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                  Refactorings

                                  Further Reading

                                  Similar blocks of code found in 2 locations. Consider refactoring.
                                  Open

                                  func (m *StorageManager) ForEachRmManagedImage(ctx context.Context, projectName string, managedImages []string, f func(ctx context.Context, managedImage string, err error) error) error {
                                      return parallel.DoTasks(ctx, len(managedImages), parallel.DoTasksOptions{
                                          MaxNumberOfWorkers: m.MaxNumberOfWorkers(),
                                      }, func(ctx context.Context, taskId int) error {
                                          managedImage := managedImages[taskId]
                                  Severity: Major
                                  Found in pkg/storage/manager/storage_manager.go and 1 other location - About 1 hr to fix
                                  pkg/storage/manager/storage_manager.go on lines 1035..1043

                                  Duplicated Code

                                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                  Tuning

                                  This issue has a mass of 182.

                                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                  Refactorings

                                  Further Reading

                                  There are no issues that match your filters.

                                  Category
                                  Status