deduceContainerPlatform tries to deduce `ctr`'s platform. If both `ctr.OS` and `ctr.ImageManifest` are empty, assume the image comes from a pre-OS times and use the host platform to match the behavior of [container.FromDisk]. Otherwise: - `ctr.ImageManifest.Platform` is used, if it exists and is not
( ctx context.Context, migration platformReader, ctr *container.Container, )
| 49 | // `ctr.ImageID`) is used – this looks for the best *present* matching manifest in |
| 50 | // the store. |
| 51 | func deduceContainerPlatform( |
| 52 | ctx context.Context, |
| 53 | migration platformReader, |
| 54 | ctr *container.Container, |
| 55 | ) (ocispec.Platform, error) { |
| 56 | if ctr.OS == "" && ctr.ImageManifest == nil { //nolint:staticcheck // ignore SA1019 because we are testing deprecated field migration |
| 57 | return platforms.DefaultSpec(), nil |
| 58 | } |
| 59 | |
| 60 | var errs []error |
| 61 | isValidPlatform := func(p ocispec.Platform) bool { |
| 62 | return p.OS != "" && p.Architecture != "" |
| 63 | } |
| 64 | |
| 65 | if ctr.ImageManifest != nil { |
| 66 | if ctr.ImageManifest.Platform != nil { |
| 67 | return *ctr.ImageManifest.Platform, nil |
| 68 | } |
| 69 | |
| 70 | if ctr.ImageManifest != nil { |
| 71 | p, err := migration.ReadPlatformFromConfigByImageManifest(ctx, *ctr.ImageManifest) |
| 72 | if err != nil { |
| 73 | errs = append(errs, err) |
| 74 | } else { |
| 75 | if isValidPlatform(p) { |
| 76 | return p, nil |
| 77 | } |
| 78 | errs = append(errs, errors.New("malformed image config obtained by ImageManifestDescriptor")) |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | if ctr.ImageID != "" { |
| 84 | p, err := migration.ReadPlatformFromImage(ctx, ctr.ImageID) |
| 85 | if err != nil { |
| 86 | errs = append(errs, err) |
| 87 | } else { |
| 88 | if isValidPlatform(p) { |
| 89 | return p, nil |
| 90 | } |
| 91 | errs = append(errs, errors.New("malformed image config obtained by image id")) |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | return ocispec.Platform{}, errors.Wrap(multierror.Join(errs...), "cannot deduce the container platform") |
| 96 | } |
| 97 | |
| 98 | type daemonPlatformReader struct { |
| 99 | imageService ImageService |
no test coverage detected
searching dependent graphs…