summaryrefslogtreecommitdiff
path: root/pkg/specgen
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/specgen')
-rw-r--r--pkg/specgen/generate/container.go42
-rw-r--r--pkg/specgen/generate/pod_create.go9
-rw-r--r--pkg/specgen/pod_validate.go18
-rw-r--r--pkg/specgen/podspecgen.go2
-rw-r--r--pkg/specgen/specgen.go1
5 files changed, 37 insertions, 35 deletions
diff --git a/pkg/specgen/generate/container.go b/pkg/specgen/generate/container.go
index 92a2b4d35..a217125f4 100644
--- a/pkg/specgen/generate/container.go
+++ b/pkg/specgen/generate/container.go
@@ -9,6 +9,7 @@ import (
envLib "github.com/containers/libpod/pkg/env"
"github.com/containers/libpod/pkg/signal"
"github.com/containers/libpod/pkg/specgen"
+ "github.com/pkg/errors"
"golang.org/x/sys/unix"
)
@@ -41,31 +42,37 @@ func CompleteSpec(ctx context.Context, r *libpod.Runtime, s *specgen.SpecGenerat
if err != nil {
return err
}
- sig, err := signal.ParseSignalNameOrNumber(stopSignal)
- if err != nil {
- return err
+ if stopSignal != "" {
+ sig, err := signal.ParseSignalNameOrNumber(stopSignal)
+ if err != nil {
+ return err
+ }
+ s.StopSignal = &sig
}
- s.StopSignal = &sig
+ }
+
+ rtc, err := r.GetConfig()
+ if err != nil {
+ return err
+ }
+ // Get Default Environment
+ defaultEnvs, err := envLib.ParseSlice(rtc.Containers.Env)
+ if err != nil {
+ return errors.Wrap(err, "Env fields in containers.conf failed to parse")
}
// Image envs from the image if they don't exist
- // already
- env, err := newImage.Env(ctx)
+ // already, overriding the default environments
+ imageEnvs, err := newImage.Env(ctx)
if err != nil {
return err
}
- if len(env) > 0 {
- envs, err := envLib.ParseSlice(env)
- if err != nil {
- return err
- }
- for k, v := range envs {
- if _, exists := s.Env[k]; !exists {
- s.Env[v] = k
- }
- }
+ envs, err := envLib.ParseSlice(imageEnvs)
+ if err != nil {
+ return errors.Wrap(err, "Env fields from image failed to parse")
}
+ s.Env = envLib.Join(envLib.Join(defaultEnvs, envs), s.Env)
labels, err := newImage.Labels(ctx)
if err != nil {
@@ -73,6 +80,9 @@ func CompleteSpec(ctx context.Context, r *libpod.Runtime, s *specgen.SpecGenerat
}
// labels from the image that dont exist already
+ if len(labels) > 0 && s.Labels == nil {
+ s.Labels = make(map[string]string)
+ }
for k, v := range labels {
if _, exists := s.Labels[k]; !exists {
s.Labels[k] = v
diff --git a/pkg/specgen/generate/pod_create.go b/pkg/specgen/generate/pod_create.go
index df5775f8b..cd2d69cfb 100644
--- a/pkg/specgen/generate/pod_create.go
+++ b/pkg/specgen/generate/pod_create.go
@@ -5,6 +5,7 @@ import (
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/specgen"
+ "github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
@@ -68,15 +69,17 @@ func createPodOptions(p *specgen.PodSpecGenerator) ([]libpod.PodCreateOption, er
if p.NoManageResolvConf {
options = append(options, libpod.WithPodUseImageResolvConf())
}
+ if len(p.CNINetworks) > 0 {
+ options = append(options, libpod.WithPodNetworks(p.CNINetworks))
+ }
switch p.NetNS.NSMode {
- case specgen.Bridge:
+ case specgen.Bridge, specgen.Default, "":
logrus.Debugf("Pod using default network mode")
case specgen.Host:
logrus.Debugf("Pod will use host networking")
options = append(options, libpod.WithPodHostNetwork())
default:
- logrus.Debugf("Pod joining CNI networks: %v", p.CNINetworks)
- options = append(options, libpod.WithPodNetworks(p.CNINetworks))
+ return nil, errors.Errorf("pods presently do not support network mode %s", p.NetNS.NSMode)
}
if p.NoManageHosts {
diff --git a/pkg/specgen/pod_validate.go b/pkg/specgen/pod_validate.go
index 98d59549e..640447e71 100644
--- a/pkg/specgen/pod_validate.go
+++ b/pkg/specgen/pod_validate.go
@@ -1,7 +1,6 @@
package specgen
import (
- "github.com/containers/libpod/pkg/rootless"
"github.com/containers/libpod/pkg/util"
"github.com/pkg/errors"
)
@@ -33,12 +32,12 @@ func (p *PodSpecGenerator) Validate() error {
}
// PodNetworkConfig
- if err := p.NetNS.validate(); err != nil {
+ if err := validateNetNS(&p.NetNS); err != nil {
return err
}
if p.NoInfra {
- if p.NetNS.NSMode == NoNetwork {
- return errors.New("NoInfra and a none network cannot be used toegther")
+ if p.NetNS.NSMode != Default && p.NetNS.NSMode != "" {
+ return errors.New("NoInfra and network modes cannot be used toegther")
}
if p.StaticIP != nil {
return exclusivePodOptions("NoInfra", "StaticIP")
@@ -85,18 +84,7 @@ func (p *PodSpecGenerator) Validate() error {
return exclusivePodOptions("NoManageHosts", "HostAdd")
}
- if err := p.NetNS.validate(); err != nil {
- return err
- }
-
// Set Defaults
- if p.NetNS.Value == "" {
- if rootless.IsRootless() {
- p.NetNS.NSMode = Slirp
- } else {
- p.NetNS.NSMode = Bridge
- }
- }
if len(p.InfraImage) < 1 {
p.InfraImage = containerConfig.Engine.InfraImage
}
diff --git a/pkg/specgen/podspecgen.go b/pkg/specgen/podspecgen.go
index 682f3f215..11976233a 100644
--- a/pkg/specgen/podspecgen.go
+++ b/pkg/specgen/podspecgen.go
@@ -54,7 +54,7 @@ type PodNetworkConfig struct {
// namespace. This network will, by default, be shared with all
// containers in the pod.
// Cannot be set to FromContainer and FromPod.
- // Setting this to anything except "" conflicts with NoInfra=true.
+ // Setting this to anything except default conflicts with NoInfra=true.
// Defaults to Bridge as root and Slirp as rootless.
// Mandatory.
NetNS Namespace `json:"netns,omitempty"`
diff --git a/pkg/specgen/specgen.go b/pkg/specgen/specgen.go
index 4ad6dd6fb..bb01a5d14 100644
--- a/pkg/specgen/specgen.go
+++ b/pkg/specgen/specgen.go
@@ -47,6 +47,7 @@ type ContainerBasicConfig struct {
// Optional.
Env map[string]string `json:"env,omitempty"`
// Terminal is whether the container will create a PTY.
+ // Optional.
Terminal bool `json:"terminal,omitempty"`
// Stdin is whether the container will keep its STDIN open.
Stdin bool `json:"stdin,omitempty"`