diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-05-22 18:36:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-22 18:36:09 +0200 |
commit | d58497bbc2949af81ddbeb2ebe1d307d8a57d285 (patch) | |
tree | 0f7b197097bbb9ec682c23a318e86d36b687018a /pkg/domain | |
parent | 6aa802d8012a78ac95e4fe2017a5b54ec8d4b8de (diff) | |
parent | f51e0d0597757da72fd7a10085998052684e396b (diff) | |
download | podman-d58497bbc2949af81ddbeb2ebe1d307d8a57d285.tar.gz podman-d58497bbc2949af81ddbeb2ebe1d307d8a57d285.tar.bz2 podman-d58497bbc2949af81ddbeb2ebe1d307d8a57d285.zip |
Merge pull request #6332 from jwhonce/jira/884
V2 enable remote logs and testing
Diffstat (limited to 'pkg/domain')
-rw-r--r-- | pkg/domain/infra/tunnel/containers.go | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/pkg/domain/infra/tunnel/containers.go b/pkg/domain/infra/tunnel/containers.go index 30c4a8359..beba55c2b 100644 --- a/pkg/domain/infra/tunnel/containers.go +++ b/pkg/domain/infra/tunnel/containers.go @@ -4,7 +4,9 @@ import ( "context" "io" "os" + "strconv" "strings" + "time" "github.com/containers/common/pkg/config" "github.com/containers/image/v5/docker/reference" @@ -336,9 +338,36 @@ func (ic *ContainerEngine) ContainerCreate(ctx context.Context, s *specgen.SpecG return &entities.ContainerCreateReport{Id: response.ID}, nil } -func (ic *ContainerEngine) ContainerLogs(ctx context.Context, containers []string, options entities.ContainerLogsOptions) error { - // The endpoint is not ready yet and requires some more work. - return errors.New("not implemented yet") +func (ic *ContainerEngine) ContainerLogs(_ context.Context, nameOrIds []string, options entities.ContainerLogsOptions) error { + since := options.Since.Format(time.RFC3339) + tail := strconv.FormatInt(options.Tail, 10) + stdout := options.Writer != nil + opts := containers.LogOptions{ + Follow: &options.Follow, + Since: &since, + Stderr: &stdout, + Stdout: &stdout, + Tail: &tail, + Timestamps: &options.Timestamps, + Until: nil, + } + + var err error + outCh := make(chan string) + ctx, cancel := context.WithCancel(context.Background()) + go func() { + err = containers.Logs(ic.ClientCxt, nameOrIds[0], opts, outCh, outCh) + cancel() + }() + + for { + select { + case <-ctx.Done(): + return err + case line := <-outCh: + _, _ = io.WriteString(options.Writer, line) + } + } } func (ic *ContainerEngine) ContainerAttach(ctx context.Context, nameOrId string, options entities.AttachOptions) error { |