File storage_manager.go
has 851 lines of code (exceeds 500 allowed). Consider refactoring. Open
package manager
import (
"context"
"errors"
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)
- Read upRead up
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
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)
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)
- Read upRead up
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)
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)
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)
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)
}
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) {
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)
}
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)
}
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 {
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 {
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) {
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
}
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)
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 {
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]
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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]
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76