diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-12-14 09:33:42 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-14 09:33:42 -0500 |
commit | 0fd31e29948631c264df21a128b3de2700f7f007 (patch) | |
tree | fa8fe500592a9f845761cec95b96e0cf397acdcf /libpod | |
parent | 803c078d3b844339c5fca0088ffcb759b6256b9b (diff) | |
parent | 74fcd9fef3a31fa94f3487361b5fda1180e8cee2 (diff) | |
download | podman-0fd31e29948631c264df21a128b3de2700f7f007.tar.gz podman-0fd31e29948631c264df21a128b3de2700f7f007.tar.bz2 podman-0fd31e29948631c264df21a128b3de2700f7f007.zip |
Merge pull request #8696 from Luap99/podman-events-until
podman events allow future time for --until
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/events/events.go | 3 | ||||
-rw-r--r-- | libpod/events/journal_linux.go | 16 | ||||
-rw-r--r-- | libpod/events/logfile.go | 12 | ||||
-rw-r--r-- | libpod/options.go | 1 |
4 files changed, 27 insertions, 5 deletions
diff --git a/libpod/events/events.go b/libpod/events/events.go index 4e7267af3..aa0401b62 100644 --- a/libpod/events/events.go +++ b/libpod/events/events.go @@ -216,8 +216,5 @@ func (e EventLogFile) getTail(options ReadOptions) (*tail.Tail, error) { reopen = false } stream := options.Stream - if len(options.Until) > 0 { - stream = false - } return tail.TailFile(e.options.LogFilePath, tail.Config{ReOpen: reopen, Follow: stream, Location: &seek, Logger: tail.DiscardingLogger, Poll: true}) } diff --git a/libpod/events/journal_linux.go b/libpod/events/journal_linux.go index 9a514e302..71c638017 100644 --- a/libpod/events/journal_linux.go +++ b/libpod/events/journal_linux.go @@ -8,6 +8,7 @@ import ( "strconv" "time" + "github.com/containers/podman/v2/pkg/util" "github.com/coreos/go-systemd/v22/journal" "github.com/coreos/go-systemd/v22/sdjournal" "github.com/pkg/errors" @@ -72,6 +73,13 @@ func (e EventJournalD) Read(ctx context.Context, options ReadOptions) error { if err != nil { return errors.Wrapf(err, "failed to generate event options") } + var untilTime time.Time + if len(options.Until) > 0 { + untilTime, err = util.ParseInputTime(options.Until) + if err != nil { + return err + } + } j, err := sdjournal.NewJournal() if err != nil { return err @@ -122,10 +130,14 @@ func (e EventJournalD) Read(ctx context.Context, options ReadOptions) error { return errors.Wrap(err, "failed to get journal cursor") } if prevCursor == newCursor { - if len(options.Until) > 0 || !options.Stream { + if !options.Stream || (len(options.Until) > 0 && time.Now().After(untilTime)) { break } - _ = j.Wait(sdjournal.IndefiniteWait) + t := sdjournal.IndefiniteWait + if len(options.Until) > 0 { + t = time.Until(untilTime) + } + _ = j.Wait(t) continue } prevCursor = newCursor diff --git a/libpod/events/logfile.go b/libpod/events/logfile.go index 57e38b815..05ae3ce52 100644 --- a/libpod/events/logfile.go +++ b/libpod/events/logfile.go @@ -4,7 +4,9 @@ import ( "context" "fmt" "os" + "time" + "github.com/containers/podman/v2/pkg/util" "github.com/containers/storage" "github.com/pkg/errors" ) @@ -51,6 +53,16 @@ func (e EventLogFile) Read(ctx context.Context, options ReadOptions) error { if err != nil { return err } + if len(options.Until) > 0 { + untilTime, err := util.ParseInputTime(options.Until) + if err != nil { + return err + } + go func() { + time.Sleep(time.Until(untilTime)) + t.Stop() + }() + } funcDone := make(chan bool) copy := true go func() { diff --git a/libpod/options.go b/libpod/options.go index bd12c0c34..c2db13560 100644 --- a/libpod/options.go +++ b/libpod/options.go @@ -502,6 +502,7 @@ func WithEventsLogger(logger string) RuntimeOption { } rt.config.Engine.EventsLogger = logger + rt.config.Engine.EventsLogFilePath = filepath.Join(rt.config.Engine.TmpDir, "events", "events.log") return nil } |