Skip to content

Commit ada160a

Browse files
committed
verify os and arch, following golang doc
Signed-off-by: liang chenye <[email protected]>
1 parent 30dfd9a commit ada160a

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

validate.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ var bundleValidateCommand = cli.Command{
6363
var spec rspec.Spec
6464
if err = json.NewDecoder(sf).Decode(&spec); err != nil {
6565
logrus.Fatal(err)
66-
} else {
67-
if spec.Platform.OS != "linux" {
68-
logrus.Fatalf("Operation system '%s' of the bundle is not supported yet.", spec.Platform.OS)
69-
}
7066
}
7167

7268
rootfsPath := path.Join(inputPath, spec.Root.Path)
@@ -75,6 +71,7 @@ var bundleValidateCommand = cli.Command{
7571
} else if !fi.IsDir() {
7672
logrus.Fatalf("Rootfs: %v is not a directory.", spec.Root.Path)
7773
}
74+
7875
bundleValidate(spec, rootfsPath)
7976
logrus.Infof("Bundle validation succeeded.")
8077
},
@@ -83,6 +80,7 @@ var bundleValidateCommand = cli.Command{
8380
func bundleValidate(spec rspec.Spec, rootfs string) {
8481
checkMandatoryField(spec)
8582
checkSemVer(spec.Version)
83+
checkPlatform(spec.Platform)
8684
checkProcess(spec.Process, rootfs)
8785
checkMounts(spec.Mounts, rootfs)
8886
checkLinux(spec.Linux, rootfs)
@@ -106,6 +104,30 @@ func checkMounts(mounts []rspec.Mount, rootfs string) {
106104
}
107105
}
108106

107+
func checkPlatform(platform rspec.Platform) {
108+
validCombins := map[string][]string{
109+
"darwin": {"386", "amd64", "arm", "arm64"},
110+
"dragonfly": {"amd64"},
111+
"freebsd": {"386", "amd64", "arm"},
112+
"linux": {"386", "amd64", "arm", "arm64", "ppc64", "ppc64le", "mips64", "mips64le"},
113+
"netbsd": {"386", "amd64", "arm"},
114+
"openbsd": {"386", "amd64", "arm"},
115+
"plan9": {"386", "amd64"},
116+
"solaris": {"amd64"},
117+
"windows": {"386", "amd64"}}
118+
for os, archs := range validCombins {
119+
if os == platform.OS {
120+
for _, arch := range archs {
121+
if arch == platform.Arch {
122+
return
123+
}
124+
}
125+
logrus.Fatalf("Combination of '%s' and '%s' is invalid.", platform.OS, platform.Arch)
126+
}
127+
}
128+
logrus.Fatalf("Operation system '%s' of the bundle is not supported yet.", platform.OS)
129+
}
130+
109131
func checkProcess(process rspec.Process, rootfs string) {
110132
for index := 0; index < len(process.Capabilities); index++ {
111133
capability := process.Capabilities[index]

0 commit comments

Comments
 (0)