This repository has been archived by the owner on Jan 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 489
Show container image manifest for pods #2695
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
df8bec1
Show container image manifest for pods
mklanjsek d5332d2
Add image related tags to go command lane tools
mklanjsek 50b5ffd
Specify host os for image inspection
mklanjsek a6a54ee
Update go modules
mklanjsek 044a1f8
Install libraries for verify generated code step
mklanjsek 6410676
Fix mock files
mklanjsek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Show container image manifest for pods |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package printer | ||
|
||
import ( | ||
context "context" | ||
"fmt" | ||
"strings" | ||
"sync" | ||
|
||
"github.com/containers/image/v5/image" | ||
"github.com/containers/image/v5/transports/alltransports" | ||
"github.com/containers/image/v5/types" | ||
|
||
"github.com/vmware-tanzu/octant/internal/util/json" | ||
) | ||
|
||
type ImageManifest struct { | ||
Manifest string | ||
Configuration string | ||
} | ||
|
||
type ImageEntry struct { | ||
ImageName string | ||
HostOS string | ||
} | ||
|
||
type ManifestConfiguration struct { | ||
imageCache map[ImageEntry]ImageManifest | ||
imageLock sync.Mutex | ||
} | ||
|
||
var ( | ||
ManifestManager = *NewManifestConfiguration() | ||
) | ||
|
||
func NewManifestConfiguration() *ManifestConfiguration { | ||
mc := &ManifestConfiguration{} | ||
return mc | ||
} | ||
|
||
func (manifest *ManifestConfiguration) GetImageManifest(ctx context.Context, hostOS, imageName string) (string, string, error) { | ||
parts := strings.SplitN(imageName, "://", 2) // if format not specified, assume docker | ||
if len(parts) != 2 { | ||
imageName = "docker://" + imageName | ||
} | ||
|
||
imageEntry := ImageEntry{ImageName: imageName, HostOS: hostOS} | ||
if _, ok := manifest.imageCache[imageEntry]; ok { | ||
return manifest.imageCache[imageEntry].Manifest, manifest.imageCache[imageEntry].Configuration, nil | ||
} | ||
|
||
manifest.imageLock.Lock() | ||
defer manifest.imageLock.Unlock() | ||
|
||
srcRef, err := alltransports.ParseImageName(imageName) | ||
if err != nil { | ||
return "", "", fmt.Errorf("error parsing image name for image %s: %w", imageName, err) | ||
} | ||
|
||
systemCtx := &types.SystemContext{OSChoice: hostOS} | ||
|
||
imageSrc, err := srcRef.NewImageSource(ctx, systemCtx) | ||
if err != nil { | ||
return "", "", fmt.Errorf("error creating image source for image %s: %w", imageName, err) | ||
} | ||
|
||
rawManifest, _, err := imageSrc.GetManifest(ctx, nil) | ||
if err != nil { | ||
return "", "", fmt.Errorf("error getting manifest for for image %s: %w", imageName, err) | ||
} | ||
|
||
image, err := image.FromUnparsedImage(ctx, systemCtx, image.UnparsedInstance(imageSrc, nil)) | ||
if err != nil { | ||
return "", "", fmt.Errorf("error parsing manifest for for image %s: %w", imageName, err) | ||
} | ||
|
||
rawConfiguration, err := image.OCIConfig(ctx) | ||
if err != nil { | ||
return "", "", fmt.Errorf("error getting image config blob for for image %s: %w", imageName, err) | ||
} | ||
|
||
configOutput, err := json.MarshalIndent(rawConfiguration, "", " ") | ||
|
||
if manifest.imageCache == nil { | ||
manifest.imageCache = make(map[ImageEntry]ImageManifest) | ||
} | ||
manifest.imageCache[imageEntry] = ImageManifest{string(rawManifest), string(configOutput)} | ||
|
||
return string(rawManifest), string(configOutput), nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error shown in the UI is hard to read when all the errors from the error chain are concatenated together.
An easy way to reproduce this is to kill the internet before caching and see the error in the pod summary.
It shows something like:
Unable to load image manifest error creating image source for image docker://nginx:1.14.2: pinging container registry registry-1.docker.io: Get "https://registry-1.docker.io/v2/": dial tcp: lookup registry-1.docker.io: no such host
.The error from https://github.com/vmware-tanzu/octant/pull/2695/files#diff-85fedc5e144e89139dc0296c0fb2574d2576d493b8bad648bd79c31d32dbd73bR63 and others in the manifest.go and any subsequent errors can be formatted a little better with some delimiters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is not a huge blocker and can be made afterwards.