Skip to content
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

Merged
merged 1 commit into from
Mar 24, 2019
Merged

Conversation

chendave
Copy link
Collaborator

@chendave chendave commented Mar 5, 2019

Signed-off-by: Dave Chen dave.chen@arm.com

@AkihiroSuda
Copy link
Member

@tonistiigi PTAL?

@chendave
Copy link
Collaborator Author

chendave commented Mar 7, 2019

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.

@tonistiigi
Copy link
Member

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 F is missing in the options. If binfmt_misc is not mounted but the binary check in #840 still works then it should be safe to assume that F was configured properly.

@tonistiigi
Copy link
Member

Another way would be to run (a second pass of) #840 with chroot that should also detect if F was checked or not.

@chendave
Copy link
Collaborator Author

chendave commented Mar 8, 2019

okay, I will take a look, thanks!

@chendave
Copy link
Collaborator Author

chendave commented Mar 9, 2019

@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.

@tonistiigi
Copy link
Member

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 -F.

@chendave
Copy link
Collaborator Author

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!

@chendave
Copy link
Collaborator Author

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.

Copy link
Member

@tonistiigi tonistiigi left a 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.

cmd/buildkitd/main_containerd_worker.go Outdated Show resolved Hide resolved
@chendave
Copy link
Collaborator Author

At least make it so it works with manual config as well, not as an exception for flags.

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?

Note that #840 does not actually guarantee -F afaik . -F is needed for chrooted programs but the detection currently does not check that.

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!

@chendave chendave force-pushed the hint branch 2 times, most recently from ca781b0 to d7a155d Compare March 12, 2019 05:23
@tonistiigi
Copy link
Member

May I know what do you mean by "make it works with manual config"

GlobalStringSlice only returns values from the flags, there is also a config file for buildkitd that has the same options.

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.

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.

@chendave
Copy link
Collaborator Author

@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 chroot can have a try there.

I am thinking of providing a similar tool in buildkit to do something like below, but this will be a long term effort.

docker run --rm --privileged multiarch/qemu-user-static:register --reset (set, clean etc.)

@chendave chendave changed the title Show the hints when buildkit is on multi-arch mode Check the validity of the platforms Mar 14, 2019
@chendave chendave closed this Mar 14, 2019
@chendave chendave reopened this Mar 14, 2019
@chendave chendave closed this Mar 14, 2019
@chendave chendave reopened this Mar 14, 2019
@tonistiigi
Copy link
Member

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 F is the issue.

For the validation of currently set ones, instead of repeating SupportedPlatforms call it and compare the 2 sets. You may also need to do normalization of the values (or just validate after they have been parsed). The error/warn should contain the name of the wrongly configured platform.

@chendave
Copy link
Collaborator Author

Thank you, I will address both of them later.

@chendave
Copy link
Collaborator Author

let's retest this.

@chendave chendave closed this Mar 19, 2019
@chendave
Copy link
Collaborator Author

@tonistiigi , hi, what do you think about this? thanks!

return exec.Command(pp).Run()
output, err := exec.Command(pp).CombinedOutput()
if err == nil {
cmd := exec.Command("chroot", ".", "/check")
Copy link
Member

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

}
if cfg.Workers.Containerd.Platforms == nil {
cfg.Workers.Containerd.Platforms = binfmt_misc.SupportedPlatforms()
} else {
Copy link
Member

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.

@@ -10,30 +10,36 @@ import (
"path/filepath"
)

func check(bin string) error {
func check(bin string) (string, error) {
Copy link
Member

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.

arr = append(arr, p)
if p := "linux/amd64"; def != p {
_, err := amd64Supported()
if err == nil {
Copy link
Member

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

//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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to printPlatfromWarning

//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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename WarnIfUnsupported

//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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

binary

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") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

directory

@chendave
Copy link
Collaborator Author

@tonistiigi , thanks for your review! hope it is better than before.

@@ -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) {
Copy link
Member

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

Copy link
Collaborator Author

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.

for _, p := range pfs {
if p != def {
if p == "linux/amd64" {
err := amd64Supported()
Copy link
Member

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)
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

return exec.Command(pp).Run()
err = exec.Command(pp).Run()
if err == nil {
cmd := exec.Command("/check")
Copy link
Member

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?

Copy link
Collaborator Author

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.

@@ -35,5 +36,12 @@ func check(bin string) error {
}
f.Close()

return exec.Command(pp).Run()
if err == nil {
Copy link
Member

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

Copy link
Member

@tonistiigi tonistiigi left a 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) {
Copy link
Member

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 ....

Copy link
Collaborator Author

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>
@chendave
Copy link
Collaborator Author

retest

@chendave chendave closed this Mar 24, 2019
@chendave chendave reopened this Mar 24, 2019
@chendave
Copy link
Collaborator Author

weird, the CI is not much stable?

@chendave chendave closed this Mar 24, 2019
@chendave chendave reopened this Mar 24, 2019
@tonistiigi tonistiigi merged commit 2453e6f into moby:master Mar 24, 2019
@chendave chendave deleted the hint branch March 25, 2019 01:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants