aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hunt <pehunt@redhat.com>2019-05-18 19:39:11 -0400
committerPeter Hunt <pehunt@redhat.com>2019-05-28 11:10:57 -0400
commitf61fa28d39298def261dded2644b8dcf45366415 (patch)
tree36081cf2a2644264099ffcf32836b8c85f9ddb04
parent18d7fcb5eb1966c4d3748a50c625c01c1ebd9f5b (diff)
downloadpodman-f61fa28d39298def261dded2644b8dcf45366415.tar.gz
podman-f61fa28d39298def261dded2644b8dcf45366415.tar.bz2
podman-f61fa28d39298def261dded2644b8dcf45366415.zip
Added --log-driver and journald logging
Signed-off-by: Peter Hunt <pehunt@redhat.com>
-rw-r--r--cmd/podman/shared/container.go5
-rw-r--r--cmd/podman/shared/create.go7
-rw-r--r--completions/bash/podman2
-rw-r--r--libpod/container.go7
-rw-r--r--libpod/container_log.go5
-rw-r--r--libpod/oci.go5
-rw-r--r--libpod/oci_linux.go8
-rw-r--r--libpod/options.go19
-rw-r--r--libpod/runtime_ctr.go3
-rw-r--r--pkg/inspect/inspect.go2
-rw-r--r--pkg/spec/createconfig.go3
11 files changed, 58 insertions, 8 deletions
diff --git a/cmd/podman/shared/container.go b/cmd/podman/shared/container.go
index fe447d10d..55cc529e0 100644
--- a/cmd/podman/shared/container.go
+++ b/cmd/podman/shared/container.go
@@ -631,6 +631,10 @@ func GetCtrInspectInfo(config *libpod.ContainerConfig, ctrInspectData *inspect.C
memKernel, memReservation, memSwap, memSwappiness, memDisableOOMKiller := getMemoryInfo(spec)
pidsLimit := getPidsInfo(spec)
cgroup := getCgroup(spec)
+ logConfig := inspect.LogConfig{
+ config.LogDriver,
+ make(map[string]string),
+ }
data := &inspect.ContainerData{
ctrInspectData,
@@ -681,6 +685,7 @@ func GetCtrInspectInfo(config *libpod.ContainerConfig, ctrInspectData *inspect.C
Ulimits: createArtifact.Resources.Ulimit,
SecurityOpt: createArtifact.SecurityOpts,
Tmpfs: createArtifact.Tmpfs,
+ LogConfig: &logConfig,
},
&inspect.CtrConfig{
Hostname: spec.Hostname,
diff --git a/cmd/podman/shared/create.go b/cmd/podman/shared/create.go
index 3c9b17804..4e105cad4 100644
--- a/cmd/podman/shared/create.go
+++ b/cmd/podman/shared/create.go
@@ -603,6 +603,11 @@ func ParseCreateOpts(ctx context.Context, c *GenericCLIResults, runtime *libpod.
memorySwappiness := c.Int64("memory-swappiness")
+ logDriver := "k8s-file"
+ if c.Changed("log-driver") {
+ logDriver = c.String("log-driver")
+ }
+
config := &cc.CreateConfig{
Annotations: annotations,
BuiltinImgVolumes: ImageVolumes,
@@ -635,7 +640,7 @@ func ParseCreateOpts(ctx context.Context, c *GenericCLIResults, runtime *libpod.
IPAddress: c.String("ip"),
Labels: labels,
//LinkLocalIP: c.StringSlice("link-local-ip"), // Not implemented yet
- LogDriver: c.String("log-driver"),
+ LogDriver: logDriver,
LogDriverOpt: c.StringSlice("log-opt"),
MacAddress: c.String("mac-address"),
Name: c.String("name"),
diff --git a/completions/bash/podman b/completions/bash/podman
index b2b27756d..5b23e12dc 100644
--- a/completions/bash/podman
+++ b/completions/bash/podman
@@ -486,7 +486,7 @@ __podman_complete_log_drivers() {
none
splunk
syslog
- k8s-file
+ k8s-file
" -- "$cur" ) )
}
diff --git a/libpod/container.go b/libpod/container.go
index c07f4c78d..9ac08cba0 100644
--- a/libpod/container.go
+++ b/libpod/container.go
@@ -368,6 +368,8 @@ type ContainerConfig struct {
CgroupParent string `json:"cgroupParent"`
// LogPath log location
LogPath string `json:"logPath"`
+ // LogDriver driver for logs
+ LogDriver string `json:"logDriver"`
// File containing the conmon PID
ConmonPidFile string `json:"conmonPidFile,omitempty"`
// RestartPolicy indicates what action the container will take upon
@@ -775,6 +777,11 @@ func (c *Container) RestartRetries() uint {
return c.config.RestartRetries
}
+// LogDriver returns the log driver for this container
+func (c *Container) LogDriver() string {
+ return c.config.LogDriver
+}
+
// RuntimeName returns the name of the runtime
func (c *Container) RuntimeName() string {
return c.runtime.ociRuntime.name
diff --git a/libpod/container_log.go b/libpod/container_log.go
index e998ad316..f11db8014 100644
--- a/libpod/container_log.go
+++ b/libpod/container_log.go
@@ -53,6 +53,11 @@ func (r *Runtime) Log(containers []*Container, options *LogOptions, logChannel c
// ReadLog reads a containers log based on the input options and returns loglines over a channel
func (c *Container) ReadLog(options *LogOptions, logChannel chan *LogLine) error {
+ // TODO Skip sending logs until journald logs can be read
+ // TODO make this not a magic string
+ if c.LogDriver() == "journald" {
+ return ErrNotImplemented
+ }
t, tailLog, err := getLogFile(c.LogPath(), options)
if err != nil {
// If the log file does not exist, this is not fatal.
diff --git a/libpod/oci.go b/libpod/oci.go
index abc6214b9..152c8e73e 100644
--- a/libpod/oci.go
+++ b/libpod/oci.go
@@ -367,8 +367,6 @@ func (r *OCIRuntime) execContainer(c *Container, cmd, capAdd, env []string, tty
args := []string{}
// TODO - should we maintain separate logpaths for exec sessions?
- args = append(args, "--log", c.LogPath())
-
args = append(args, "exec")
if cwd != "" {
@@ -402,9 +400,10 @@ func (r *OCIRuntime) execContainer(c *Container, cmd, capAdd, env []string, tty
args = append(args, "--env", envVar)
}
- // Append container ID and command
+ // Append container ID, name and command
args = append(args, c.ID())
args = append(args, cmd...)
+ args = append(args, c.Name())
logrus.Debugf("Starting runtime %s with following arguments: %v", r.path, args)
diff --git a/libpod/oci_linux.go b/libpod/oci_linux.go
index 1c1e4a203..b3a21948e 100644
--- a/libpod/oci_linux.go
+++ b/libpod/oci_linux.go
@@ -217,7 +217,6 @@ func (r *OCIRuntime) createOCIContainer(ctr *Container, cgroupParent string, res
args = append(args, "-r", r.path)
args = append(args, "-b", ctr.bundlePath())
args = append(args, "-p", filepath.Join(ctr.state.RunDir, "pidfile"))
- args = append(args, "-l", ctr.LogPath())
args = append(args, "--exit-dir", r.exitsDir)
if ctr.config.ConmonPidFile != "" {
args = append(args, "--conmon-pidfile", ctr.config.ConmonPidFile)
@@ -237,6 +236,13 @@ func (r *OCIRuntime) createOCIContainer(ctr *Container, cgroupParent string, res
if r.logSizeMax >= 0 {
args = append(args, "--log-size-max", fmt.Sprintf("%v", r.logSizeMax))
}
+
+ logDriver := "k8s-file"
+ if ctr.LogDriver() != "" {
+ logDriver = ctr.LogDriver()
+ }
+ args = append(args, "-l", fmt.Sprintf("%s:%s", logDriver, ctr.LogPath()))
+
if r.noPivot {
args = append(args, "--no-pivot")
}
diff --git a/libpod/options.go b/libpod/options.go
index 7ec7dfe63..d6eb97609 100644
--- a/libpod/options.go
+++ b/libpod/options.go
@@ -979,6 +979,25 @@ func WithStaticIP(ip net.IP) CtrCreateOption {
}
}
+// WithLogDriver sets the log driver for the container
+func WithLogDriver(driver string) CtrCreateOption {
+ return func(ctr *Container) error {
+ if ctr.valid {
+ return ErrCtrFinalized
+ }
+ if driver == "" {
+ return errors.Wrapf(ErrInvalidArg, "log driver must be set")
+ }
+ if driver != "journald" && driver != "k8s-file" && driver != "json-file" {
+ return errors.Wrapf(ErrInvalidArg, "invalid log driver")
+ }
+
+ ctr.config.LogDriver = driver
+
+ return nil
+ }
+}
+
// WithLogPath sets the path to the log file.
func WithLogPath(path string) CtrCreateOption {
return func(ctr *Container) error {
diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go
index c7758055f..25db10d33 100644
--- a/libpod/runtime_ctr.go
+++ b/libpod/runtime_ctr.go
@@ -196,7 +196,8 @@ func (r *Runtime) newContainer(ctx context.Context, rSpec *spec.Spec, options ..
}
}
- if ctr.config.LogPath == "" {
+ // TODO magic string
+ if ctr.config.LogPath == "" && ctr.config.LogDriver != "journald" {
ctr.config.LogPath = filepath.Join(ctr.config.StaticDir, "ctr.log")
}
diff --git a/pkg/inspect/inspect.go b/pkg/inspect/inspect.go
index 693755aa8..2082bb3a6 100644
--- a/pkg/inspect/inspect.go
+++ b/pkg/inspect/inspect.go
@@ -103,7 +103,7 @@ type CtrConfig struct {
// LogConfig holds the log information for a container
type LogConfig struct {
- Type string `json:"Type"` // TODO
+ Type string `json:"Type"`
Config map[string]string `json:"Config"` //idk type, TODO
}
diff --git a/pkg/spec/createconfig.go b/pkg/spec/createconfig.go
index 9979e773c..e4501aaac 100644
--- a/pkg/spec/createconfig.go
+++ b/pkg/spec/createconfig.go
@@ -319,6 +319,9 @@ func (c *CreateConfig) getContainerCreateOptions(runtime *libpod.Runtime, pod *l
if logPath != "" {
options = append(options, libpod.WithLogPath(logPath))
}
+
+ options = append(options, libpod.WithLogDriver(c.LogDriver))
+
if c.IPAddress != "" {
ip := net.ParseIP(c.IPAddress)
if ip == nil {