ValidateImage given a reference, validate that it is complete. If not, it will *not* pull down missing content. This function is network-free. If you wish to validate and fill in missing content, use PullImage. If the reference is to an index, it will check the index for a manifest for the given arc
(ref *reference.Spec, platforms []imagespec.Platform)
| 31 | // for other architectures. If no architecture is provided, it will validate all manifests. |
| 32 | // It also calculates the hash of each component. |
| 33 | func (p *Provider) ValidateImage(ref *reference.Spec, platforms []imagespec.Platform) (lktspec.ImageSource, error) { |
| 34 | var ( |
| 35 | imageIndex v1.ImageIndex |
| 36 | image v1.Image |
| 37 | imageName = ref.String() |
| 38 | desc *v1.Descriptor |
| 39 | platformMessage = platformMessageGenerator(platforms) |
| 40 | ) |
| 41 | // next try the local cache |
| 42 | root, err := p.FindRoot(imageName) |
| 43 | if err == nil { |
| 44 | img, err := root.Image() |
| 45 | if err == nil { |
| 46 | image = img |
| 47 | if desc, err = partial.Descriptor(img); err != nil { |
| 48 | return ImageSource{}, errors.New("image could not create valid descriptor") |
| 49 | } |
| 50 | } else { |
| 51 | ii, err := root.ImageIndex() |
| 52 | if err == nil { |
| 53 | imageIndex = ii |
| 54 | if desc, err = partial.Descriptor(ii); err != nil { |
| 55 | return ImageSource{}, errors.New("index could not create valid descriptor") |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | // three possibilities now: |
| 61 | // - we did not find anything locally |
| 62 | // - we found an index locally |
| 63 | // - we found an image locally |
| 64 | switch { |
| 65 | case imageIndex == nil && image == nil: |
| 66 | // we did not find it yet - either because we were told not to look locally, |
| 67 | // or because it was not available - so get it from the remote |
| 68 | return ImageSource{}, &noReferenceError{reference: imageName} |
| 69 | case imageIndex != nil: |
| 70 | // check that the index has a manifest for our arch, as well as any non-arch-specific ones |
| 71 | im, err := imageIndex.IndexManifest() |
| 72 | if err != nil { |
| 73 | return ImageSource{}, fmt.Errorf("could not get index manifest: %w", err) |
| 74 | } |
| 75 | var ( |
| 76 | targetPlatforms = make(map[string]bool) |
| 77 | foundPlatforms = make(map[string]bool) |
| 78 | ) |
| 79 | for _, plat := range platforms { |
| 80 | pString := platformString(plat) |
| 81 | targetPlatforms[pString] = false |
| 82 | foundPlatforms[pString] = false |
| 83 | } |
| 84 | // ignore only other architectures; manifest entries that have no architectures at all |
| 85 | // are going to be additional metadata, so we need to check them |
| 86 | for _, m := range im.Manifests { |
| 87 | if m.Platform == nil || (m.Platform.Architecture == unknown && m.Platform.OS == unknown) { |
| 88 | if err := validateManifestContents(imageIndex, m.Digest); err != nil { |
| 89 | return ImageSource{}, fmt.Errorf("invalid image: %w", err) |
| 90 | } |
no test coverage detected