diff --git a/pkg/v1/remote/write.go b/pkg/v1/remote/write.go index f4369e2a0..6bfce75e7 100644 --- a/pkg/v1/remote/write.go +++ b/pkg/v1/remote/write.go @@ -210,7 +210,7 @@ func (w *writer) initiateUpload(ctx context.Context, from, mount, origin string) req.Header.Set("Content-Type", "application/json") resp, err := w.client.Do(req.WithContext(ctx)) if err != nil { - if origin != "" && origin != w.repo.RegistryStr() { + if from != "" { // https://github.com/google/go-containerregistry/issues/1679 logs.Warn.Printf("retrying without mount: %v", err) return w.initiateUpload(ctx, "", "", "") @@ -220,7 +220,7 @@ func (w *writer) initiateUpload(ctx context.Context, from, mount, origin string) defer resp.Body.Close() if err := transport.CheckError(resp, http.StatusCreated, http.StatusAccepted); err != nil { - if origin != "" && origin != w.repo.RegistryStr() { + if from != "" { // https://github.com/google/go-containerregistry/issues/1404 logs.Warn.Printf("retrying without mount: %v", err) return w.initiateUpload(ctx, "", "", "") @@ -360,8 +360,16 @@ func (w *writer) uploadOne(ctx context.Context, l v1.Layer) error { if err := w.maybeUpdateScopes(ctx, ml); err != nil { return err } + from = ml.Reference.Context().RepositoryStr() origin = ml.Reference.Context().RegistryStr() + + // This keeps breaking with DockerHub. + // https://github.com/google/go-containerregistry/issues/1741 + if w.repo.RegistryStr() == name.DefaultRegistry && origin != w.repo.RegistryStr() { + from = "" + origin = "" + } } location, mounted, err := w.initiateUpload(ctx, from, mount, origin) diff --git a/pkg/v1/remote/write_test.go b/pkg/v1/remote/write_test.go index 3f2696d7f..77504fcc1 100644 --- a/pkg/v1/remote/write_test.go +++ b/pkg/v1/remote/write_test.go @@ -315,6 +315,8 @@ func TestInitiateUploadNoMountsBadStatus(t *testing.T) { "from": []string{"baz/bar"}, }.Encode() + first := true + w, closer, err := setupWriter(expectedRepo, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodPost { t.Errorf("Method; got %v, want %v", r.Method, http.MethodPost) @@ -322,9 +324,17 @@ func TestInitiateUploadNoMountsBadStatus(t *testing.T) { if r.URL.Path != expectedPath { t.Errorf("URL; got %v, want %v", r.URL.Path, expectedPath) } - if r.URL.RawQuery != expectedQuery { - t.Errorf("RawQuery; got %v, want %v", r.URL.RawQuery, expectedQuery) + if first { + if r.URL.RawQuery != expectedQuery { + t.Errorf("RawQuery; got %v, want %v", r.URL.RawQuery, expectedQuery) + } + first = false + } else { + if r.URL.RawQuery != "" { + t.Errorf("RawQuery; got %v, want %v", r.URL.RawQuery, "") + } } + http.Error(w, "Unknown", http.StatusNoContent) })) if err != nil {