Skip to content

Commit

Permalink
gcrane: Use page size of 10,000 for googley things (#1645)
Browse files Browse the repository at this point in the history
We dropped down to 1000 for the sake of ECR, but that doesn't make much
sense, really.

Per https://cloud.google.com/artifact-registry/quotas#limits this will
return up to 10k items.
  • Loading branch information
jonjohnsonjr committed Apr 18, 2023
1 parent 375fb61 commit 6f96bba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
13 changes: 8 additions & 5 deletions pkg/v1/google/keychain.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ type googleKeychain struct {
// gcloud configuration in the scope of this one process.
func (gk *googleKeychain) Resolve(target authn.Resource) (authn.Authenticator, error) {
// Only authenticate GCR and AR so it works with authn.NewMultiKeychain to fallback.
host := target.RegistryStr()
if host != "gcr.io" &&
!strings.HasSuffix(host, ".gcr.io") &&
!strings.HasSuffix(host, ".pkg.dev") &&
!strings.HasSuffix(host, ".google.com") {
if !isGoogle(target.RegistryStr()) {
return authn.Anonymous, nil
}

Expand Down Expand Up @@ -90,3 +86,10 @@ func resolve() authn.Authenticator {
}
return authn.Anonymous
}

func isGoogle(host string) bool {
return host == "gcr.io" ||
strings.HasSuffix(host, ".gcr.io") ||
strings.HasSuffix(host, ".pkg.dev") ||
strings.HasSuffix(host, ".google.com")
}
16 changes: 10 additions & 6 deletions pkg/v1/google/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,16 @@ func newLister(repo name.Repository, options ...Option) (*lister, error) {

func (l *lister) list(repo name.Repository) (*Tags, error) {
uri := &url.URL{
Scheme: repo.Registry.Scheme(),
Host: repo.Registry.RegistryStr(),
Path: fmt.Sprintf("/v2/%s/tags/list", repo.RepositoryStr()),
// ECR returns an error if n > 1000:
// https://github.com/google/go-containerregistry/issues/681
RawQuery: "n=1000",
Scheme: repo.Registry.Scheme(),
Host: repo.Registry.RegistryStr(),
Path: fmt.Sprintf("/v2/%s/tags/list", repo.RepositoryStr()),
RawQuery: "n=10000",
}

// ECR returns an error if n > 1000:
// https://github.com/google/go-containerregistry/issues/681
if !isGoogle(repo.RegistryStr()) {
uri.RawQuery = "n=1000"
}

tags := Tags{}
Expand Down

0 comments on commit 6f96bba

Please sign in to comment.