Skip to content

Commit

Permalink
logging: new mode -l passthrough
Browse files Browse the repository at this point in the history
it allows to pass the current std streams down to the container.

conmon support: containers/conmon#289

[NO TESTS NEEDED] it needs a new conmon.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
  • Loading branch information
giuseppe committed Sep 2, 2021
1 parent 83de22e commit 37929c6
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cmd/podman/common/completion.go
Expand Up @@ -780,7 +780,7 @@ func AutocompleteImageVolume(cmd *cobra.Command, args []string, toComplete strin
// -> "journald", "none", "k8s-file"
func AutocompleteLogDriver(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
// don't show json-file
logDrivers := []string{define.JournaldLogging, define.NoLogging, define.KubernetesLogging}
logDrivers := []string{define.JournaldLogging, define.NoLogging, define.KubernetesLogging, define.PassthroughLogging}
return logDrivers, cobra.ShellCompDirectiveNoFileComp
}

Expand Down
7 changes: 6 additions & 1 deletion cmd/podman/containers/create.go
Expand Up @@ -161,7 +161,9 @@ func create(cmd *cobra.Command, args []string) error {
}
}

fmt.Println(report.Id)
if cliVals.LogDriver != define.PassthroughLogging {
fmt.Println(report.Id)
}
return nil
}

Expand All @@ -188,6 +190,9 @@ func CreateInit(c *cobra.Command, vals entities.ContainerCreateOptions, isInfra
vals.UserNS = "private"
}
}
if registry.IsRemote() && cliVals.LogDriver == define.PassthroughLogging {
return vals, errors.New("the '--log-driver passthrough' option is not supported in remote mode")
}

if !isInfra {
if c.Flag("shm-size").Changed {
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/containers/run.go
Expand Up @@ -200,7 +200,7 @@ func run(cmd *cobra.Command, args []string) error {
return err
}

if runOpts.Detach {
if runOpts.Detach && cliVals.LogDriver != define.PassthroughLogging {
fmt.Println(report.Id)
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion docs/source/markdown/podman-create.1.md
Expand Up @@ -513,7 +513,7 @@ Not implemented

#### **--log-driver**="*k8s-file*"

Logging driver for the container. Currently available options are *k8s-file*, *journald*, and *none*, with *json-file* aliased to *k8s-file* for scripting compatibility.
Logging driver for the container. Currently available options are *k8s-file*, *journald*, *none* and *passthrough*, with *json-file* aliased to *k8s-file* for scripting compatibility.

#### **--log-opt**=*name*=*value*

Expand Down
2 changes: 1 addition & 1 deletion docs/source/markdown/podman-run.1.md
Expand Up @@ -538,7 +538,7 @@ Not implemented.

#### **--log-driver**="*driver*"

Logging driver for the container. Currently available options are **k8s-file**, **journald**, and **none**, with **json-file** aliased to **k8s-file** for scripting compatibility.
Logging driver for the container. Currently available options are **k8s-file**, **journald**, **none** and **passthrough**, with **json-file** aliased to **k8s-file** for scripting compatibility.

#### **--log-opt**=*name*=*value*

Expand Down
4 changes: 4 additions & 0 deletions libpod/container_api.go
Expand Up @@ -229,6 +229,10 @@ func (c *Container) Kill(signal uint) error {
// This function returns when the attach finishes. It does not hold the lock for
// the duration of its runtime, only using it at the beginning to verify state.
func (c *Container) Attach(streams *define.AttachStreams, keys string, resize <-chan define.TerminalSize) error {
switch c.LogDriver() {
case define.PassthroughLogging:
return errors.Wrapf(define.ErrNoLogs, "this container is using the 'passthrough' log driver, cannot attach")
}
if !c.batched {
c.lock.Lock()
if err := c.syncContainer(); err != nil {
Expand Down
4 changes: 3 additions & 1 deletion libpod/container_log.go
Expand Up @@ -18,7 +18,7 @@ import (
var logDrivers []string

func init() {
logDrivers = append(logDrivers, define.KubernetesLogging, define.NoLogging)
logDrivers = append(logDrivers, define.KubernetesLogging, define.NoLogging, define.PassthroughLogging)
}

// Log is a runtime function that can read one or more container logs.
Expand All @@ -34,6 +34,8 @@ func (r *Runtime) Log(ctx context.Context, containers []*Container, options *log
// ReadLog reads a containers log based on the input options and returns log lines over a channel.
func (c *Container) ReadLog(ctx context.Context, options *logs.LogOptions, logChannel chan *logs.LogLine) error {
switch c.LogDriver() {
case define.PassthroughLogging:
return errors.Wrapf(define.ErrNoLogs, "this container is using the 'passthrough' log driver, cannot read logs")
case define.NoLogging:
return errors.Wrapf(define.ErrNoLogs, "this container is using the 'none' log driver, cannot read logs")
case define.JournaldLogging:
Expand Down
3 changes: 3 additions & 0 deletions libpod/define/config.go
Expand Up @@ -78,6 +78,9 @@ const JSONLogging = "json-file"
// NoLogging is the string conmon expects when specifying to use no log driver whatsoever
const NoLogging = "none"

// PassthroughLogging is the string conmon expects when specifying to use the passthrough driver
const PassthroughLogging = "passthrough"

// Strings used for --sdnotify option to podman
const (
SdNotifyModeContainer = "container"
Expand Down
2 changes: 2 additions & 0 deletions libpod/oci_conmon_linux.go
Expand Up @@ -1285,6 +1285,8 @@ func (r *ConmonOCIRuntime) sharedConmonArgs(ctr *Container, cuuid, bundlePath, p
logDriverArg = define.JournaldLogging
case define.NoLogging:
logDriverArg = define.NoLogging
case define.PassthroughLogging:
logDriverArg = define.PassthroughLogging
case define.JSONLogging:
fallthrough
//lint:ignore ST1015 the default case has to be here
Expand Down
2 changes: 1 addition & 1 deletion libpod/options.go
Expand Up @@ -1114,7 +1114,7 @@ func WithLogDriver(driver string) CtrCreateOption {
switch driver {
case "":
return errors.Wrapf(define.ErrInvalidArg, "log driver must be set")
case define.JournaldLogging, define.KubernetesLogging, define.JSONLogging, define.NoLogging:
case define.JournaldLogging, define.KubernetesLogging, define.JSONLogging, define.NoLogging, define.PassthroughLogging:
break
default:
return errors.Wrapf(define.ErrInvalidArg, "invalid log driver")
Expand Down
2 changes: 1 addition & 1 deletion libpod/runtime_ctr.go
Expand Up @@ -474,7 +474,7 @@ func (r *Runtime) setupContainer(ctx context.Context, ctr *Container) (_ *Contai
}

switch ctr.config.LogDriver {
case define.NoLogging:
case define.NoLogging, define.PassthroughLogging:
break
case define.JournaldLogging:
ctr.initializeJournal(ctx)
Expand Down

0 comments on commit 37929c6

Please sign in to comment.