summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2022-01-15 20:39:16 +0100
committerGitHub <noreply@github.com>2022-01-15 20:39:16 +0100
commit3c9e41bb5393e0a857d8755bb50345544cc31b50 (patch)
tree9f2af691f56081271e7fff6971ddd7e5fe45271a
parentfff9e8755c298bfe2b3b0c33c4b96ffd43a1eab6 (diff)
parent14940a067d007af445560a0a7eb414f6547a7cd4 (diff)
downloadpodman-3c9e41bb5393e0a857d8755bb50345544cc31b50.tar.gz
podman-3c9e41bb5393e0a857d8755bb50345544cc31b50.tar.bz2
podman-3c9e41bb5393e0a857d8755bb50345544cc31b50.zip
Merge pull request #12572 from rhatdan/image
Remove two GetImages functions from API
-rw-r--r--pkg/api/handlers/compat/images.go54
-rw-r--r--pkg/api/handlers/libpod/images.go43
-rw-r--r--pkg/api/handlers/types.go40
-rw-r--r--pkg/api/handlers/utils/images.go40
-rw-r--r--pkg/api/server/register_images.go2
-rw-r--r--pkg/domain/infra/abi/images_list.go11
6 files changed, 48 insertions, 142 deletions
diff --git a/pkg/api/handlers/compat/images.go b/pkg/api/handlers/compat/images.go
index c1cc99da4..f08a7ee41 100644
--- a/pkg/api/handlers/compat/images.go
+++ b/pkg/api/handlers/compat/images.go
@@ -11,6 +11,7 @@ import (
"github.com/containers/buildah"
"github.com/containers/common/libimage"
"github.com/containers/common/pkg/config"
+ "github.com/containers/common/pkg/filters"
"github.com/containers/image/v5/manifest"
"github.com/containers/image/v5/types"
"github.com/containers/podman/v3/libpod"
@@ -404,25 +405,52 @@ func GetImage(w http.ResponseWriter, r *http.Request) {
}
func GetImages(w http.ResponseWriter, r *http.Request) {
- images, err := utils.GetImages(w, r)
- if err != nil {
- utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "Failed get images"))
+ decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder)
+ runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
+ query := struct {
+ All bool
+ Digests bool
+ Filter string // Docker 1.24 compatibility
+ }{
+ // This is where you can override the golang default value for one of fields
+ }
+
+ if err := decoder.Decode(&query, r.URL.Query()); err != nil {
+ utils.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest,
+ errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
+ return
+ }
+ if _, found := r.URL.Query()["digests"]; found && query.Digests {
+ utils.UnSupportedParameter("digests")
return
}
- summaries := make([]*entities.ImageSummary, 0, len(images))
- for _, img := range images {
- // If the image is a manifest list, extract as much as we can.
- if isML, _ := img.IsManifestList(r.Context()); isML {
- continue
+ filterList, err := filters.FiltersFromRequest(r)
+ if err != nil {
+ utils.Error(w, "Something went wrong.", http.StatusInternalServerError, err)
+ return
+ }
+ if !utils.IsLibpodRequest(r) {
+ if len(query.Filter) > 0 { // Docker 1.24 compatibility
+ filterList = append(filterList, "reference="+query.Filter)
}
+ filterList = append(filterList, "manifest=false")
+ }
- is, err := handlers.ImageToImageSummary(img)
- if err != nil {
- utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "Failed transform image summaries"))
- return
+ imageEngine := abi.ImageEngine{Libpod: runtime}
+
+ listOptions := entities.ImageListOptions{All: query.All, Filter: filterList}
+ summaries, err := imageEngine.List(r.Context(), listOptions)
+ if err != nil {
+ utils.Error(w, "Something went wrong.", http.StatusInternalServerError, err)
+ return
+ }
+
+ if !utils.IsLibpodRequest(r) {
+ // docker adds sha256: in front of the ID
+ for _, s := range summaries {
+ s.ID = "sha256:" + s.ID
}
- summaries = append(summaries, is)
}
utils.WriteResponse(w, http.StatusOK, summaries)
}
diff --git a/pkg/api/handlers/libpod/images.go b/pkg/api/handlers/libpod/images.go
index 6e23845f0..d3dbf3023 100644
--- a/pkg/api/handlers/libpod/images.go
+++ b/pkg/api/handlers/libpod/images.go
@@ -12,7 +12,6 @@ import (
"github.com/containers/buildah"
"github.com/containers/common/libimage"
- "github.com/containers/common/pkg/filters"
"github.com/containers/image/v5/manifest"
"github.com/containers/image/v5/types"
"github.com/containers/podman/v3/libpod"
@@ -103,48 +102,6 @@ func GetImage(w http.ResponseWriter, r *http.Request) {
utils.WriteResponse(w, http.StatusOK, inspect)
}
-func GetImages(w http.ResponseWriter, r *http.Request) {
- decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder)
- runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
- query := struct {
- All bool
- Digests bool
- Filter string // Docker 1.24 compatibility
- }{
- // This is where you can override the golang default value for one of fields
- }
-
- if err := decoder.Decode(&query, r.URL.Query()); err != nil {
- utils.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest,
- errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
- return
- }
- if _, found := r.URL.Query()["digests"]; found && query.Digests {
- utils.UnSupportedParameter("digests")
- return
- }
-
- filterList, err := filters.FiltersFromRequest(r)
- if err != nil {
- utils.Error(w, "Something went wrong.", http.StatusInternalServerError, err)
- return
- }
- if !utils.IsLibpodRequest(r) && len(query.Filter) > 0 { // Docker 1.24 compatibility
- filterList = append(filterList, "reference="+query.Filter)
- }
-
- imageEngine := abi.ImageEngine{Libpod: runtime}
-
- listOptions := entities.ImageListOptions{All: query.All, Filter: filterList}
- summaries, err := imageEngine.List(r.Context(), listOptions)
- if err != nil {
- utils.Error(w, "Something went wrong.", http.StatusInternalServerError, err)
- return
- }
-
- utils.WriteResponse(w, http.StatusOK, summaries)
-}
-
func PruneImages(w http.ResponseWriter, r *http.Request) {
var (
err error
diff --git a/pkg/api/handlers/types.go b/pkg/api/handlers/types.go
index 588758b2c..3b821d9e7 100644
--- a/pkg/api/handlers/types.go
+++ b/pkg/api/handlers/types.go
@@ -184,46 +184,6 @@ type ExecStartConfig struct {
Width uint16 `json:"w"`
}
-func ImageToImageSummary(l *libimage.Image) (*entities.ImageSummary, error) {
- options := &libimage.InspectOptions{WithParent: true, WithSize: true}
- imageData, err := l.Inspect(context.TODO(), options)
- if err != nil {
- return nil, errors.Wrapf(err, "failed to obtain summary for image %s", l.ID())
- }
-
- containers, err := l.Containers()
- if err != nil {
- return nil, errors.Wrapf(err, "failed to obtain Containers for image %s", l.ID())
- }
- containerCount := len(containers)
-
- isDangling, err := l.IsDangling(context.TODO())
- if err != nil {
- return nil, errors.Wrapf(err, "failed to check if image %s is dangling", l.ID())
- }
-
- is := entities.ImageSummary{
- // docker adds sha256: in front of the ID
- ID: "sha256:" + l.ID(),
- ParentId: imageData.Parent,
- RepoTags: imageData.RepoTags,
- RepoDigests: imageData.RepoDigests,
- Created: l.Created().Unix(),
- Size: imageData.Size,
- SharedSize: 0,
- VirtualSize: imageData.VirtualSize,
- Labels: imageData.Labels,
- Containers: containerCount,
- ReadOnly: l.IsReadOnly(),
- Dangling: isDangling,
- Names: l.Names(),
- Digest: string(imageData.Digest),
- ConfigDigest: "", // TODO: libpod/image didn't set it but libimage should
- History: imageData.NamesHistory,
- }
- return &is, nil
-}
-
func ImageDataToImageInspect(ctx context.Context, l *libimage.Image) (*ImageInspect, error) {
options := &libimage.InspectOptions{WithParent: true, WithSize: true}
info, err := l.Inspect(context.Background(), options)
diff --git a/pkg/api/handlers/utils/images.go b/pkg/api/handlers/utils/images.go
index 3f3f48193..639de9915 100644
--- a/pkg/api/handlers/utils/images.go
+++ b/pkg/api/handlers/utils/images.go
@@ -6,7 +6,6 @@ import (
"strings"
"github.com/containers/common/libimage"
- "github.com/containers/common/pkg/filters"
"github.com/containers/image/v5/docker"
storageTransport "github.com/containers/image/v5/storage"
"github.com/containers/image/v5/transports/alltransports"
@@ -16,7 +15,6 @@ import (
"github.com/containers/podman/v3/pkg/util"
"github.com/containers/storage"
"github.com/docker/distribution/reference"
- "github.com/gorilla/schema"
"github.com/pkg/errors"
)
@@ -91,44 +89,6 @@ func ParseStorageReference(name string) (types.ImageReference, error) {
return imageRef, nil
}
-// GetImages is a common function used to get images for libpod and other compatibility
-// mechanisms
-func GetImages(w http.ResponseWriter, r *http.Request) ([]*libimage.Image, error) {
- decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder)
- runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
- query := struct {
- All bool
- Digests bool
- Filter string // Docker 1.24 compatibility
- }{
- // This is where you can override the golang default value for one of fields
- }
-
- if err := decoder.Decode(&query, r.URL.Query()); err != nil {
- return nil, err
- }
- if _, found := r.URL.Query()["digests"]; found && query.Digests {
- UnSupportedParameter("digests")
- }
-
- filterList, err := filters.FiltersFromRequest(r)
- if err != nil {
- return nil, err
- }
- if !IsLibpodRequest(r) && len(query.Filter) > 0 { // Docker 1.24 compatibility
- filterList = append(filterList, "reference="+query.Filter)
- }
-
- if !query.All {
- // Filter intermediate images unless we want to list *all*.
- // NOTE: it's a positive filter, so `intermediate=false` means
- // to display non-intermediate images.
- filterList = append(filterList, "intermediate=false")
- }
- listOptions := &libimage.ListImagesOptions{Filters: filterList}
- return runtime.LibimageRuntime().ListImages(r.Context(), nil, listOptions)
-}
-
func GetImage(r *http.Request, name string) (*libimage.Image, error) {
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
image, _, err := runtime.LibimageRuntime().LookupImage(name, nil)
diff --git a/pkg/api/server/register_images.go b/pkg/api/server/register_images.go
index d9cda8579..df48253e2 100644
--- a/pkg/api/server/register_images.go
+++ b/pkg/api/server/register_images.go
@@ -840,7 +840,7 @@ func (s *APIServer) registerImagesHandlers(r *mux.Router) error {
// $ref: "#/responses/LibpodImageSummaryResponse"
// 500:
// $ref: '#/responses/InternalError'
- r.Handle(VersionedPath("/libpod/images/json"), s.APIHandler(libpod.GetImages)).Methods(http.MethodGet)
+ r.Handle(VersionedPath("/libpod/images/json"), s.APIHandler(compat.GetImages)).Methods(http.MethodGet)
// swagger:operation POST /libpod/images/load libpod ImageLoadLibpod
// ---
// tags:
diff --git a/pkg/domain/infra/abi/images_list.go b/pkg/domain/infra/abi/images_list.go
index 2ec4ad244..47b47b065 100644
--- a/pkg/domain/infra/abi/images_list.go
+++ b/pkg/domain/infra/abi/images_list.go
@@ -26,9 +26,9 @@ func (ir *ImageEngine) List(ctx context.Context, opts entities.ImageListOptions)
summaries := []*entities.ImageSummary{}
for _, img := range images {
- digests := make([]string, len(img.Digests()))
- for j, d := range img.Digests() {
- digests[j] = string(d)
+ repoDigests, err := img.RepoDigests()
+ if err != nil {
+ return nil, errors.Wrapf(err, "getting repoDigests from image %q", img.ID())
}
isDangling, err := img.IsDangling(ctx)
if err != nil {
@@ -37,11 +37,12 @@ func (ir *ImageEngine) List(ctx context.Context, opts entities.ImageListOptions)
e := entities.ImageSummary{
ID: img.ID(),
- // ConfigDigest: string(img.ConfigDigest),
+ // TODO: libpod/image didn't set it but libimage should
+ // ConfigDigest: string(img.ConfigDigest),
Created: img.Created().Unix(),
Dangling: isDangling,
Digest: string(img.Digest()),
- RepoDigests: digests,
+ RepoDigests: repoDigests,
History: img.NamesHistory(),
Names: img.Names(),
ReadOnly: img.IsReadOnly(),