dotcloud/docker

View on GitHub
daemon/containerd/image_builder.go

Summary

Maintainability
D
1 day
Test Coverage

File image_builder.go has 510 lines of code (exceeds 500 allowed). Consider refactoring.
Open

package containerd

import (
    "bytes"
    "context"
Severity: Minor
Found in daemon/containerd/image_builder.go - About 2 hrs to fix

    Method ImageService.GetImageAndReleasableLayer has a Cognitive Complexity of 27 (exceeds 20 allowed). Consider refactoring.
    Open

    func (i *ImageService) GetImageAndReleasableLayer(ctx context.Context, refOrID string, opts backend.GetImageAndLayerOptions) (builder.Image, builder.ROLayer, error) {
        if refOrID == "" { // FROM scratch
            if runtime.GOOS == "windows" {
                return nil, nil, fmt.Errorf(`"FROM scratch" is not supported on Windows`)
            }
    Severity: Minor
    Found in daemon/containerd/image_builder.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

    Method ImageService.GetImageAndReleasableLayer has 13 return statements (exceeds 4 allowed).
    Open

    func (i *ImageService) GetImageAndReleasableLayer(ctx context.Context, refOrID string, opts backend.GetImageAndLayerOptions) (builder.Image, builder.ROLayer, error) {
        if refOrID == "" { // FROM scratch
            if runtime.GOOS == "windows" {
                return nil, nil, fmt.Errorf(`"FROM scratch" is not supported on Windows`)
            }
    Severity: Major
    Found in daemon/containerd/image_builder.go - About 1 hr to fix

      Function writeContentsForImage has 54 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func writeContentsForImage(ctx context.Context, snName string, cs content.Store,
          newConfig imagespec.DockerOCIImage, layers []ocispec.Descriptor,
          containerConfig container.Config,
      ) (
          manifestDesc ocispec.Descriptor,
      Severity: Minor
      Found in daemon/containerd/image_builder.go - About 1 hr to fix

        Method ImageService.GetImageAndReleasableLayer has 53 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (i *ImageService) GetImageAndReleasableLayer(ctx context.Context, refOrID string, opts backend.GetImageAndLayerOptions) (builder.Image, builder.ROLayer, error) {
            if refOrID == "" { // FROM scratch
                if runtime.GOOS == "windows" {
                    return nil, nil, fmt.Errorf(`"FROM scratch" is not supported on Windows`)
                }
        Severity: Minor
        Found in daemon/containerd/image_builder.go - About 1 hr to fix

          Method rwlayer.Commit has 8 return statements (exceeds 4 allowed).
          Open

          func (rw *rwlayer) Commit() (_ builder.ROLayer, outErr error) {
              snapshotter := rw.c.SnapshotService(rw.snapshotter)
          
              key := stringid.GenerateRandomID()
          
          
          Severity: Major
          Found in daemon/containerd/image_builder.go - About 50 mins to fix

            Method ImageService.CreateImage has 8 return statements (exceeds 4 allowed).
            Open

            func (i *ImageService) CreateImage(ctx context.Context, config []byte, parent string, layerDigest digest.Digest) (builder.Image, error) {
                imgToCreate, err := dimage.NewFromJSON(config)
                if err != nil {
                    return nil, err
                }
            Severity: Major
            Found in daemon/containerd/image_builder.go - About 50 mins to fix

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

              func writeContentsForImage(ctx context.Context, snName string, cs content.Store,
                  newConfig imagespec.DockerOCIImage, layers []ocispec.Descriptor,
                  containerConfig container.Config,
              Severity: Minor
              Found in daemon/containerd/image_builder.go - About 45 mins to fix

                Method ImageService.pullForBuilder has 7 return statements (exceeds 4 allowed).
                Open

                func (i *ImageService) pullForBuilder(ctx context.Context, name string, authConfigs map[string]registry.AuthConfig, output io.Writer, platform *ocispec.Platform) (*ocispec.Descriptor, error) {
                    ref, err := reference.ParseNormalizedNamed(name)
                    if err != nil {
                        return nil, err
                    }
                Severity: Major
                Found in daemon/containerd/image_builder.go - About 45 mins to fix

                  Method ImageService.createImageOCI has 6 return statements (exceeds 4 allowed).
                  Open

                  func (i *ImageService) createImageOCI(ctx context.Context, imgToCreate imagespec.DockerOCIImage,
                      parentDigest digest.Digest, layers []ocispec.Descriptor,
                      containerConfig container.Config,
                  ) (dimage.ID, error) {
                      // Necessary to prevent the contents from being GC'd
                  Severity: Major
                  Found in daemon/containerd/image_builder.go - About 40 mins to fix

                    Function writeContentsForImage has 6 return statements (exceeds 4 allowed).
                    Open

                    func writeContentsForImage(ctx context.Context, snName string, cs content.Store,
                        newConfig imagespec.DockerOCIImage, layers []ocispec.Descriptor,
                        containerConfig container.Config,
                    ) (
                        manifestDesc ocispec.Descriptor,
                    Severity: Major
                    Found in daemon/containerd/image_builder.go - About 40 mins to fix

                      Method ImageService.createImageOCI has 5 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                      func (i *ImageService) createImageOCI(ctx context.Context, imgToCreate imagespec.DockerOCIImage,
                          parentDigest digest.Digest, layers []ocispec.Descriptor,
                          containerConfig container.Config,
                      Severity: Minor
                      Found in daemon/containerd/image_builder.go - About 35 mins to fix

                        Method ImageService.pullForBuilder has 5 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                        func (i *ImageService) pullForBuilder(ctx context.Context, name string, authConfigs map[string]registry.AuthConfig, output io.Writer, platform *ocispec.Platform) (*ocispec.Descriptor, error) {
                        Severity: Minor
                        Found in daemon/containerd/image_builder.go - About 35 mins to fix

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

                          func newROLayerForImage(ctx context.Context, imgDesc *ocispec.Descriptor, i *ImageService, platform *ocispec.Platform) (builder.ROLayer, error) {
                              if imgDesc == nil {
                                  return nil, fmt.Errorf("can't make an RO layer for a nil image :'(")
                              }
                          
                          
                          Severity: Major
                          Found in daemon/containerd/image_builder.go - About 35 mins to fix

                            Method rolayer.NewRWLayer has 5 return statements (exceeds 4 allowed).
                            Open

                            func (rl *rolayer) NewRWLayer() (_ builder.RWLayer, outErr error) {
                                snapshotter := rl.c.SnapshotService(rl.snapshotter)
                            
                                key := stringid.GenerateRandomID()
                            
                            
                            Severity: Major
                            Found in daemon/containerd/image_builder.go - About 35 mins to fix

                              There are no issues that match your filters.

                              Category
                              Status