Commit Graph

62 Commits

Author SHA1 Message Date
Brian Goff
8442521645 Add fallback for windows platforms without osversion
The background for this change:

1. Windows host-process containers do not have an OS version set
2. Buildx v0.10 started pushing manifest lists by default, but it never
   has the OSVersion in the platform data (not that there is any way to
   specify what particular OS version you want). The change means that
   containerd cannot run images created with the new buildx on Windows
   because there is no matching OSVersion in the list of manifests.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2023-02-13 23:07:06 +00:00
Maksym Pavlenko
3c8469a782 Use Platform instead of generated API
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2023-01-12 10:30:42 -08:00
Wei Fu
6b7e237fc7 chore: use go fix to cleanup old +build buildtag
Signed-off-by: Wei Fu <fuweid89@gmail.com>
2022-12-29 14:25:14 +08:00
Tony Fang
6e55234c38 Add unit test to function GetCPUVariantFromArch
Add unit test to function GetCPUVariantFromArch
Fix import issue on non-linux platforms
Fix some style issue

Signed-off-by: Tony Fang <nenghui.fang@gmail.com>
2022-12-20 22:00:12 +00:00
Tony Fang
8d5c045435 Use uname machine field to get CPU variant if fails at /proc/cpuinfo
When images/containers in ARM arch were built/executed on x86 host,
getCPUVariant will fail as it tries to look for /proc/cpuinfo, whose
content is from the host. Adding a new method as fallback to check uname
machine when it happens.

Signed-off-by: Tony Fang <nenghui.fang@gmail.com>
2022-12-20 21:59:32 +00:00
Maksym Pavlenko
3bc8fc4d30 Cleanup build constraints
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2022-12-08 09:36:20 -08:00
Kate
f32595a0c2 Fix "getCPUInfo for OS freebsd: not implemented" on FreeBSD/arm64
Signed-off-by: Kate <kit.ty.kate@disroot.org>
2022-11-04 12:31:03 +00:00
Maksym Pavlenko
ca3b9b50fe Run gofmt 1.19
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2022-08-04 18:18:33 -07:00
Kazuyoshi Kato
a1eb2d8a67 Use testing.F on FuzzPlatformsParse
Signed-off-by: Kazuyoshi Kato <katokazu@amazon.com>
2022-06-15 14:56:20 +00:00
Samuel Karp
95f1d79718
platforms: Run goimports for FreeBSD
Signed-off-by: Samuel Karp <me@samuelkarp.com>
2022-06-09 18:54:10 -07:00
Gijs Peskens
ae22854e2b
Linux containers on FreeBSD
This allows running Linux containers on FreeBSD and modifies the
mounts so that they represent the linux emulated filesystems, as per:
https://wiki.freebsd.org/LinuxJails

Co-authored-by: Gijs Peskens <gijs@peskens.net>, Samuel Karp <samuelkarp@users.noreply.github.com>
Signed-off-by: Artem Khramov <akhramov@pm.me>
2022-06-01 00:56:24 +02:00
Phil Estes
807ded41f0
Update TestNormalize to only test Windows
The output of platforms.DefaultSpec() and the normalized version of the
default platform on 32- and 64-bit ARM are not comparable. This test
was added to validate not losing Windows-specific information during
normalize of the platform object, so for now we are moving this to be a
Windows-only test until we resolve the right behavior on ARM.

Signed-off-by: Phil Estes <estesp@amazon.com>
2022-03-10 11:38:10 -05:00
James Sturtevant
83c80388b2 Initialize platform matchers for current platform
Signed-off-by: James Sturtevant <jsturtevant@gmail.com>
2022-02-10 08:03:25 -08:00
Sebastiaan van Stijn
bec6e4dd67
platforms.Normalize(): do not reset OSVersion and OSFeatures
Commit fb0688362c implemented the Normalize()
function, but marked these fields as deprecated.

It's unclear what the motivation was for this, as the fields are part of the OCI
Image spec. On Windows, the OSVersion field specifically is important when matching
images (as kernel versions may not be compatible).

This patch updates platforms.Normalize() to preserve the OSVersion and OSFeatures
fields.

As a follow-up, we should look at defining an appropriate string-representation
for these fields (possibly as part of the OCI Spec), and update platforms.Parse()
accordingly.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-02-01 17:19:28 +01:00
Phil Estes
a43703fcba
Merge pull request #6455 from tonistiigi/amd64-variants
platforms: add support for matching amd64 variants
2022-01-27 10:07:49 -05:00
Tonis Tiigi
af83e9af10 platforms: add support for matching amd64 variants
Correctly matches optional variants for amd64
arch. These should be used for standardized values
v1-v4 from https://en.wikipedia.org/wiki/X86-64#Microarchitecture_levels.

V1 remains the default and is cleared by default.
Pulling a higher variant will match the highest
available platform lower or equal to the provided one
when platformVector is used.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2022-01-18 20:13:37 -08:00
haoyun
bbe46b8c43 feat: replace github.com/pkg/errors to errors
Signed-off-by: haoyun <yun.hao@daocloud.io>
Co-authored-by: zounengren <zouyee1989@gmail.com>
2022-01-07 10:27:03 +08:00
Daniel Canter
ff77dd1121 Add Windows Server 2022 CI runs
GA for ws2022 github actions VMs launched a couple weeks ago so seems like
it's time to try out the CI on this new SKU.

This involved adding new ws2022 runs for the OS matrices in the CI, fixing up
a test in the platforms package and adding a mapping for the ws2022 container image in
integration/client.

Signed-off-by: Daniel Canter <dcanter@microsoft.com>
2021-12-02 16:18:25 -08:00
zounengren
3a713811be run gofmt with Go 1.17
Signed-off-by: Zou Nengren <zouyee1989@gmail.com>
2021-10-07 20:16:59 +08:00
Hajime Tazaki
a43fa9f284 darwin: runtime support
This commit attemts to support containerd on darwin platform.  With an
external runtime shim, ctr run should work with, for instance,
--runtime=io.containerd.runu.v1.  An example of runtime and shim is
managed under different repository (github.com/ukontainer/runu/).

Signed-off-by: Hajime Tazaki <thehajime@gmail.com>
2021-09-03 09:48:21 +09:00
Claudiu Belu
e2c769d6fb windows: The DefaultSpec platform should match the Default matcher
The Windows Default matcher also checks the the OS Version prefix,
however, the platforms.DefaultSpec does not include it, which means
that it won't match the matcher.

This solves the issue by adding the OS Version to the DefaultSpec.

Signed-off-by: Claudiu Belu <cbelu@cloudbasesolutions.com>
2021-08-26 16:01:21 +00:00
Akihiro Suda
d3aa7ee9f0
Run go fmt with Go 1.17
The new `go fmt` adds `//go:build` lines (https://golang.org/doc/go1.17#tools).

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2021-08-22 09:31:50 +09:00
Derek McGowan
6f027e38a8
Remove redundant build tags
Remove build tags which are already implied by the name of the file.
Ensures build tags are used consistently

Signed-off-by: Derek McGowan <derek@mcg.dev>
2021-08-05 22:27:46 -07:00
Sebastiaan van Stijn
f2c3122e9c
platforms: Format(): use path.Join() instead of joinNotEmpty()
path.Join() also skips empty components, making it the equivalent of
this function.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-08-02 09:48:34 +02:00
Sebastiaan van Stijn
2405671d40
platforms: add "ios" as known OS, "loong64" as known ARCH
- GOOS iOS was added in https://go-review.googlesource.com/c/go/+/254740, and part of go1.16beta1
- GOARCH loong64 was added in https://go-review.googlesource.com/c/go/+/333909, and currently only in master

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-07-23 10:56:08 +02:00
James Sturtevant
d9ff8ebef5 support multi-arch images for windows via ctr
Signed-off-by: James Sturtevant <jstur@microsoft.com>
2021-03-31 15:50:01 -07:00
Derek McGowan
c4bff3d17c
Merge pull request #4943 from AkihiroSuda/platforms-literallyonly
platforms: add subarchless version of Only()
2021-01-20 17:27:43 -08:00
Jason Hall
363f2c392c Derive cpuinfo as needed, instead of at init-time
This changes platforms.Parse to hit /proc to look up CPU info only when
it's needed, instead of in init(). This makes the package a bit easier
for other packages to consume, especially clients that don't call
platforms.Parse or need to lookup CPU info.

Signed-off-by: Jason Hall <jasonhall@redhat.com>
2021-01-19 14:10:39 -05:00
Akihiro Suda
e22ce0fa03
platforms: add subarchless version of Only()
`OnlyStrict()` returns a match comparer for a single platform.

Unlike `Only()`, `OnlyStrict()` does not match sub platforms.
So, "arm/vN" will not match "arm/vM" where M < N, and "amd64" will not also match "386".

`OnlyStrict()` matches non-canonical forms. So, "arm64" matches "arm/64/v8".

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2021-01-15 14:58:14 +09:00
Tianon Gravi
4073aaa7a9 Allow arm64 to fallback to arm (v8, v7, v6, v5)
This isn't supported by *all* arm64 chips, but it is common enough that I think it's worth an explicit fallback.  I think it will be more common for images to have arm64 support without arm support, but even if a user has an arm64 chip that does not support arm32, having it fail to run the arm32 image is an acceptable compromise (because it's non-trivial to detect arm32 support without running a binary, AFAIK).

Also, before this change the failure would've simply been "no such image" instead of "failed to run" so I think it's pretty reasonable to allow it to try the additional 32bit set of images just in case one of them actually does work (like it will on many popular chips like 64bit Raspberry Pis and AWS Graviton).

Signed-off-by: Tianon Gravi <admwiggin@gmail.com>
2021-01-13 09:19:08 -08:00
Tianon Gravi
5fa5f15de5 Add amd64->386 fallback
Signed-off-by: Tianon Gravi <admwiggin@gmail.com>
2021-01-11 16:18:19 -08:00
Tianon Gravi
9072b09145 Refactor platforms.Only with a "platformVector" helper
This improves the hard-coded list of ARM fallbacks in the `platform.Only` implementation (by doing a descending loop over variant numbers instead, which is all the hard-coded list was doing).

Making this a separate function can then more easily be recursive later for handling an `arm64`->`arm` fallback (or similar), but I think it makes the code a lot more clear too (so we're calculating a vector of platforms separately from building a matcher object).

This also makes a minor adjustment in `TestImagePullWithDistSourceLabel` which had an implicit assumption that `platforms.Only` would only ever result in a single suitable manifest, which isn't strictly true (and is likely failing as-is when run on any 32bit `arm` system that's `v6` or higher, which this fixes 😅).

Signed-off-by: Tianon Gravi <admwiggin@gmail.com>
2020-12-28 14:11:14 -08:00
Tianon Gravi
66a3f2cbc7 Add platforms.Only test
This adds a test for `platforms.Only` (previously untested, as far as I can tell).

Signed-off-by: Tianon Gravi <admwiggin@gmail.com>
2020-12-23 14:54:16 -08:00
Kazuyoshi Kato
bb8aac38a0 Do not hardcode "amd64" on LCOW and Windows-related files
Fixes #3281.

Signed-off-by: Kazuyoshi Kato <katokazu@amazon.com>
2020-11-09 13:39:07 -08:00
Tianon Gravi
2055e12953 Add RPi1/RPi0 workaround
On the very popular Raspberry Pi 1 and Zero devices, the CPU is actually ARMv6, but the chip happens to support the feature bit the kernel uses to differentiate v6/v7, so it gets reported as "CPU architecture: 7" and thus fails to run many of the images that get pulled.

To account for this very popular edge case, this also checks "model name" which on these chips will begin with "ARMv6-compatible" -- we could also check uname, but getCPUInfo is already handy, low overhead, and mirrors the code before this.

Signed-off-by: Tianon Gravi <admwiggin@gmail.com>
2020-09-04 14:19:37 -07:00
Tonis Tiigi
7119a2a152 platforms: don’t log arm variant error on darwin
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2020-07-14 08:16:14 -07:00
Phil Estes
89de113de9
Support 32-bit userspace on 64-bit ARM cores
Don't rely on /proc/cpuinfo denoting a 64-bit ARMv8 processor if the
runtime detected GOARCH == arm. This allows aarch64 32-bit userspace
distros to run containers properly via a 32-bit runtime.

Signed-off-by: Phil Estes <estesp@linux.vnet.ibm.com>
2020-02-13 00:10:01 -05:00
Shengjing Zhu
90cd777a6c platforms: fill default arm variant when parse platform specifier
arm has been supported, but something is missing, causes test failure

    --- FAIL: TestParseSelector/linux (0.00s)
        platforms_test.go:292: arm support not fully implemented: not implemented
    --- FAIL: TestParseSelector/macOS (0.00s)
        platforms_test.go:292: arm support not fully implemented: not implemented

Signed-off-by: Shengjing Zhu <zhsj@debian.org>
2020-01-08 13:35:49 +08:00
sayaoailun
726dcaea50 update cpuinfo to make variant matches aarch64 and so on
Signed-off-by: sayaoailun <guojianwei007@126.com>
2019-11-30 23:48:10 +08:00
Derek McGowan
672b86acf8
Merge pull request #3624 from tklauser/platforms-update
platforms: update known OS and arch values
2019-09-05 16:53:37 -07:00
Tobias Klauser
c8cb864ce0 platforms: update known OS and arch values
Update the lists in isKnownOS and isKnownOS according to goosList and
goarchList taken from Go 1.13, see
https://github.com/golang/go/blob/release-branch.go1.13/src/go/build/syslist.go

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2019-09-05 14:15:43 +02:00
chentanjun
8788af7f8d modify-document-duplicate-word
Signed-off-by: chentanjun <2799194073@qq.com>
2019-09-05 09:10:19 +08:00
chentanjun
92a5b08a68 fix-grammar-mistake
Signed-off-by: chentanjun <2799194073@qq.com>
2019-08-28 16:10:08 +08:00
Jaime Caamaño Ruiz
ad25c1a9c3 Improve ARM platform matching
This commit improves ARM platform matching in two instances:

* Some old kernels reported the CPU architecture of arm64 cpus as
  Aarch64 [1].
* In cases where the user is running with armv8 cpu and kernel but amrhf
  user land (so armhf containerd), a possibility given the compatibility
  of armv8 with armv7.

[1] https://elixir.bootlin.com/linux/v3.14.29/source/arch/arm64/kernel/setup.c#L420

Signed-off-by: Jaime Caamaño Ruiz <jcaamano@suse.com>
2019-05-10 16:27:20 +02:00
Jiri Appl
e6529f4ebc Add support to detect ARM variant on Windows
ARM variant detection logic was authored originally with
POSIX OS in mind. This change leaves POSIX code path unaltered
and adds support to detect ARM variant on Windows by leveraging
runtime.goarch.

Signed-off-by: Jiri Appl <jiria@microsoft.com>
2018-10-10 14:17:11 -07:00
Justin Terry (VM)
0110b3c0bc Introduce the Windows lcow diff/snaphotter
Implements the Windows lcow differ/snapshotter responsible for managing
the creation and lifetime of lcow containers on Windows.

Signed-off-by: Justin Terry (VM) <juterry@microsoft.com>
2018-08-28 13:51:04 -07:00
Derek McGowan
9edcfcc1cb
Add platform match comparer interface
Adds a new platform interface for matching and comparing platforms.
This new interface allows both filtering and ordering of platforms
to support running multiple platform and choosing the best platform.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2018-08-27 00:11:46 -07:00
Ian Campbell
c83f9773bc platforms: Add MustParse
This function is analogous to `regexp.MustCompile` and can simplify production
of a `Platform` from a hard-coded strings, e.g. for global variable
initialisation.

Signed-off-by: Ian Campbell <ian.campbell@docker.com>
2018-08-15 11:30:46 +01:00
Derek McGowan
db3c5afc6d
Normalize arm64 to an empty variant
Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2018-06-23 16:35:46 -07:00
Derek McGowan
37ab93e2c8
Fix arm platform matching
The normalization was being inconsistently applied causing a
failure to match some platforms in manifest lists.
Fix the matcher and normalization to be more consistent and
add changes to parser to prevent the defaulted variants from being
set in the platform structure.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2018-06-21 17:07:58 -07:00