Skip to content

Commit

Permalink
Added flag --layers to enable/disable funtionality of showing each la…
Browse files Browse the repository at this point in the history
…yer of image

Signed-off-by: kumari tanushree <ktanushree@vmware.com>
  • Loading branch information
kumari tanushree committed Feb 26, 2024
1 parent 287c735 commit e75c415
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
19 changes: 13 additions & 6 deletions pkg/imgpkg/cmd/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type DescribeOptions struct {

Concurrency int
OutputType string
Layers bool
IncludeCosignArtifacts bool
}

Expand All @@ -53,6 +54,7 @@ func NewDescribeCmd(o *DescribeOptions) *cobra.Command {
o.RegistryFlags.Set(cmd)
cmd.Flags().IntVar(&o.Concurrency, "concurrency", 5, "Concurrency")
cmd.Flags().StringVarP(&o.OutputType, "output-type", "o", "text", "Type of output possible values: [text, yaml]")
cmd.Flags().BoolVarP(&o.Layers, "layers", "", true, "Retrieve image layers info (Default: false)")
cmd.Flags().BoolVar(&o.IncludeCosignArtifacts, "cosign-artifacts", true, "Retrieve cosign artifact information (Default: true)")
return cmd
}
Expand All @@ -72,6 +74,7 @@ func (d *DescribeOptions) Run() error {
Logger: levelLogger,
Concurrency: d.Concurrency,
IncludeCosignArtifacts: d.IncludeCosignArtifacts,
Layers: d.Layers,
},
d.RegistryFlags.AsRegistryOpts())
if err != nil {
Expand Down Expand Up @@ -138,9 +141,11 @@ func (p bundleTextPrinter) printerRec(description v1.Description, originalLogger
indentLogger.Logf("- Image: %s\n", b.Image)
indentLogger.Logf(" Type: Bundle\n")
indentLogger.Logf(" Origin: %s\n", b.Origin)
indentLogger.Logf(" Layers:\n")
for _, d := range b.Layers {
indentLogger.Logf(" - Digest: %s\n", d.Digest)
if len(b.Layers) > 0 {
indentLogger.Logf(" Layers:\n")
for _, d := range b.Layers {
indentLogger.Logf(" - Digest: %s\n", d.Digest)
}
}
annotations := b.Annotations

Expand All @@ -164,9 +169,11 @@ func (p bundleTextPrinter) printerRec(description v1.Description, originalLogger
if image.ImageType == bundle.ContentImage {
indentLogger.Logf(" Origin: %s\n", image.Origin)
}
indentLogger.Logf(" Layers:\n")
for _, d := range image.Layers {
indentLogger.Logf(" - Digest: %s\n", d.Digest)
if len(image.Layers) > 0 {
indentLogger.Logf(" Layers:\n")
for _, d := range image.Layers {
indentLogger.Logf(" - Digest: %s\n", d.Digest)
}
}
annotations := image.Annotations
p.printAnnotations(annotations, util.NewIndentedLogger(indentLogger))
Expand Down
31 changes: 20 additions & 11 deletions pkg/imgpkg/v1/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type DescribeOpts struct {
Logger bundle.Logger
Concurrency int
IncludeCosignArtifacts bool
Layers bool
}

// SignatureFetcher Interface to retrieve signatures associated with Images
Expand Down Expand Up @@ -116,28 +117,34 @@ func DescribeWithRegistryAndSignatureFetcher(bundleImage string, opts DescribeOp
topBundle := refWithDescription{
imgRef: bundle.NewBundleImageRef(lockconfig.ImageRef{Image: newBundle.DigestRef()}),
}
return topBundle.DescribeBundle(allBundles)
return topBundle.DescribeBundle(allBundles, opts.Layers)
}

type refWithDescription struct {
imgRef bundle.ImageRef
bundle Description
}

func (r *refWithDescription) DescribeBundle(bundles []*bundle.Bundle) (Description, error) {
func (r *refWithDescription) DescribeBundle(bundles []*bundle.Bundle, layers bool) (Description, error) {
var visitedImgs map[string]refWithDescription
return r.describeBundleRec(visitedImgs, r.imgRef, bundles)
return r.describeBundleRec(visitedImgs, r.imgRef, bundles, layers)
}

func (r *refWithDescription) describeBundleRec(visitedImgs map[string]refWithDescription, currentBundle bundle.ImageRef, bundles []*bundle.Bundle) (Description, error) {
func (r *refWithDescription) describeBundleRec(visitedImgs map[string]refWithDescription, currentBundle bundle.ImageRef, bundles []*bundle.Bundle, showLayers bool) (Description, error) {
desc, wasVisited := visitedImgs[currentBundle.Image]
var (
layers []Layers
err error
)
if wasVisited {
return desc.bundle, nil
}

layers, err := getImageLayersInfo(currentBundle.Image)
if err != nil {
return desc.bundle, err
if showLayers {
layers, err = getImageLayersInfo(currentBundle.Image)
if err != nil {
return desc.bundle, err
}
}

desc = refWithDescription{
Expand Down Expand Up @@ -176,7 +183,7 @@ func (r *refWithDescription) describeBundleRec(visitedImgs map[string]refWithDes
}

if *ref.IsBundle {
bundleDesc, err := r.describeBundleRec(visitedImgs, ref, bundles)
bundleDesc, err := r.describeBundleRec(visitedImgs, ref, bundles, showLayers)
if err != nil {
return desc.bundle, err
}
Expand All @@ -192,9 +199,11 @@ func (r *refWithDescription) describeBundleRec(visitedImgs map[string]refWithDes
if err != nil {
return desc.bundle, fmt.Errorf("Internal inconsistency: image %s should be fully resolved", ref.Image)
}
layers, err = getImageLayersInfo(ref.Image)
if err != nil {
return desc.bundle, err
if showLayers {
layers, err = getImageLayersInfo(ref.Image)
if err != nil {
return desc.bundle, err
}
}
desc.bundle.Content.Images[digest.DigestStr()] = ImageInfo{
Image: ref.PrimaryLocation(),
Expand Down

0 comments on commit e75c415

Please sign in to comment.