Skip to content
This repository was archived by the owner on Jan 15, 2026. It is now read-only.

Commit a7f5cc0

Browse files
author
zhouhao
committed
add config validate
Signed-off-by: zhouhao <zhouhao@cn.fujitsu.com>
1 parent b88fd0b commit a7f5cc0

2 files changed

Lines changed: 31 additions & 17 deletions

File tree

image/config.go

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ func findConfig(w walker, d *descriptor) (*config, error) {
5353
if err := json.Unmarshal(buf, &c); err != nil {
5454
return err
5555
}
56+
// check if the rootfs type is 'layers'
57+
if c.RootFS.Type != "layers" {
58+
return fmt.Errorf("%q is an unknown rootfs type, MUST be 'layers'", c.RootFS.Type)
59+
}
60+
61+
//check os and architecture
62+
if err := checkPlatform(c); err != nil {
63+
return err
64+
}
5665
return errEOW
5766
}); err {
5867
case nil:
@@ -64,19 +73,28 @@ func findConfig(w walker, d *descriptor) (*config, error) {
6473
}
6574
}
6675

67-
func (c *config) validate(w walk) error {
68-
69-
// check if the rootfs type is 'layers'
70-
if c.RootFS.Type != "layers" {
71-
return errors.New("%q is an unknown rootfs type, MUST be 'layers'", c.RootFS.Type)
76+
func checkPlatform(c config) error {
77+
validCombins := map[string][]string{
78+
"darwin": {"386", "amd64", "arm", "arm64"},
79+
"dragonfly": {"amd64"},
80+
"freebsd": {"386", "amd64", "arm"},
81+
"linux": {"386", "amd64", "arm", "arm64", "ppc64", "ppc64le", "mips64", "mips64le"},
82+
"netbsd": {"386", "amd64", "arm"},
83+
"openbsd": {"386", "amd64", "arm"},
84+
"plan9": {"386", "amd64"},
85+
"solaris": {"amd64"},
86+
"windows": {"386", "amd64"}}
87+
for os, archs := range validCombins {
88+
if os == c.OS {
89+
for _, arch := range archs {
90+
if arch == c.Architecture {
91+
return nil
92+
}
93+
}
94+
return fmt.Errorf("Combination of %q and %q is invalid.", c.OS, c.Architecture)
95+
}
7296
}
73-
74-
for _, d = range c.RootFs.DiffIDs {
75-
h := sha256.New()
76-
DiffIds := "sha256" + hex.EncodeToString(h.Sum(nil))
77-
78-
if DiffIds != d {
79-
return errors.New("DiffIDs mismatch")
97+
return fmt.Errorf("Operation system %q of the bundle is not supported yet.", c.OS)
8098
}
8199

82100
func (c *config) runtimeSpec(rootfs string) (*specs.Spec, error) {

image/image.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,11 @@ func validate(w walker, refs []string, out *log.Logger) error {
8888
return err
8989
}
9090

91-
c, err := findConfig(w, &m.Config)
91+
_, err := findConfig(w, &m.Config)
9292
if err != nil {
9393
return err
9494
}
9595

96-
if err := c.validate(w); err != nil {
97-
return err
98-
}
99-
10096
if out != nil {
10197
out.Printf("reference %q: OK", ref)
10298
}

0 commit comments

Comments
 (0)