diff options
-rw-r--r-- | libpod/events.go | 23 | ||||
-rw-r--r-- | pkg/api/handlers/utils/images.go | 13 | ||||
-rw-r--r-- | test/apiv2/10-images.at | 8 |
3 files changed, 32 insertions, 12 deletions
diff --git a/libpod/events.go b/libpod/events.go index 7560940a5..3cbde8c5e 100644 --- a/libpod/events.go +++ b/libpod/events.go @@ -3,6 +3,7 @@ package libpod import ( "context" "fmt" + "sync" "github.com/containers/libpod/v2/libpod/events" "github.com/pkg/errors" @@ -86,7 +87,6 @@ func (r *Runtime) Events(ctx context.Context, options events.ReadOptions) error // GetEvents reads the event log and returns events based on input filters func (r *Runtime) GetEvents(ctx context.Context, filters []string) ([]*events.Event, error) { - var readErr error eventChannel := make(chan *events.Event) options := events.ReadOptions{ EventChannel: eventChannel, @@ -98,17 +98,20 @@ func (r *Runtime) GetEvents(ctx context.Context, filters []string) ([]*events.Ev if err != nil { return nil, err } + + logEvents := make([]*events.Event, 0, len(eventChannel)) + readLock := sync.Mutex{} + readLock.Lock() go func() { - readErr = eventer.Read(ctx, options) + for e := range eventChannel { + logEvents = append(logEvents, e) + } + readLock.Unlock() }() - if readErr != nil { - return nil, readErr - } - logEvents := make([]*events.Event, 0, len(eventChannel)) - for e := range eventChannel { - logEvents = append(logEvents, e) - } - return logEvents, nil + + readErr := eventer.Read(ctx, options) + readLock.Lock() // Wait for the events to be consumed. + return logEvents, readErr } // GetLastContainerEvent takes a container name or ID and an event status and returns diff --git a/pkg/api/handlers/utils/images.go b/pkg/api/handlers/utils/images.go index 195e71b75..bf981b547 100644 --- a/pkg/api/handlers/utils/images.go +++ b/pkg/api/handlers/utils/images.go @@ -60,6 +60,7 @@ func GetImages(w http.ResponseWriter, r *http.Request) ([]*image.Image, error) { All bool Filters map[string][]string `schema:"filters"` Digests bool + Filter string // Docker 1.24 compatibility }{ // This is where you can override the golang default value for one of fields } @@ -76,8 +77,16 @@ func GetImages(w http.ResponseWriter, r *http.Request) ([]*image.Image, error) { err error ) - if len(query.Filters) > 0 { - for k, v := range query.Filters { + queryFilters := query.Filters + if !IsLibpodRequest(r) && len(query.Filter) > 0 { // Docker 1.24 compatibility + if queryFilters == nil { + queryFilters = make(map[string][]string) + } + queryFilters["reference"] = append(queryFilters["reference"], query.Filter) + } + + if len(queryFilters) > 0 { + for k, v := range queryFilters { filters = append(filters, fmt.Sprintf("%s=%s", k, strings.Join(v, "="))) } images, err = runtime.ImageRuntime().GetImagesWithFilters(filters) diff --git a/test/apiv2/10-images.at b/test/apiv2/10-images.at index 1c7ba8948..a204df65c 100644 --- a/test/apiv2/10-images.at +++ b/test/apiv2/10-images.at @@ -26,6 +26,14 @@ t GET libpod/images/${iid:0:12}/json 200 \ .Id=$iid \ .RepoTags[0]=$IMAGE +# Docker API V1.24 filter parameter compatibility +t GET images/json?filter=$IMAGE 200 \ + length=1 \ + .[0].Names[0]=$IMAGE + +# Negative test case +t GET images/json?filter=nonesuch 200 length=0 + # FIXME: docker API incompatibility: libpod returns 'id', docker 'sha256:id' t GET images/$iid/json 200 \ .Id=sha256:$iid \ |