github.com/containers/podman/v2@v2.2.2-0.20210501105131-c1e07d070c4c/pkg/domain/infra/tunnel/events.go (about) 1 package tunnel 2 3 import ( 4 "context" 5 // "fmt" 6 "strings" 7 8 "github.com/containers/podman/v2/libpod/events" 9 "github.com/containers/podman/v2/pkg/bindings/system" 10 "github.com/containers/podman/v2/pkg/domain/entities" 11 "github.com/pkg/errors" 12 ) 13 14 func (ic *ContainerEngine) Events(ctx context.Context, opts entities.EventsOptions) error { 15 filters := make(map[string][]string) 16 if len(opts.Filter) > 0 { 17 for _, filter := range opts.Filter { 18 split := strings.Split(filter, "=") 19 if len(split) < 2 { 20 return errors.Errorf("invalid filter %q", filter) 21 } 22 filters[split[0]] = append(filters[split[0]], strings.Join(split[1:], "=")) 23 } 24 } 25 binChan := make(chan entities.Event) 26 go func() { 27 for e := range binChan { 28 opts.EventChan <- entities.ConvertToLibpodEvent(e) 29 } 30 close(opts.EventChan) 31 }() 32 return system.Events(ic.ClientCxt, binChan, nil, &opts.Since, &opts.Until, filters, &opts.Stream) 33 } 34 35 // GetLastContainerEvent takes a container name or ID and an event status and returns 36 // the last occurrence of the container event 37 func (ic *ContainerEngine) GetLastContainerEvent(ctx context.Context, nameOrID string, containerEvent events.Status) (*events.Event, error) { 38 // check to make sure the event.Status is valid 39 if _, err := events.StringToStatus(containerEvent.String()); err != nil { 40 return nil, err 41 } 42 var event events.Event 43 return &event, nil 44 45 /* 46 FIXME: We need new bindings for this section 47 filters := []string{ 48 fmt.Sprintf("container=%s", nameOrID), 49 fmt.Sprintf("event=%s", containerEvent), 50 "type=container", 51 } 52 53 containerEvents, err := system.GetEvents(ctx, entities.EventsOptions{Filter: filters}) 54 if err != nil { 55 return nil, err 56 } 57 if len(containerEvents) < 1 { 58 return nil, errors.Wrapf(events.ErrEventNotFound, "%s not found", containerEvent.String()) 59 } 60 // return the last element in the slice 61 return containerEvents[len(containerEvents)-1], nil 62 */ 63 }