-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
2 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |