Add version check for spec
We need this version check during our initial work so that runc does not fail silently while make changes to runc to match the spec work going on. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
b2d9d99610
commit
4c829ea2ad
|
@ -42,7 +42,7 @@ user named `daemon` defined within that file-system.
|
|||
|
||||
```json
|
||||
{
|
||||
"version": "0.1",
|
||||
"version": "0.1.1",
|
||||
"platform": {
|
||||
"os": "linux",
|
||||
"arch": "amd64"
|
||||
|
|
8
main.go
8
main.go
|
@ -10,7 +10,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
version = "0.1"
|
||||
version = "0.1.1"
|
||||
usage = `Open Container Project runtime
|
||||
|
||||
runc is a command line client for running applications packaged according to the Open Container Format (OCF) and is
|
||||
|
@ -79,13 +79,13 @@ func main() {
|
|||
}
|
||||
// default action is to execute a container
|
||||
app.Action = func(context *cli.Context) {
|
||||
if os.Geteuid() != 0 {
|
||||
logrus.Fatal("runc should be run as root")
|
||||
}
|
||||
spec, err := loadSpec(context.Args().First())
|
||||
if err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
if os.Geteuid() != 0 {
|
||||
logrus.Fatal("runc should be run as root")
|
||||
}
|
||||
status, err := execContainer(context, spec)
|
||||
if err != nil {
|
||||
logrus.Fatalf("Container start failed: %v", err)
|
||||
|
|
|
@ -107,10 +107,10 @@ var namespaceMapping = map[string]configs.NamespaceType{
|
|||
}
|
||||
|
||||
// loadSpec loads the specification from the provided path.
|
||||
// If the path is empty then the default path will be "container.json"
|
||||
// If the path is empty then the default path will be "config.json"
|
||||
func loadSpec(path string) (*Spec, error) {
|
||||
if path == "" {
|
||||
path = "container.json"
|
||||
path = "config.json"
|
||||
}
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
|
@ -124,7 +124,16 @@ func loadSpec(path string) (*Spec, error) {
|
|||
if err := json.NewDecoder(f).Decode(&s); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return s, nil
|
||||
return s, checkSpecVersion(s)
|
||||
}
|
||||
|
||||
// checkSpecVersion makes sure that the spec version matches runc's while we are in the initial
|
||||
// development period. It is better to hard fail than have missing fields or options in the spec.
|
||||
func checkSpecVersion(s *Spec) error {
|
||||
if s.Version != version {
|
||||
return fmt.Errorf("spec version is not compatible with runc version %q: spec %q", version, s.Version)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func createLibcontainerConfig(spec *Spec) (*configs.Config, error) {
|
||||
|
|
Loading…
Reference in New Issue