Skip to content

Commit

Permalink
WIP: Add fallback handler
Browse files Browse the repository at this point in the history
OCI registries don't provide a way to retrieve metadata in the same call
as listing tags.

This means that you have to do a separate API request for each tag if
you want the metadata, which could be very slow for a large number of
tags.

As such, preferably use the selfhosted client as a fallback, but add a
fallback fallback to the oci handler for registries that are
incompatible with the selfhosted API implementation.
  • Loading branch information
aidy committed Feb 27, 2024
1 parent d28f8c6 commit 02d3b96
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"github.com/jetstack/version-checker/pkg/client/acr"
"github.com/jetstack/version-checker/pkg/client/docker"
"github.com/jetstack/version-checker/pkg/client/ecr"
"github.com/jetstack/version-checker/pkg/client/fallback"
"github.com/jetstack/version-checker/pkg/client/gcr"
"github.com/jetstack/version-checker/pkg/client/ghcr"
"github.com/jetstack/version-checker/pkg/client/oci"
"github.com/jetstack/version-checker/pkg/client/quay"
"github.com/jetstack/version-checker/pkg/client/selfhosted"
)
Expand Down Expand Up @@ -76,7 +76,7 @@ func New(ctx context.Context, log *logrus.Entry, opts Options) (*Client, error)
selfhostedClients = append(selfhostedClients, sClient)
}

fallbackClient, err := oci.New()
fallbackClient, err := fallback.New(ctx, log)
if err != nil {
return nil, fmt.Errorf("failed to create fallback client: %s", err)
}
Expand Down
51 changes: 51 additions & 0 deletions pkg/client/fallback/fallback.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package fallback

import (
"context"

"github.com/jetstack/version-checker/pkg/api"
"github.com/jetstack/version-checker/pkg/client/oci"
"github.com/jetstack/version-checker/pkg/client/selfhosted"
"github.com/sirupsen/logrus"
)

type Client struct {
SelfHosted *selfhosted.Client
OCI *oci.Client
}

func New(ctx context.Context, log *logrus.Entry) (*Client, error) {
sh, err := selfhosted.New(ctx, log, new(selfhosted.Options))
if err != nil {
return nil, err
}
oci, err := oci.New()
if err != nil {
return nil, err
}

return &Client{
SelfHosted: sh,
OCI: oci,
}, nil
}

func (c *Client) Name() string {
return "fallback"
}

func (c *Client) Tags(ctx context.Context, host, repo, image string) ([]api.ImageTag, error) {
// TODO: Cache selfhosted/oci by host
if tags, err := c.SelfHosted.Tags(ctx, host, repo, image); err == nil {
return tags, err
}
return c.OCI.Tags(ctx, host, repo, image)
}

func (c *Client) IsHost(host string) bool {
return true
}

func (c *Client) RepoImageFromPath(path string) (string, string) {
return c.SelfHosted.RepoImageFromPath(path)
}

0 comments on commit 02d3b96

Please sign in to comment.