Skip to content

Commit eda1ac7

Browse files
committed
validate: With --host-specific, compare config platform vs. runtime
This is a bit aggressive. For example, maybe a Linux kernel was compiled with CONFIG_64BIT, CONFIG_X86, and CONFIG_X86_X32. Your ocitools build may be 386 and validating an amd64 image (or vice versa) and both would run fine. I'm not sure x32 is supported by Go, but you could have and x32 container if somebody submits it to the OCI specs as an extention arch. So I'd rather have an arch mismatch be a warning than a fatal error. But in most cases, you'll want the arch to match (e.g. no arm configs if ocitools is amd64), so I don't want to ignore the missmatch completely. In the absence of warning-support, an overly strict check seems safer than an overly lax check, because the caller can always read the error messages and decide if they care ;). Signed-off-by: W. Trevor King <wking@tremily.us>
1 parent ea1d5dd commit eda1ac7

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

cmd/ocitools/validate.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"path"
1111
"path/filepath"
1212
"reflect"
13+
"runtime"
1314
"strings"
1415
"unicode"
1516
"unicode/utf8"
@@ -170,6 +171,16 @@ func checkPlatform(spec rspec.Spec, rootfs string, hostCheck bool) (msgs []strin
170171
}
171172
msgs = append(msgs, fmt.Sprintf("Operation system %q of the bundle is not supported yet.", platform.OS))
172173

174+
if hostCheck {
175+
if platform.OS != runtime.GOOS {
176+
msgs = append(msgs, fmt.Sprintf("platform.os is %s, not %s", platform.OS, runtime.GOOS))
177+
}
178+
if platform.Arch != runtime.GOARCH {
179+
// warning, not an error, since kernels can support multiple architectures
180+
msgs = append(msgs, fmt.Sprintf("platform.arch is %s, not %s", platform.Arch, runtime.GOARCH))
181+
}
182+
}
183+
173184
return
174185
}
175186

0 commit comments

Comments
 (0)