Skip to content

Commit e619e18

Browse files
authored
Warn about unknown fields in OCI config
1 parent fc2f4df commit e619e18

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

runsc/specutils/specutils.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"strconv"
2727
"strings"
2828
"time"
29+
"bytes"
2930

3031
"github.com/cenkalti/backoff"
3132
"github.com/mohae/deepcopy"
@@ -215,8 +216,14 @@ func ReadSpecFromFile(bundleDir string, specFile *os.File, conf *config.Config)
215216
return nil, fmt.Errorf("error reading spec from file %q: %v", specFile.Name(), err)
216217
}
217218
var spec specs.Spec
218-
if err := json.Unmarshal(specBytes, &spec); err != nil {
219-
return nil, fmt.Errorf("error unmarshaling spec from file %q: %v\n %s", specFile.Name(), err, string(specBytes))
219+
decoder := json.NewDecoder(bytes.NewReader(specBytes))
220+
decoder.DisallowUnknownFields()
221+
if err := decoder.Decode(&spec); err != nil {
222+
if err2 := json.Unmarshal(specBytes, &spec); err2 != nil {
223+
return nil, fmt.Errorf("error unmarshaling spec from file %q: %v\n %s", specFile.Name(), err2, string(specBytes))
224+
} else {
225+
log.Warningf("Problem with spec file %q: %v. Consider removing unnecessary fields.", specFile.Name(), err)
226+
}
220227
}
221228
if err := ValidateSpec(&spec); err != nil {
222229
return nil, err

0 commit comments

Comments
 (0)