aboutsummaryrefslogtreecommitdiff
path: root/pkg/domain/infra/tunnel/events.go
blob: 93da3aeb4b2eda8e55a2e1de0b1c09f97c7e75e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package tunnel

import (
	"context"
	"strings"

	"github.com/containers/libpod/pkg/bindings/system"
	"github.com/containers/libpod/pkg/domain/entities"
	"github.com/pkg/errors"
)

func (ic *ContainerEngine) Events(ctx context.Context, opts entities.EventsOptions) error {
	filters := make(map[string][]string)
	if len(opts.Filter) > 0 {
		for _, filter := range opts.Filter {
			split := strings.Split(filter, "=")
			if len(split) < 2 {
				return errors.Errorf("invalid filter %q", filter)
			}
			filters[split[0]] = append(filters[split[0]], strings.Join(split[1:], "="))
		}
	}
	binChan := make(chan entities.Event)
	go func() {
		for e := range binChan {
			opts.EventChan <- entities.ConvertToLibpodEvent(e)
		}
	}()
	return system.Events(ic.ClientCxt, binChan, nil, &opts.Since, &opts.Until, filters)
}