-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Check the validity of the platforms #854
Conversation
@tonistiigi PTAL? |
Cause we cannot make it without the "-F" options is set, we'd better to show the warning somewhere to give end-user an hint, thanks for the review. |
In this place, I don't think there is any indication that the user is using qemu or if it is configured at all or configured incorrectly. We could instead modify the main qemu detection in #840 to look for the enabled configuration and warn or error if |
Another way would be to run (a second pass of) #840 with chroot that should also detect if |
okay, I will take a look, thanks! |
@tonistiigi, I did a test locally, the check will pass regardless the binfmt_misc is mounted or not, but as long as the "-F" flag has been set. |
With #840 the config of secondary platforms is not needed anymore. If it is used, it means manual override and probably doesn't need hints. Also, in the place where you have added it, it only works for flags and not for configuration. We could do either #854 (comment) or #854 (comment) though if you want to hint the need for |
okay, if the "-F" is not configured well, secondary platforms will not pass the check, and then #840 will not configure the platform as a available platform, I think this is good so far, the secondary platforms are not added so that the warn per my understanding is needn't. But what I want to say in this patch is when the platform is added by flags manually, it can be show by the CLI, and those platforms that are added seems okay, but actually, if the "-F" is not set configured well, those secondary platforms won't work, this is why I want to show the warning message here, those secondary platforms are added but they might not work though. Based on those warning message, he/she might consider to set the option "-F" and then those manually added platform should work. what do you think? thanks! |
and someone like me not always depend on what's the default configuration provides but only concern the specific platform and this is case why the flag override is need here. |
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.
At least make it so it works with manual config as well, not as an exception for flags.
Note that #840 does not actually guarantee -F
afaik . -F
is needed for chrooted programs but the detection currently does not check that.
May I know what do you mean by "make it works with manual config"? Could you pls elaborate a little? My understanding is #840 will provide the default available platforms, while the flag here is to override the default and is the manual configuration, am I wrong?
I tried, if the "-F" option is not set, the #840 check while fail, while "-F" option is set the #840 will success, so I think #840 check it enough. BTW, I am still new to this project, pls help to guide me if there is any misunderstanding from me, thanks! |
ca781b0
to
d7a155d
Compare
I haven't tested the flag myself but it also depends on if you are running the buildkitd from host or from a different mount namespace. |
@tonistiigi , you are right! this patch doesn't check the option of "-F", I still don't have a good way to check that, cause this need a secondary filesystem so that I am thinking of providing a similar tool in buildkit to do something like below, but this will be a long term effort.
|
If you want to go with chroot path then as the test binaries are static you could just specify the chroot to their parent directory on invoking. That should be enough. You could also run with and without chroot and provide a better error if you can detect that missing For the validation of currently set ones, instead of repeating |
Thank you, I will address both of them later. |
let's retest this. |
@tonistiigi , hi, what do you think about this? thanks! |
util/binfmt_misc/check.go
Outdated
return exec.Command(pp).Run() | ||
output, err := exec.Command(pp).CombinedOutput() | ||
if err == nil { | ||
cmd := exec.Command("chroot", ".", "/check") |
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.
set chroot in SysProcAttr
, don't call the binary
cmd/buildkitd/main.go
Outdated
} | ||
if cfg.Workers.Containerd.Platforms == nil { | ||
cfg.Workers.Containerd.Platforms = binfmt_misc.SupportedPlatforms() | ||
} else { |
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.
just run it once per each worker instead of looking for else/flags-set case. if detection was automatic validation is just a no-op.
util/binfmt_misc/check.go
Outdated
@@ -10,30 +10,36 @@ import ( | |||
"path/filepath" | |||
) | |||
|
|||
func check(bin string) error { | |||
func check(bin string) (string, error) { |
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.
just return error. You can access stderr from ExitError
or you can wrap the error with extra message if you like.
util/binfmt_misc/detect.go
Outdated
arr = append(arr, p) | ||
if p := "linux/amd64"; def != p { | ||
_, err := amd64Supported() | ||
if err == nil { |
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.
nit: put these check on a single line
util/binfmt_misc/detect.go
Outdated
//Only show the warning when the platforms are maually specified, show the message for the platforms | ||
//finding provided by `SupportedPlatforms` is a little annoying, no platform specifed but the warning | ||
//message is shown might confuse end users. | ||
func printErr(p string, output string, err error) { |
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.
rename to printPlatfromWarning
util/binfmt_misc/detect.go
Outdated
//Here, the func just validate the platforms and show warning message if there is, | ||
//the end user could fix the issue based on those warning, and thus no need to drop | ||
//the platfrom from the candidates. | ||
func ValidatePlatforms(pfs []string) { |
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.
rename WarnIfUnsupported
util/binfmt_misc/detect.go
Outdated
//message is shown might confuse end users. | ||
func printErr(p string, output string, err error) { | ||
if strings.Contains(err.Error(), "exec format error") { | ||
logrus.Warnf("platform %s cannot pass the validation, kernel support for miscellaneous bianry may have not enabled.", p) |
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.
binary
util/binfmt_misc/detect.go
Outdated
func printErr(p string, output string, err error) { | ||
if strings.Contains(err.Error(), "exec format error") { | ||
logrus.Warnf("platform %s cannot pass the validation, kernel support for miscellaneous bianry may have not enabled.", p) | ||
} else if strings.Contains(output, "No such file or director") { |
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.
directory
@tonistiigi , thanks for your review! hope it is better than before. |
util/binfmt_misc/detect.go
Outdated
@@ -14,19 +15,56 @@ func SupportedPlatforms() []string { | |||
once.Do(func() { | |||
def := platforms.DefaultString() | |||
arr = append(arr, def) | |||
|
|||
if p := "linux/amd64"; def != p && amd64Supported() { | |||
if p := "linux/amd64"; def != p && (amd64Supported() == nil) { |
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.
parenthesis are not needed in these checks
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.
agreed, but parenthesis here make it easier to read, anyway, I will remove it.
util/binfmt_misc/detect.go
Outdated
for _, p := range pfs { | ||
if p != def { | ||
if p == "linux/amd64" { | ||
err := amd64Supported() |
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.
nit: single-line these:
if err := amd64Supported(); err != nil {
printPlatfromWarning(p, err)
}
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.
will do
util/binfmt_misc/check.go
Outdated
return exec.Command(pp).Run() | ||
err = exec.Command(pp).Run() | ||
if err == nil { | ||
cmd := exec.Command("/check") |
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.
what's the benefit of running it twice and not only the chroot version?
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.
Nice catch! no benefit at all, new RP is one the way.
util/binfmt_misc/check.go
Outdated
@@ -35,5 +36,12 @@ func check(bin string) error { | |||
} | |||
f.Close() | |||
|
|||
return exec.Command(pp).Run() | |||
if err == nil { |
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 err == nil
check is meaningless
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.
LGTM after comment fix
//Here, the func just validate the platforms and show warning message if there is, | ||
//the end user could fix the issue based on those warning, and thus no need to drop | ||
//the platfrom from the candidates. | ||
func WarnIfUnsupported(pfs []string) { |
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.
(Sorry, didn't notice this before.) The godoc convention is that a function comment needs to start with the function name. Eg. // WarnIfUnsupported validates the platform and shows warning ....
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.
np, you left many good comments! really learnt a lot from those comments, thanks!
platforms can still be added but some warning message will be emitted if the platform cannot pass the validity check. Signed-off-by: Dave Chen <dave.chen@arm.com>
retest |
weird, the CI is not much stable? |
Signed-off-by: Dave Chen dave.chen@arm.com