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

Commit 99f9203

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

2 files changed

Lines changed: 36 additions & 9 deletions

File tree

image/config.go

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

67-
func (c *config) validate(w walk) error {
67+
func (c *config)validate() 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 := c.checkPlatform(); err != nil {
76+
return err
77+
}
78+
return nil
79+
}
7780

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

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

image/image.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func validate(w walker, refs []string, out *log.Logger) error {
8484
return err
8585
}
8686

87-
if err := m.validate(w); err != nil {
87+
if err = m.validate(w); err != nil {
8888
return err
8989
}
9090

@@ -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 = c.validate(); 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 = c.validate(); 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)