daemon/containerd/image_builder.go
File image_builder.go
has 510 lines of code (exceeds 500 allowed). Consider refactoring. Open
Open
package containerd
import (
"bytes"
"context"
Method ImageService.GetImageAndReleasableLayer
has a Cognitive Complexity of 27 (exceeds 20 allowed). Consider refactoring. Open
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`)
}
- 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 ImageService.GetImageAndReleasableLayer
has 13 return statements (exceeds 4 allowed). Open
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`)
}
Function writeContentsForImage
has 54 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func writeContentsForImage(ctx context.Context, snName string, cs content.Store,
newConfig imagespec.DockerOCIImage, layers []ocispec.Descriptor,
containerConfig container.Config,
) (
manifestDesc ocispec.Descriptor,
Method ImageService.GetImageAndReleasableLayer
has 53 lines of code (exceeds 50 allowed). Consider refactoring. Open
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`)
}
Method ImageService.CreateImage
has 8 return statements (exceeds 4 allowed). Open
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
}
Method rwlayer.Commit
has 8 return statements (exceeds 4 allowed). Open
Open
func (rw *rwlayer) Commit() (_ builder.ROLayer, outErr error) {
snapshotter := rw.c.SnapshotService(rw.snapshotter)
key := stringid.GenerateRandomID()
Method ImageService.pullForBuilder
has 7 return statements (exceeds 4 allowed). Open
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
}
Function writeContentsForImage
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
func writeContentsForImage(ctx context.Context, snName string, cs content.Store,
newConfig imagespec.DockerOCIImage, layers []ocispec.Descriptor,
containerConfig container.Config,
Function writeContentsForImage
has 6 return statements (exceeds 4 allowed). Open
Open
func writeContentsForImage(ctx context.Context, snName string, cs content.Store,
newConfig imagespec.DockerOCIImage, layers []ocispec.Descriptor,
containerConfig container.Config,
) (
manifestDesc ocispec.Descriptor,
Method ImageService.createImageOCI
has 6 return statements (exceeds 4 allowed). Open
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
Method ImageService.pullForBuilder
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
func (i *ImageService) pullForBuilder(ctx context.Context, name string, authConfigs map[string]registry.AuthConfig, output io.Writer, platform *ocispec.Platform) (*ocispec.Descriptor, error) {
Method ImageService.createImageOCI
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
func (i *ImageService) createImageOCI(ctx context.Context, imgToCreate imagespec.DockerOCIImage,
parentDigest digest.Digest, layers []ocispec.Descriptor,
containerConfig container.Config,
Function newROLayerForImage
has 5 return statements (exceeds 4 allowed). Open
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 :'(")
}
Method rolayer.NewRWLayer
has 5 return statements (exceeds 4 allowed). Open
Open
func (rl *rolayer) NewRWLayer() (_ builder.RWLayer, outErr error) {
snapshotter := rl.c.SnapshotService(rl.snapshotter)
key := stringid.GenerateRandomID()