Skip to content

Commit

Permalink
minor refactor in dmverity-vhd tool (#1948)
Browse files Browse the repository at this point in the history
Use `errors` package instead of the `github.com/pkg/errors`.

`createVHD` accepts layer number to avoid calling `layer.DiffID()`
twice.

Signed-off-by: Maksim An <maksiman@microsoft.com>
(cherry picked from commit a3be979)
  • Loading branch information
anmaxvl committed Oct 30, 2023
1 parent 9c041d3 commit 114d70c
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions cmd/dmverity-vhd/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"fmt"
"os"
"path/filepath"
Expand All @@ -11,7 +12,6 @@ import (
"github.com/google/go-containerregistry/pkg/v1/daemon"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/google/go-containerregistry/pkg/v1/tarball"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli"

Expand Down Expand Up @@ -184,28 +184,25 @@ var createVHDCommand = cli.Command{

log.Debug("creating layer VHDs with dm-verity")
for layerNumber, layer := range layers {
diff, err := layer.DiffID()
if err != nil {
return fmt.Errorf("failed to read layer diff: %w", err)
}
log.WithFields(log.Fields{
"layerNumber": layerNumber,
"layerDiff": diff.String(),
}).Debug("converting tar to layer VHD")
if err := createVHD(layer, ctx.String(outputDirFlag), ctx.Bool(hashDeviceVhdFlag)); err != nil {
if err := createVHD(layerNumber, layer, ctx.String(outputDirFlag), ctx.Bool(hashDeviceVhdFlag)); err != nil {
return err
}
}
return nil
},
}

func createVHD(layer v1.Layer, outDir string, verityHashDev bool) error {
func createVHD(layerNumber int, layer v1.Layer, outDir string, verityHashDev bool) error {
diffID, err := layer.DiffID()
if err != nil {
return fmt.Errorf("failed to read layer diff: %w", err)
}

log.WithFields(log.Fields{
"layerNumber": layerNumber,
"layerDiff": diffID.String(),
}).Debug("converting tar to layer VHD")

rc, err := layer.Uncompressed()
if err != nil {
return fmt.Errorf("failed to uncompress layer %s: %w", diffID.String(), err)
Expand Down

0 comments on commit 114d70c

Please sign in to comment.