pkg/host_cleaning/local_docker_server.go

Summary

Maintainability
D
2 days
Test Coverage
F
5%

Function RunGCForLocalDockerServer has 168 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func RunGCForLocalDockerServer(ctx context.Context, allowedVolumeUsagePercentage, allowedVolumeUsageMarginPercentage float64, dockerServerStoragePath string, force, dryRun bool) error {
    if dockerServerStoragePath == "" {
        return nil
    }

Severity: Major
Found in pkg/host_cleaning/local_docker_server.go - About 5 hrs to fix

    Function GetLocalDockerServerStorageCheck has a Cognitive Complexity of 40 (exceeds 20 allowed). Consider refactoring.
    Open

    func GetLocalDockerServerStorageCheck(ctx context.Context, dockerServerStoragePath string) (*LocalDockerServerStorageCheckResult, error) {
        res := &LocalDockerServerStorageCheckResult{}
    
        vu, err := volumeutils.GetVolumeUsageByPath(ctx, dockerServerStoragePath)
        if err != nil {
    Severity: Minor
    Found in pkg/host_cleaning/local_docker_server.go - About 3 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

    Function GetLocalDockerServerStorageCheck has 101 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func GetLocalDockerServerStorageCheck(ctx context.Context, dockerServerStoragePath string) (*LocalDockerServerStorageCheckResult, error) {
        res := &LocalDockerServerStorageCheckResult{}
    
        vu, err := volumeutils.GetVolumeUsageByPath(ctx, dockerServerStoragePath)
        if err != nil {
    Severity: Major
    Found in pkg/host_cleaning/local_docker_server.go - About 3 hrs to fix

      Function RunGCForLocalDockerServer has a Cognitive Complexity of 29 (exceeds 20 allowed). Consider refactoring.
      Open

      func RunGCForLocalDockerServer(ctx context.Context, allowedVolumeUsagePercentage, allowedVolumeUsageMarginPercentage float64, dockerServerStoragePath string, force, dryRun bool) error {
          if dockerServerStoragePath == "" {
              return nil
          }
      
      
      Severity: Minor
      Found in pkg/host_cleaning/local_docker_server.go - About 1 hr 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

      Function RunGCForLocalDockerServer has 14 return statements (exceeds 4 allowed).
      Open

      func RunGCForLocalDockerServer(ctx context.Context, allowedVolumeUsagePercentage, allowedVolumeUsageMarginPercentage float64, dockerServerStoragePath string, force, dryRun bool) error {
          if dockerServerStoragePath == "" {
              return nil
          }
      
      
      Severity: Major
      Found in pkg/host_cleaning/local_docker_server.go - About 1 hr to fix

        Avoid deeply nested control flow statements.
        Open

                                if allTagsRemoved {
                                    imageRemoved = true
                                }
        Severity: Major
        Found in pkg/host_cleaning/local_docker_server.go - About 45 mins to fix

          Function safeContainersCleanup has 7 return statements (exceeds 4 allowed).
          Open

          func safeContainersCleanup(ctx context.Context, processedDockerContainersIDs []string, options CommonOptions) ([]string, error) {
              containers, err := werfContainersByFilterSet(ctx, filters.NewArgs())
              if err != nil {
                  return nil, fmt.Errorf("cannot get stages build containers: %w", err)
              }
          Severity: Major
          Found in pkg/host_cleaning/local_docker_server.go - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                } else if len(desc.ImageSummary.RepoDigests) > 0 {
                                    allDigestsRemoved := true
            
                                    for _, repoDigest := range desc.ImageSummary.RepoDigests {
                                        if err := removeImage(ctx, repoDigest, force, dryRun); err != nil {
            Severity: Major
            Found in pkg/host_cleaning/local_docker_server.go - About 45 mins to fix

              Function GetLocalDockerServerStorageCheck has 7 return statements (exceeds 4 allowed).
              Open

              func GetLocalDockerServerStorageCheck(ctx context.Context, dockerServerStoragePath string) (*LocalDockerServerStorageCheckResult, error) {
                  res := &LocalDockerServerStorageCheckResult{}
              
                  vu, err := volumeutils.GetVolumeUsageByPath(ctx, dockerServerStoragePath)
                  if err != nil {
              Severity: Major
              Found in pkg/host_cleaning/local_docker_server.go - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                            if ref == "<none>:<none>" {
                                                if err := removeImage(ctx, desc.ImageSummary.ID, force, dryRun); err != nil {
                                                    logboek.Context(ctx).Warn().LogF("failed to remove local docker image by ID %q: %s\n", desc.ImageSummary.ID, err)
                                                    allTagsRemoved = false
                                                }
                Severity: Major
                Found in pkg/host_cleaning/local_docker_server.go - About 45 mins to fix

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

                              logboek.Context(ctx).Default().LogBlock("Local docker server storage check").Do(func() {
                                  logboek.Context(ctx).Default().LogF("Docker server storage path: %s\n", dockerServerStoragePath)
                                  logboek.Context(ctx).Default().LogF("Volume usage: %s / %s\n", humanize.Bytes(checkResult.VolumeUsage.UsedBytes), humanize.Bytes(checkResult.VolumeUsage.TotalBytes))
                                  logboek.Context(ctx).Default().LogF("Target volume usage percentage: %s <= %s — %s\n", utils.GreenF("%0.2f%%", checkResult.VolumeUsage.Percentage), utils.BlueF("%0.2f%%", targetVolumeUsage), utils.GreenF("OK"))
                              })
                  Severity: Major
                  Found in pkg/host_cleaning/local_docker_server.go and 1 other location - About 1 hr to fix
                  pkg/host_cleaning/local_docker_server.go on lines 263..267

                  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 187.

                  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

                          logboek.Context(ctx).Default().LogBlock("Local docker server storage check").Do(func() {
                              logboek.Context(ctx).Default().LogF("Docker server storage path: %s\n", dockerServerStoragePath)
                              logboek.Context(ctx).Default().LogF("Volume usage: %s / %s\n", humanize.Bytes(checkResult.VolumeUsage.UsedBytes), humanize.Bytes(checkResult.VolumeUsage.TotalBytes))
                              logboek.Context(ctx).Default().LogF("Allowed volume usage percentage: %s <= %s — %s\n", utils.GreenF("%0.2f%%", checkResult.VolumeUsage.Percentage), utils.BlueF("%0.2f%%", allowedVolumeUsagePercentage), utils.GreenF("OK"))
                          })
                  Severity: Major
                  Found in pkg/host_cleaning/local_docker_server.go and 1 other location - About 1 hr to fix
                  pkg/host_cleaning/local_docker_server.go on lines 432..436

                  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 187.

                  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