Merge pull request #730 from 14rcole/kpod-image-filter

fix bug with creation time in ParseFilter()
This commit is contained in:
Mrunal Patel 2017-08-04 19:24:37 -07:00 committed by GitHub
commit ce8bd648de
2 changed files with 27 additions and 16 deletions

View file

@ -151,7 +151,7 @@ func outputImages(store storage.Store, images []storage.Image, format string, ha
if quiet {
fmt.Printf("%-64s\n", img.ID)
// We only want to print each id once
break
continue
}
params := imageOutputParams{

View file

@ -44,13 +44,21 @@ func ParseFilter(store storage.Store, filter string) (*FilterParams, error) {
params.label = pair[1]
case "before":
if img, err := findImageInSlice(images, pair[1]); err == nil {
params.beforeImage = img.Created
info, err := getImageInspectInfo(store, img)
if err != nil {
return nil, err
}
params.beforeImage = info.Created
} else {
return nil, fmt.Errorf("no such id: %s", pair[0])
}
case "since":
if img, err := findImageInSlice(images, pair[1]); err == nil {
params.sinceImage = img.Created
info, err := getImageInspectInfo(store, img)
if err != nil {
return nil, err
}
params.sinceImage = info.Created
} else {
return nil, fmt.Errorf("no such id: %s``", pair[0])
}
@ -68,20 +76,10 @@ func matchesFilter(store storage.Store, image storage.Image, name string, params
return true
}
storeRef, err := is.Transport.ParseStoreReference(store, "@"+image.ID)
info, err := getImageInspectInfo(store, image)
if err != nil {
return false
}
img, err := storeRef.NewImage(nil)
if err != nil {
return false
}
defer img.Close()
info, err := img.Inspect()
if err != nil {
return false
}
if params.dangling != "" && !matchesDangling(name, params.dangling) {
return false
} else if params.label != "" && !matchesLabel(info, store, params.label) {
@ -151,7 +149,7 @@ func MatchesID(id, argID string) bool {
// But redis:alpine, ry/redis, library, and io/library/redis will not
func MatchesReference(name, argName string) bool {
if argName == "" {
return true
return false
}
splitName := strings.Split(name, ":")
// If the arg contains a tag, we handle it differently than if it does not
@ -273,7 +271,7 @@ func GetImagesMatchingFilter(store storage.Store, filter *FilterParams, argName
names = append(names, "<none>")
}
for _, name := range names {
if filter == nil || (matchesFilter(store, image, name, filter) || MatchesReference(name, argName)) {
if (filter == nil && argName == "") || (filter != nil && matchesFilter(store, image, name, filter)) || MatchesReference(name, argName) {
newImage := image
newImage.Names = []string{name}
filteredImages = append(filteredImages, newImage)
@ -282,3 +280,16 @@ func GetImagesMatchingFilter(store storage.Store, filter *FilterParams, argName
}
return filteredImages, nil
}
func getImageInspectInfo(store storage.Store, image storage.Image) (*types.ImageInspectInfo, error) {
storeRef, err := is.Transport.ParseStoreReference(store, "@"+image.ID)
if err != nil {
return nil, err
}
img, err := storeRef.NewImage(nil)
if err != nil {
return nil, err
}
defer img.Close()
return img.Inspect()
}