aboutsummaryrefslogtreecommitdiff
path: root/pkg/api/handlers/libpod/images_pull.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2022-08-24 06:00:03 -0400
committerGitHub <noreply@github.com>2022-08-24 06:00:03 -0400
commitd4e54fa9992d369596bcaf969bea8dbbcb7335ab (patch)
tree8f1d53081039b64330060d3e3e16717239206e2c /pkg/api/handlers/libpod/images_pull.go
parentbbd8b64a4247c591738f7ebbac683f48aa7351a5 (diff)
parent3bf52aa338b33de719e087e15402081568453284 (diff)
downloadpodman-d4e54fa9992d369596bcaf969bea8dbbcb7335ab.tar.gz
podman-d4e54fa9992d369596bcaf969bea8dbbcb7335ab.tar.bz2
podman-d4e54fa9992d369596bcaf969bea8dbbcb7335ab.zip
Merge pull request #15351 from marshall-lee/images-pull-simple
Simplify ImagesPull for when Quiet flag is on
Diffstat (limited to 'pkg/api/handlers/libpod/images_pull.go')
-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():