Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust referrers fallback behavior to be optional #1748

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pkg/v1/remote/referrers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"errors"
"io"
"net/http"
"os"
"strings"

"github.com/google/go-containerregistry/pkg/name"
Expand Down Expand Up @@ -71,7 +72,7 @@ func (f *fetcher) fetchReferrers(ctx context.Context, filter map[string]string,
if err != nil {
return nil, err
}
} else {
} else if os.Getenv("GGCR_REF_FALLBACK") != "" {
// The registry doesn't support the Referrers API endpoint, so we'll use the fallback tag scheme.
b, _, err = f.fetchManifest(ctx, fallbackTag(d), []types.MediaType{types.OCIImageIndex})
var terr *transport.Error
Expand All @@ -81,6 +82,9 @@ func (f *fetcher) fetchReferrers(ctx context.Context, filter map[string]string,
} else if err != nil {
return nil, err
}
} else {
// TODO just returning "empty" here doesn't feel quite right -- maybe transport.CheckError again but this time letting http.StatusBadRequest return an error?
return empty.Index, nil
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming back to this almost a year later and feeling like a nice fmt.Errorf is probably more appropriate here. Thoughts? Maybe the variable needs to be opt-out instead of opt-in, also? (GGCR_REF_NO_FALLBACK or GGCR_REF_NEVER_FALLBACK ?)

}

h, sz, err := v1.SHA256(bytes.NewReader(b))
Expand Down
3 changes: 2 additions & 1 deletion pkg/v1/remote/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"io"
"net/http"
"net/url"
"os"
"sort"
"strings"
"sync"
Expand Down Expand Up @@ -595,7 +596,7 @@ func (w *writer) commitManifest(ctx context.Context, t Taggable, ref name.Refere

// If the manifest referred to a subject, we may need to update the fallback tag manifest.
// TODO: If this fails, we'll retry the whole upload. We should retry just this part.
if mf.Subject != nil {
if mf.Subject != nil && os.Getenv("GGCR_REF_FALLBACK") != "" {
h, size, err := v1.SHA256(bytes.NewReader(raw))
if err != nil {
return err
Expand Down
Loading