summaryrefslogtreecommitdiff
path: root/pkg/api/handlers/libpod
diff options
context:
space:
mode:
authorVladimir Kochnev <hashtable@yandex.ru>2022-08-17 03:04:55 +0300
committerVladimir Kochnev <hashtable@yandex.ru>2022-08-18 23:48:41 +0300
commitb9fb60c68acb57e56edae0b35dd408f454d32be5 (patch)
tree53f11d37a81add090b9eb9c34c277bf8078c3d7e /pkg/api/handlers/libpod
parent31bb53f5ffccfa98e991901417b06fc6ab7b19d9 (diff)
downloadpodman-b9fb60c68acb57e56edae0b35dd408f454d32be5.tar.gz
podman-b9fb60c68acb57e56edae0b35dd408f454d32be5.tar.bz2
podman-b9fb60c68acb57e56edae0b35dd408f454d32be5.zip
Simplify ImagesPull for when Quiet flag is on
Refactor ImagesPull the same way the ImagesPush and ManifestPush are done. [NO NEW TESTS NEEDED] Signed-off-by: Vladimir Kochnev <hashtable@yandex.ru>
Diffstat (limited to 'pkg/api/handlers/libpod')
-rw-r--r--pkg/api/handlers/libpod/images_pull.go31
1 files changed, 22 insertions, 9 deletions
diff --git a/pkg/api/handlers/libpod/images_pull.go b/pkg/api/handlers/libpod/images_pull.go
index 7e24ae5ac..57b2e3a78 100644
--- a/pkg/api/handlers/libpod/images_pull.go
+++ b/pkg/api/handlers/libpod/images_pull.go
@@ -82,17 +82,32 @@ func ImagesPull(w http.ResponseWriter, r *http.Request) {
pullOptions.IdentityToken = authConf.IdentityToken
}
- writer := channel.NewWriter(make(chan []byte))
- defer writer.Close()
-
- pullOptions.Writer = writer
-
pullPolicy, err := config.ParsePullPolicy(query.PullPolicy)
if err != nil {
utils.Error(w, http.StatusBadRequest, err)
return
}
+ // Let's keep thing simple when running in quiet mode and pull directly.
+ if query.Quiet {
+ images, err := runtime.LibimageRuntime().Pull(r.Context(), query.Reference, pullPolicy, pullOptions)
+ var report entities.ImagePullReport
+ if err != nil {
+ report.Error = err.Error()
+ }
+ for _, image := range images {
+ report.Images = append(report.Images, image.ID())
+ // Pull last ID from list and publish in 'id' stanza. This maintains previous API contract
+ report.ID = image.ID()
+ }
+ utils.WriteResponse(w, http.StatusOK, report)
+ return
+ }
+
+ writer := channel.NewWriter(make(chan []byte))
+ defer writer.Close()
+ pullOptions.Writer = writer
+
var pulledImages []*libimage.Image
var pullError error
runCtx, cancel := context.WithCancel(r.Context())
@@ -118,10 +133,8 @@ func ImagesPull(w http.ResponseWriter, r *http.Request) {
select {
case s := <-writer.Chan():
report.Stream = string(s)
- if !query.Quiet {
- if err := enc.Encode(report); err != nil {
- logrus.Warnf("Failed to encode json: %v", err)
- }
+ if err := enc.Encode(report); err != nil {
+ logrus.Warnf("Failed to encode json: %v", err)
}
flush()
case <-runCtx.Done():