@@ -51,6 +51,7 @@ var uniklog = logrus.WithField("subsystem", "unikontainers")
5151var ErrQueueProxy = errors .New ("this a queue proxy container" )
5252var ErrNotUnikernel = errors .New ("this is not a unikernel container" )
5353var ErrNotExistingNS = errors .New ("the namespace does not exist" )
54+ var ErrMissingLinuxSpec = errors .New ("invalid OCI spec: linux section is required" )
5455
5556// Unikontainer holds the data necessary to create, manage and delete unikernel containers
5657type Unikontainer struct {
@@ -70,6 +71,10 @@ func New(bundlePath string, containerID string, rootDir string, cfg *UruncConfig
7071 return nil , err
7172 }
7273
74+ if spec == nil || spec .Linux == nil {
75+ return nil , ErrMissingLinuxSpec
76+ }
77+
7378 containerName := spec .Annotations ["io.kubernetes.cri.container-name" ]
7479 if containerName == "queue-proxy" {
7580 uniklog .Warn ("This is a queue-proxy container. Adding IP env." )
@@ -125,6 +130,9 @@ func Get(containerID string, rootDir string) (*Unikontainer, error) {
125130 if err != nil {
126131 return nil , err
127132 }
133+ if spec == nil || spec .Linux == nil {
134+ return nil , ErrMissingLinuxSpec
135+ }
128136 u .BaseDir = containerDir
129137 u .RootDir = rootDir
130138 u .Spec = spec
@@ -357,7 +365,7 @@ func (u *Unikontainer) Exec(metrics m.Writer) error {
357365
358366 // ExecArgs
359367 // If memory limit is set in spec, use it instead of the config default value
360- if u .Spec .Linux .Resources .Memory != nil {
368+ if u .Spec .Linux .Resources != nil && u . Spec . Linux . Resources .Memory != nil {
361369 if u .Spec .Linux .Resources .Memory .Limit != nil {
362370 if * u .Spec .Linux .Resources .Memory .Limit > 0 {
363371 vmmArgs .MemSizeB = uint64 (* u .Spec .Linux .Resources .Memory .Limit ) // nolint:gosec
0 commit comments