aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libpod/container.go27
-rw-r--r--libpod/oci_conmon_exec_linux.go2
-rw-r--r--pkg/specgen/generate/container.go6
-rw-r--r--pkg/specgen/generate/container_create.go1
-rw-r--r--pkg/specgen/generate/kube/kube.go14
-rw-r--r--test/e2e/play_kube_test.go20
6 files changed, 55 insertions, 15 deletions
diff --git a/libpod/container.go b/libpod/container.go
index 457b290b7..4b2af02ab 100644
--- a/libpod/container.go
+++ b/libpod/container.go
@@ -281,21 +281,29 @@ type ContainerNetworkDescriptions map[string]int
// Config accessors
// Unlocked
-// Config returns the configuration used to create the container
+// Config returns the configuration used to create the container.
+// Note that the returned config does not include the actual networks.
+// Use ConfigWithNetworks() if you need them.
func (c *Container) Config() *ContainerConfig {
returnConfig := new(ContainerConfig)
if err := JSONDeepCopy(c.config, returnConfig); err != nil {
return nil
}
+ return returnConfig
+}
- if c != nil {
- networks, err := c.networks()
- if err != nil {
- return nil
- }
+// Config returns the configuration used to create the container.
+func (c *Container) ConfigWithNetworks() *ContainerConfig {
+ returnConfig := c.Config()
+ if returnConfig == nil {
+ return nil
+ }
- returnConfig.Networks = networks
+ networks, err := c.networks()
+ if err != nil {
+ return nil
}
+ returnConfig.Networks = networks
return returnConfig
}
@@ -1269,10 +1277,7 @@ func (c *Container) NetworkMode() string {
// Unlocked accessor for networks
func (c *Container) networks() (map[string]types.PerNetworkOptions, error) {
- if c != nil && c.runtime != nil && c.runtime.state != nil { // can fail if c.networks is called from the tests
- return c.runtime.state.GetNetworks(c)
- }
- return nil, nil
+ return c.runtime.state.GetNetworks(c)
}
// getInterfaceByName returns a formatted interface name for a given
diff --git a/libpod/oci_conmon_exec_linux.go b/libpod/oci_conmon_exec_linux.go
index 6d2f13525..70124bec1 100644
--- a/libpod/oci_conmon_exec_linux.go
+++ b/libpod/oci_conmon_exec_linux.go
@@ -391,7 +391,7 @@ func (r *ConmonOCIRuntime) startExec(c *Container, sessionID string, options *Ex
}
defer processFile.Close()
- args := r.sharedConmonArgs(c, sessionID, c.execBundlePath(sessionID), c.execPidPath(sessionID), c.execLogPath(sessionID), c.execExitFileDir(sessionID), ociLog, define.NoLogging, "")
+ args := r.sharedConmonArgs(c, sessionID, c.execBundlePath(sessionID), c.execPidPath(sessionID), c.execLogPath(sessionID), c.execExitFileDir(sessionID), ociLog, define.NoLogging, c.config.LogTag)
if options.PreserveFDs > 0 {
args = append(args, formatRuntimeOpts("--preserve-fds", fmt.Sprintf("%d", options.PreserveFDs))...)
diff --git a/pkg/specgen/generate/container.go b/pkg/specgen/generate/container.go
index 63caaa77c..d8008b10b 100644
--- a/pkg/specgen/generate/container.go
+++ b/pkg/specgen/generate/container.go
@@ -3,6 +3,7 @@ package generate
import (
"context"
"encoding/json"
+ "fmt"
"os"
"strings"
"time"
@@ -352,7 +353,10 @@ func ConfigToSpec(rt *libpod.Runtime, specg *specgen.SpecGenerator, contaierID s
if err != nil {
return nil, nil, err
}
- conf := c.Config()
+ conf := c.ConfigWithNetworks()
+ if conf == nil {
+ return nil, nil, fmt.Errorf("failed to get config for container %s", c.ID())
+ }
tmpSystemd := conf.Systemd
tmpMounts := conf.Mounts
diff --git a/pkg/specgen/generate/container_create.go b/pkg/specgen/generate/container_create.go
index 19a2b702c..04e24d625 100644
--- a/pkg/specgen/generate/container_create.go
+++ b/pkg/specgen/generate/container_create.go
@@ -425,7 +425,6 @@ func createContainerOptions(rt *libpod.Runtime, s *specgen.SpecGenerator, pod *l
options = append(options, libpod.WithMaxLogSize(s.LogConfiguration.Size))
}
if len(s.LogConfiguration.Options) > 0 && s.LogConfiguration.Options["tag"] != "" {
- // Note: I'm really guessing here.
options = append(options, libpod.WithLogTag(s.LogConfiguration.Options["tag"]))
}
diff --git a/pkg/specgen/generate/kube/kube.go b/pkg/specgen/generate/kube/kube.go
index 4c11e4bff..d56b50fd5 100644
--- a/pkg/specgen/generate/kube/kube.go
+++ b/pkg/specgen/generate/kube/kube.go
@@ -29,6 +29,7 @@ import (
"github.com/docker/go-units"
spec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
+ "github.com/sirupsen/logrus"
)
func ToPodOpt(ctx context.Context, podName string, p entities.PodCreateOptions, podYAML *v1.PodTemplateSpec) (entities.PodCreateOptions, error) {
@@ -153,6 +154,7 @@ func ToSpecGen(ctx context.Context, opts *CtrSpecGenOptions) (*specgen.SpecGener
Driver: opts.LogDriver,
}
+ s.LogConfiguration.Options = make(map[string]string)
for _, o := range opts.LogOptions {
split := strings.SplitN(o, "=", 2)
if len(split) < 2 {
@@ -170,7 +172,17 @@ func ToSpecGen(ctx context.Context, opts *CtrSpecGenOptions) (*specgen.SpecGener
}
s.LogConfiguration.Size = logSize
default:
- s.LogConfiguration.Options[split[0]] = split[1]
+ switch len(split[1]) {
+ case 0:
+ return nil, errors.Wrapf(define.ErrInvalidArg, "invalid log option")
+ default:
+ // tags for journald only
+ if s.LogConfiguration.Driver == "" || s.LogConfiguration.Driver == define.JournaldLogging {
+ s.LogConfiguration.Options[split[0]] = split[1]
+ } else {
+ logrus.Warnf("Can only set tags with journald log driver but driver is %q", s.LogConfiguration.Driver)
+ }
+ }
}
}
diff --git a/test/e2e/play_kube_test.go b/test/e2e/play_kube_test.go
index 45414ec04..1b223637e 100644
--- a/test/e2e/play_kube_test.go
+++ b/test/e2e/play_kube_test.go
@@ -3536,4 +3536,24 @@ ENV OPENJ9_JAVA_OPTIONS=%q
Expect(kube.ErrorToString()).To(ContainSubstring("ambiguous configuration: the same config map foo is present in YAML and in --configmaps"))
})
})
+
+ It("podman play kube --log-opt = tag test", func() {
+ pod := getPod()
+ err := generateKubeYaml("pod", pod, kubeYaml)
+ Expect(err).To(BeNil())
+
+ kube := podmanTest.Podman([]string{"play", "kube", kubeYaml, "--log-driver", "journald", "--log-opt", "tag={{.ImageName}}"})
+ kube.WaitWithDefaultTimeout()
+ Expect(kube).Should(Exit(0))
+
+ start := podmanTest.Podman([]string{"start", getCtrNameInPod(pod)})
+ start.WaitWithDefaultTimeout()
+ Expect(start).Should(Exit(0))
+
+ inspect := podmanTest.Podman([]string{"inspect", getCtrNameInPod(pod)})
+ inspect.WaitWithDefaultTimeout()
+ Expect(start).Should(Exit(0))
+ Expect((inspect.InspectContainerToJSON()[0]).HostConfig.LogConfig.Tag).To(Equal("{{.ImageName}}"))
+
+ })
})