Check the validity of the platforms
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>docker-19.03
parent
e5b647a1a3
commit
aa31ff073f
|
@ -558,7 +558,9 @@ func newWorkerController(c *cli.Context, wiOpt workerInitializerOpt) (*worker.Co
|
|||
return nil, err
|
||||
}
|
||||
for _, w := range ws {
|
||||
logrus.Infof("found worker %q, labels=%v, platforms=%v", w.ID(), w.Labels(), formatPlatforms(w.Platforms()))
|
||||
p := formatPlatforms(w.Platforms())
|
||||
logrus.Infof("found worker %q, labels=%v, platforms=%v", w.ID(), w.Labels(), p)
|
||||
binfmt_misc.WarnIfUnsupported(p)
|
||||
if err = wc.Add(w); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
package binfmt_misc
|
||||
|
||||
func amd64Supported() bool {
|
||||
return check(Binaryamd64) == nil
|
||||
func amd64Supported() error {
|
||||
return check(Binaryamd64)
|
||||
}
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
package binfmt_misc
|
||||
|
||||
func amd64Supported() bool {
|
||||
return true
|
||||
func amd64Supported() error {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
package binfmt_misc
|
||||
|
||||
func arm64Supported() bool {
|
||||
return check(Binaryarm64) == nil
|
||||
func arm64Supported() error {
|
||||
return check(Binaryarm64)
|
||||
}
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
package binfmt_misc
|
||||
|
||||
func arm64Supported() bool {
|
||||
return true
|
||||
func arm64Supported() error {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
package binfmt_misc
|
||||
|
||||
func armSupported() bool {
|
||||
return check(Binaryarm) == nil
|
||||
func armSupported() error {
|
||||
return check(Binaryarm)
|
||||
}
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
package binfmt_misc
|
||||
|
||||
func armSupported() bool {
|
||||
return true
|
||||
func armSupported() error {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func check(bin string) error {
|
||||
|
@ -35,5 +36,10 @@ func check(bin string) error {
|
|||
}
|
||||
f.Close()
|
||||
|
||||
return exec.Command(pp).Run()
|
||||
cmd := exec.Command("/check")
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||
Chroot: tmpdir,
|
||||
}
|
||||
err = cmd.Run()
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"sync"
|
||||
|
||||
"github.com/containerd/containerd/platforms"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var once sync.Once
|
||||
|
@ -14,19 +15,53 @@ 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 {
|
||||
arr = append(arr, p)
|
||||
}
|
||||
if p := "linux/arm64"; def != p && arm64Supported() {
|
||||
if p := "linux/arm64"; def != p && arm64Supported() == nil {
|
||||
arr = append(arr, p)
|
||||
}
|
||||
if !strings.HasPrefix(def, "linux/arm/") && armSupported() {
|
||||
if !strings.HasPrefix(def, "linux/arm/") && armSupported() == nil {
|
||||
arr = append(arr, "linux/arm/v7", "linux/arm/v6")
|
||||
} else if def == "linux/arm/v7" {
|
||||
arr = append(arr, "linux/arm/v6")
|
||||
}
|
||||
})
|
||||
|
||||
return arr
|
||||
}
|
||||
|
||||
//WarnIfUnsupported validates 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 platform from the candidates.
|
||||
func WarnIfUnsupported(pfs []string) {
|
||||
def := platforms.DefaultString()
|
||||
for _, p := range pfs {
|
||||
if p != def {
|
||||
if p == "linux/amd64" {
|
||||
if err := amd64Supported(); err != nil {
|
||||
printPlatfromWarning(p, err)
|
||||
}
|
||||
}
|
||||
if p == "linux/arm64" {
|
||||
if err := arm64Supported(); err != nil {
|
||||
printPlatfromWarning(p, err)
|
||||
}
|
||||
}
|
||||
if strings.HasPrefix(p, "linux/arm/v6") || strings.HasPrefix(p, "linux/arm/v7") {
|
||||
if err := armSupported(); err != nil {
|
||||
printPlatfromWarning(p, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func printPlatfromWarning(p string, err error) {
|
||||
if strings.Contains(err.Error(), "exec format error") {
|
||||
logrus.Warnf("platform %s cannot pass the validation, kernel support for miscellaneous binary may have not enabled.", p)
|
||||
} else if strings.Contains(err.Error(), "no such file or directory") {
|
||||
logrus.Warnf("platforms %s cannot pass the validation, '-F' flag might have not set for 'binfmt_misc'.", p)
|
||||
} else {
|
||||
logrus.Warnf("platforms %s cannot pass the validation: %s", p, err.Error())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue