summaryrefslogtreecommitdiff
path: root/pkg/specgen
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/specgen')
-rw-r--r--pkg/specgen/create.go13
-rw-r--r--pkg/specgen/namespaces.go15
-rw-r--r--pkg/specgen/validate.go2
3 files changed, 20 insertions, 10 deletions
diff --git a/pkg/specgen/create.go b/pkg/specgen/create.go
index 34f9ffac2..99a99083b 100644
--- a/pkg/specgen/create.go
+++ b/pkg/specgen/create.go
@@ -2,17 +2,17 @@ package specgen
import (
"context"
+ "os"
+
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/libpod/config"
"github.com/containers/libpod/libpod/define"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
- "os"
)
// MakeContainer creates a container based on the SpecGenerator
func (s *SpecGenerator) MakeContainer(rt *libpod.Runtime) (*libpod.Container, error) {
- var pod *libpod.Pod
if err := s.validate(rt); err != nil {
return nil, errors.Wrap(err, "invalid config provided")
}
@@ -21,7 +21,7 @@ func (s *SpecGenerator) MakeContainer(rt *libpod.Runtime) (*libpod.Container, er
return nil, err
}
- options, err := s.createContainerOptions(rt, pod)
+ options, err := s.createContainerOptions(rt)
if err != nil {
return nil, err
}
@@ -45,7 +45,7 @@ func (s *SpecGenerator) MakeContainer(rt *libpod.Runtime) (*libpod.Container, er
return rt.NewContainer(context.Background(), runtimeSpec, options...)
}
-func (s *SpecGenerator) createContainerOptions(rt *libpod.Runtime, pod *libpod.Pod) ([]libpod.CtrCreateOption, error) {
+func (s *SpecGenerator) createContainerOptions(rt *libpod.Runtime) ([]libpod.CtrCreateOption, error) {
var options []libpod.CtrCreateOption
var err error
@@ -60,6 +60,10 @@ func (s *SpecGenerator) createContainerOptions(rt *libpod.Runtime, pod *libpod.P
options = append(options, libpod.WithName(s.Name))
}
if s.Pod != "" {
+ pod, err := rt.LookupPod(s.Pod)
+ if err != nil {
+ return nil, err
+ }
logrus.Debugf("adding container to pod %s", s.Pod)
options = append(options, rt.WithPod(pod))
}
@@ -115,7 +119,6 @@ func (s *SpecGenerator) createContainerOptions(rt *libpod.Runtime, pod *libpod.P
}
options = append(options, namespaceOptions...)
- // TODO NetworkNS still needs to be done!
if len(s.ConmonPidFile) > 0 {
options = append(options, libpod.WithConmonPidFile(s.ConmonPidFile))
}
diff --git a/pkg/specgen/namespaces.go b/pkg/specgen/namespaces.go
index 17b180cde..fa2dee77d 100644
--- a/pkg/specgen/namespaces.go
+++ b/pkg/specgen/namespaces.go
@@ -3,9 +3,9 @@ package specgen
import (
"os"
+ "github.com/containers/common/pkg/capabilities"
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/libpod/image"
- "github.com/containers/libpod/pkg/capabilities"
"github.com/cri-o/ocicni/pkg/ocicni"
spec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/runtime-tools/generate"
@@ -70,9 +70,7 @@ func (n *Namespace) IsPrivate() bool {
return n.NSMode == Private
}
-// validate perform simple validation on the namespace to make sure it is not
-// invalid from the get-go
-func (n *Namespace) validate() error {
+func validateNetNS(n *Namespace) error {
if n == nil {
return nil
}
@@ -82,6 +80,15 @@ func (n *Namespace) validate() error {
default:
return errors.Errorf("invalid network %q", n.NSMode)
}
+ return nil
+}
+
+// validate perform simple validation on the namespace to make sure it is not
+// invalid from the get-go
+func (n *Namespace) validate() error {
+ if n == nil {
+ return nil
+ }
// Path and From Container MUST have a string value set
if n.NSMode == Path || n.NSMode == FromContainer {
if len(n.Value) < 1 {
diff --git a/pkg/specgen/validate.go b/pkg/specgen/validate.go
index 78e4d8ad5..dd5ca3a55 100644
--- a/pkg/specgen/validate.go
+++ b/pkg/specgen/validate.go
@@ -138,7 +138,7 @@ func (s *SpecGenerator) validate(rt *libpod.Runtime) error {
if err := s.IpcNS.validate(); err != nil {
return err
}
- if err := s.NetNS.validate(); err != nil {
+ if err := validateNetNS(&s.NetNS); err != nil {
return err
}
if err := s.PidNS.validate(); err != nil {