Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions runsc/specutils/specutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"strconv"
"strings"
"time"
"bytes"

"github.com/cenkalti/backoff"
"github.com/mohae/deepcopy"
Expand Down Expand Up @@ -215,8 +216,14 @@ func ReadSpecFromFile(bundleDir string, specFile *os.File, conf *config.Config)
return nil, fmt.Errorf("error reading spec from file %q: %v", specFile.Name(), err)
}
var spec specs.Spec
if err := json.Unmarshal(specBytes, &spec); err != nil {
return nil, fmt.Errorf("error unmarshaling spec from file %q: %v\n %s", specFile.Name(), err, string(specBytes))
decoder := json.NewDecoder(bytes.NewReader(specBytes))
decoder.DisallowUnknownFields()
if errLooseDecode := decoder.Decode(&spec); errLooseDecode != nil {
if errStrictDecode := json.Unmarshal(specBytes, &spec); errStrictDecode != nil {
return nil, fmt.Errorf("error unmarshaling spec from file %q: %v\n %s", specFile.Name(), errStrictDecode, string(specBytes))
} else {
log.Warningf("OCI spec file %q contains fields unknown to `runsc`: %v. Ignoring these fields and continuing anyway.", specFile.Name(), errLooseDecode)
}
}
if err := ValidateSpec(&spec); err != nil {
return nil, err
Expand Down