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

Added flag --layers to enable/disable functionality of showing each layers of image #639

Merged
merged 1 commit into from
Feb 27, 2024
Merged
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
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
Loading