From 18d7fcb5eb1966c4d3748a50c625c01c1ebd9f5b Mon Sep 17 00:00:00 2001 From: Peter Hunt Date: Wed, 3 Apr 2019 10:14:14 -0400 Subject: Update completions and docs to use k8s file as log driver Signed-off-by: Peter Hunt --- completions/bash/podman | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'completions/bash') diff --git a/completions/bash/podman b/completions/bash/podman index 60d5fde52..b2b27756d 100644 --- a/completions/bash/podman +++ b/completions/bash/podman @@ -486,6 +486,7 @@ __podman_complete_log_drivers() { none splunk syslog + k8s-file " -- "$cur" ) ) } @@ -500,6 +501,7 @@ __podman_complete_log_options() { local logentries_options="logentries-token" local syslog_options="env labels syslog-address syslog-facility syslog-format syslog-tls-ca-cert syslog-tls-cert syslog-tls-key syslog-tls-skip-verify tag" local splunk_options="env labels splunk-caname splunk-capath splunk-format splunk-gzip splunk-gzip-level splunk-index splunk-insecureskipverify splunk-source splunk-sourcetype splunk-token splunk-url splunk-verify-connection tag" + local k8s_file_options="env labels max-file max-size" local all_options="$fluentd_options $gcplogs_options $gelf_options $journald_options $logentries_options $json_file_options $syslog_options $splunk_options" @@ -525,6 +527,9 @@ __podman_complete_log_options() { json-file) COMPREPLY=( $( compgen -W "$json_file_options" -S = -- "$cur" ) ) ;; + k8s-file) + COMPREPLY=( $( compgen -W "$k8s_file_options" -S = -- "$cur" ) ) + ;; logentries) COMPREPLY=( $( compgen -W "$logentries_options" -S = -- "$cur" ) ) ;; -- cgit v1.2.3-54-g00ecf From f61fa28d39298def261dded2644b8dcf45366415 Mon Sep 17 00:00:00 2001 From: Peter Hunt Date: Sat, 18 May 2019 19:39:11 -0400 Subject: Added --log-driver and journald logging Signed-off-by: Peter Hunt --- cmd/podman/shared/container.go | 5 +++++ cmd/podman/shared/create.go | 7 ++++++- completions/bash/podman | 2 +- libpod/container.go | 7 +++++++ libpod/container_log.go | 5 +++++ libpod/oci.go | 5 ++--- libpod/oci_linux.go | 8 +++++++- libpod/options.go | 19 +++++++++++++++++++ libpod/runtime_ctr.go | 3 ++- pkg/inspect/inspect.go | 2 +- pkg/spec/createconfig.go | 3 +++ 11 files changed, 58 insertions(+), 8 deletions(-) (limited to 'completions/bash') 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 { -- cgit v1.2.3-54-g00ecf