Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated dependency #131

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package groot

import (
"fmt"
"os"

"github.com/pkg/errors"
yaml "gopkg.in/yaml.v2"
)

Expand All @@ -26,11 +26,11 @@ func parseConfig(configFilePath string) (conf config, err error) {

contents, err := os.ReadFile(configFilePath)
if err != nil {
return config{}, errors.Wrap(err, "reading config file")
return config{}, fmt.Errorf("reading config file: %w", err)
}

if err := yaml.Unmarshal(contents, &conf); err != nil {
return config{}, errors.Wrap(err, "parsing config file")
return config{}, fmt.Errorf("parsing config file: %w", err)
}

return conf, nil
Expand Down
5 changes: 2 additions & 3 deletions create.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"code.cloudfoundry.org/groot/imagepuller"
runspec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
)

func (g *Groot) Create(handle string, diskLimit int64, excludeImageFromQuota bool) (runspec.Spec, error) {
Expand All @@ -24,7 +23,7 @@ func (g *Groot) Create(handle string, diskLimit int64, excludeImageFromQuota boo

image, err := g.ImagePuller.Pull(g.Logger, imageSpec)
if err != nil {
return runspec.Spec{}, errors.Wrap(err, "pulling image")
return runspec.Spec{}, fmt.Errorf("pulling image: %w", err)
}

quota := diskLimit
Expand All @@ -38,7 +37,7 @@ func (g *Groot) Create(handle string, diskLimit int64, excludeImageFromQuota boo

bundle, err := g.Driver.Bundle(g.Logger.Session("bundle"), handle, image.ChainIDs, quota)
if err != nil {
return runspec.Spec{}, errors.Wrap(err, "creating bundle")
return runspec.Spec{}, fmt.Errorf("creating bundle: %w", err)
}

if len(image.Config.Config.Env) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package groot_test

import (
"bytes"
"errors"
"io"

"code.cloudfoundry.org/groot"
Expand All @@ -13,7 +14,6 @@ import (
. "github.com/onsi/gomega"
imgspec "github.com/opencontainers/image-spec/specs-go/v1"
specs "github.com/opencontainers/runtime-spec/specs-go"
errors "github.com/pkg/errors"
)

var _ = Describe("Create", func() {
Expand Down
3 changes: 2 additions & 1 deletion delete_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package groot_test

import (
"errors"

"code.cloudfoundry.org/groot"
"code.cloudfoundry.org/groot/grootfakes"
"code.cloudfoundry.org/lager/v3/lagertest"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
errors "github.com/pkg/errors"
)

var _ = Describe("Delete", func() {
Expand Down
10 changes: 5 additions & 5 deletions fetcher/filefetcher/file_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package filefetcher // import "code.cloudfoundry.org/groot/fetcher/filefetcher"
import (
"crypto/sha256"
"encoding/hex"
"errors"
"fmt"
"io"
"net/url"
"os"

"code.cloudfoundry.org/groot/imagepuller"
"code.cloudfoundry.org/lager/v3"
"github.com/pkg/errors"
)

type FileFetcher struct {
Expand All @@ -29,17 +29,17 @@ func (l *FileFetcher) StreamBlob(logger lager.Logger, layerInfo imagepuller.Laye
defer logger.Info("ending")

if _, err := os.Stat(l.imagePath); err != nil {
return nil, 0, errors.Wrapf(err, "local image not found in `%s`", l.imagePath)
return nil, 0, fmt.Errorf("local image not found in `%s`: %w", l.imagePath, err)
}

if err := l.validateImage(); err != nil {
return nil, 0, errors.Wrap(err, "invalid base image")
return nil, 0, fmt.Errorf("invalid base image: %w", err)
}

logger.Debug("opening-tar", lager.Data{"imagePath": l.imagePath})
stream, err := os.Open(l.imagePath)
if err != nil {
return nil, 0, errors.Wrap(err, "reading local image")
return nil, 0, fmt.Errorf("reading local image: %w", err)
}

return stream, 0, nil
Expand All @@ -54,7 +54,7 @@ func (l *FileFetcher) ImageInfo(logger lager.Logger) (imagepuller.ImageInfo, err
stat, err := os.Stat(l.imagePath)
if err != nil {
return imagepuller.ImageInfo{},
errors.Wrap(err, "fetching image timestamp")
fmt.Errorf("fetching image timestamp: %w", err)
}

return imagepuller.ImageInfo{
Expand Down
5 changes: 2 additions & 3 deletions fetcher/layerfetcher/blob_reader.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package layerfetcher // import "code.cloudfoundry.org/groot/fetcher/layerfetcher"

import (
"fmt"
"io"
"os"

errorspkg "github.com/pkg/errors"
)

type BlobReader struct {
Expand All @@ -15,7 +14,7 @@ type BlobReader struct {
func NewBlobReader(blobPath string) (*BlobReader, error) {
reader, err := os.Open(blobPath)
if err != nil {
return nil, errorspkg.Wrap(err, "failed to open blob")
return nil, fmt.Errorf("failed to open blob: %w", err)
}

return &BlobReader{
Expand Down
3 changes: 1 addition & 2 deletions fetcher/layerfetcher/layer_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/containers/image/v5/types"
imgspec "github.com/opencontainers/image-spec/specs-go/v1"
errorspkg "github.com/pkg/errors"
)

//go:generate counterfeiter . Source
Expand Down Expand Up @@ -79,7 +78,7 @@ func (f *LayerFetcher) StreamBlob(logger lager.Logger, layerInfo imagepuller.Lay
blobReader, err := NewBlobReader(blobFilePath)
if err != nil {
logger.Error("blob-reader-failed", err)
return nil, 0, errorspkg.Wrap(err, "opening stream from temporary blob file")
return nil, 0, fmt.Errorf("opening stream from temporary blob file: %w", err)
}

return blobReader, size, nil
Expand Down
30 changes: 15 additions & 15 deletions fetcher/layerfetcher/source/layer_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"crypto/sha256"
"encoding/hex"
"errors"
"fmt"
"hash"
"io"
Expand All @@ -25,7 +26,6 @@ import (
"github.com/containers/image/v5/transports"
"github.com/containers/image/v5/types"
digestpkg "github.com/opencontainers/go-digest"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -59,7 +59,7 @@ func (s *LayerSource) Manifest(logger lager.Logger) (types.Image, error) {
img, err := s.getImageWithRetries(logger)
if err != nil {
logger.Error("fetching-image-reference-failed", err)
return nil, errors.Wrap(err, "fetching image reference")
return nil, fmt.Errorf("fetching image reference: %w", err)
}

img, err = s.convertImage(logger, img)
Expand All @@ -79,7 +79,7 @@ func (s *LayerSource) Manifest(logger lager.Logger) (types.Image, error) {
err = e
}

return nil, errors.Wrap(err, "fetching image configuration")
return nil, fmt.Errorf("fetching image configuration: %w", err)
}

func (s *LayerSource) Blob(logger lager.Logger, layerInfo imagepuller.LayerInfo) (string, int64, error) {
Expand Down Expand Up @@ -136,7 +136,7 @@ func (s *LayerSource) Blob(logger lager.Logger, layerInfo imagepuller.LayerInfo)

digestReader, err = gzip.NewReader(digestReader)
if err != nil {
return "", 0, errors.Wrapf(err, "expected blob to be of type %s", layerInfo.MediaType)
return "", 0, fmt.Errorf("expected blob to be of type %s: %w", layerInfo.MediaType, err)
}
defer digestReader.Close()

Expand All @@ -152,16 +152,16 @@ func (s *LayerSource) Blob(logger lager.Logger, layerInfo imagepuller.LayerInfo)
uncompressedSize, err := io.Copy(blobTempFile, digestReader)
if err != nil {
logger.Error("writing-blob-to-file", err)
return "", 0, errors.Wrap(err, "writing blob to tempfile")
return "", 0, fmt.Errorf("writing blob to tempfile: %w", err)
}

blobIDHex := strings.Split(layerInfo.BlobID, ":")[1]
if err = s.checkCheckSum(logger, blobIDHash, blobIDHex, s.imageURL.Scheme); err != nil {
return "", 0, errors.Wrap(err, "layerID digest mismatch")
return "", 0, fmt.Errorf("layerID digest mismatch: %w", err)
}

if err = s.checkCheckSum(logger, diffIDHash, layerInfo.DiffID, s.imageURL.Scheme); err != nil {
return "", 0, errors.Wrap(err, "diffID digest mismatch")
return "", 0, fmt.Errorf("diffID digest mismatch: %w", err)
}

s.remainingImageQuota -= uncompressedSize
Expand Down Expand Up @@ -219,7 +219,7 @@ func (s *LayerSource) checkCheckSum(logger lager.Logger, hash hash.Hash, digest
"downloadedChecksum": blobContentsSha,
})
if digest != blobContentsSha {
return errors.Errorf("expected: %s, actual: %s", digest, blobContentsSha)
return fmt.Errorf("expected: %s, actual: %s", digest, blobContentsSha)
}

return nil
Expand All @@ -231,7 +231,7 @@ func (s *LayerSource) reference(logger lager.Logger) (types.ImageReference, erro
transport := transports.Get(s.imageURL.Scheme)
ref, err := transport.ParseReference(refString)
if err != nil {
return nil, errors.Wrap(err, "parsing url failed")
return nil, fmt.Errorf("parsing url failed: %w", err)
}

return ref, nil
Expand Down Expand Up @@ -268,7 +268,7 @@ func (s *LayerSource) getImageWithRetries(logger lager.Logger) (types.Image, err
imgErr = err
}

return nil, errors.Wrap(imgErr, "creating image")
return nil, fmt.Errorf("creating image: %w", imgErr)
}

func (s *LayerSource) getImageSource(logger lager.Logger) (types.ImageSource, error) {
Expand All @@ -291,7 +291,7 @@ func (s *LayerSource) createImageSource(logger lager.Logger) (types.ImageSource,

imgSrc, err := ref.NewImageSource(context.TODO(), &s.systemContext)
if err != nil {
return nil, errors.Wrap(err, "creating image source")
return nil, fmt.Errorf("creating image source: %w", err)
}

return imgSrc, nil
Expand Down Expand Up @@ -320,7 +320,7 @@ func (s *LayerSource) convertImage(logger lager.Logger, originalImage types.Imag
for _, layer := range originalImage.LayerInfos() {
diffID, err := s.v1DiffID(logger, layer, imgSrc)
if err != nil {
return nil, errors.Wrap(err, "converting V1 schema failed")
return nil, fmt.Errorf("converting V1 schema failed: %w", err)
}
diffIDs = append(diffIDs, diffID)
}
Expand All @@ -339,18 +339,18 @@ func (s *LayerSource) convertImage(logger lager.Logger, originalImage types.Imag
func (s *LayerSource) v1DiffID(logger lager.Logger, layer types.BlobInfo, imgSrc types.ImageSource) (digestpkg.Digest, error) {
blob, _, err := s.getBlobWithRetries(logger, imgSrc, layer)
if err != nil {
return "", errors.Wrap(err, "fetching V1 layer blob")
return "", fmt.Errorf("fetching V1 layer blob: %w", err)
}
defer blob.Close()

gzipReader, err := gzip.NewReader(blob)
if err != nil {
return "", errors.Wrap(err, "creating reader for V1 layer blob")
return "", fmt.Errorf("creating reader for V1 layer blob: %w", err)
}

data, err := io.ReadAll(gzipReader)
if err != nil {
return "", errors.Wrap(err, "reading V1 layer blob")
return "", fmt.Errorf("reading V1 layer blob: %w", err)
}
sha := sha256.Sum256(data)

Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ require (
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.0
github.com/opencontainers/runtime-spec v1.2.0
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.3
github.com/urfave/cli v1.22.15
gopkg.in/yaml.v2 v2.4.0
Expand Down
8 changes: 4 additions & 4 deletions imagepuller/image_puller.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package imagepuller // import "code.cloudfoundry.org/groot/imagepuller"

import (
"fmt"
"io"

"code.cloudfoundry.org/groot/imagepuller/ondemand"
"code.cloudfoundry.org/lager/v3"
imgspec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
)

//go:generate counterfeiter . Fetcher
Expand Down Expand Up @@ -71,7 +71,7 @@ func (p *ImagePuller) Pull(logger lager.Logger, spec ImageSpec) (Image, error) {

imageInfo, err := p.fetcher.ImageInfo(logger)
if err != nil {
return Image{}, errors.Wrap(err, "fetching list of layer infos")
return Image{}, fmt.Errorf("fetching list of layer infos: %w", err)
}
logger.Debug("fetched-layer-infos", lager.Data{"infos": imageInfo.LayerInfos})

Expand Down Expand Up @@ -118,7 +118,7 @@ func (p *ImagePuller) buildLayer(logger lager.Logger, layerInfo LayerInfo, paren
Create: func() (io.ReadCloser, error) {
stream, blobSize, err := p.fetcher.StreamBlob(logger, layerInfo)
if err != nil {
return nil, errors.Wrapf(err, "opening stream for blob `%s`", layerInfo.BlobID)
return nil, fmt.Errorf("opening stream for blob `%s`: %w", layerInfo.BlobID, err)
}

logger.Debug("got-stream-for-blob", lager.Data{"size": blobSize})
Expand All @@ -145,7 +145,7 @@ func quotaExceeded(logger lager.Logger, layerInfos []LayerInfo, spec ImageSpec)

totalSize := layersSize(layerInfos)
if totalSize > spec.DiskLimit {
err := errors.Errorf("layers exceed disk quota %d/%d bytes", totalSize, spec.DiskLimit)
err := fmt.Errorf("layers exceed disk quota %d/%d bytes", totalSize, spec.DiskLimit)
logger.Error("blob-manifest-size-check-failed", err, lager.Data{
"totalSize": totalSize,
"diskLimit": spec.DiskLimit,
Expand Down
5 changes: 3 additions & 2 deletions pull.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package groot

import (
"fmt"

"code.cloudfoundry.org/groot/imagepuller"
"github.com/pkg/errors"
)

func (g *Groot) Pull() error {
Expand All @@ -11,5 +12,5 @@ func (g *Groot) Pull() error {
defer g.Logger.Debug("ending")

_, err := g.ImagePuller.Pull(g.Logger, imagepuller.ImageSpec{})
return errors.Wrap(err, "pulling image")
return fmt.Errorf("pulling image: %w", err)
}
2 changes: 1 addition & 1 deletion pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package groot_test

import (
"bytes"
"errors"
"io"

"code.cloudfoundry.org/groot"
Expand All @@ -11,7 +12,6 @@ import (
"code.cloudfoundry.org/lager/v3/lagertest"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
errors "github.com/pkg/errors"
)

var _ = Describe("Pull", func() {
Expand Down
3 changes: 2 additions & 1 deletion stats_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package groot_test

import (
"errors"

"code.cloudfoundry.org/groot"
"code.cloudfoundry.org/groot/grootfakes"
"code.cloudfoundry.org/lager/v3/lagertest"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
errors "github.com/pkg/errors"
)

var _ = Describe("Stats", func() {
Expand Down
Loading