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

Commit 55b2a75

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

2 files changed

Lines changed: 34 additions & 8 deletions

File tree

image/config.go

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,41 @@ func findConfig(w walker, d *descriptor) (*config, error) {
6464
}
6565
}
6666

67-
func (c *config) validate(w walk) error {
67+
func validateConfig(c config) error {
6868

6969
// check if the rootfs type is 'layers'
7070
if c.RootFS.Type != "layers" {
71-
return errors.New("%q is an unknown rootfs type, MUST be 'layers'", c.RootFS.Type)
71+
return fmt.Errorf("%q is an unknown rootfs type, MUST be 'layers'", c.RootFS.Type)
7272
}
7373

74-
for _, d = range c.RootFs.DiffIDs {
75-
h := sha256.New()
76-
DiffIds := "sha256" + hex.EncodeToString(h.Sum(nil))
74+
//check os and architecture
75+
if err := checkPlatform(c); err != nil {
76+
return err
77+
}
78+
}
7779

78-
if DiffIds != d {
79-
return errors.New("DiffIDs mismatch")
80+
func checkPlatform(c config) error {
81+
validCombins := map[string][]string{
82+
"darwin": {"386", "amd64", "arm", "arm64"},
83+
"dragonfly": {"amd64"},
84+
"freebsd": {"386", "amd64", "arm"},
85+
"linux": {"386", "amd64", "arm", "arm64", "ppc64", "ppc64le", "mips64", "mips64le"},
86+
"netbsd": {"386", "amd64", "arm"},
87+
"openbsd": {"386", "amd64", "arm"},
88+
"plan9": {"386", "amd64"},
89+
"solaris": {"amd64"},
90+
"windows": {"386", "amd64"}}
91+
for os, archs := range validCombins {
92+
if os == c.OS {
93+
for _, arch := range archs {
94+
if arch == c.Architecture {
95+
return nil
96+
}
97+
}
98+
return fmt.Errorf("Combination of %q and %q is invalid.", c.OS, c.Architecture)
99+
}
100+
}
101+
return fmt.Errorf("Operation system %q of the bundle is not supported yet.", c.OS)
80102
}
81103

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

image/image.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func validate(w walker, refs []string, out *log.Logger) error {
9393
return err
9494
}
9595

96-
if err := c.validate(w); err != nil {
96+
if err := validateConfig(c); err != nil {
9797
return err
9898
}
9999

@@ -190,6 +190,10 @@ func createRuntimeBundle(w walker, dest, refName, rootfs string) error {
190190
return err
191191
}
192192

193+
if err = validateConfig(c); err != nil {
194+
return err
195+
}
196+
193197
err = m.unpack(w, filepath.Join(dest, rootfs))
194198
if err != nil {
195199
return err

0 commit comments

Comments
 (0)