diff --git a/oci/client/build_test.go b/oci/client/build_test.go index f9814724a..233db8744 100644 --- a/oci/client/build_test.go +++ b/oci/client/build_test.go @@ -31,7 +31,7 @@ import ( func TestBuild(t *testing.T) { g := NewWithT(t) - c := NewLocalClient() + c := NewClient(DefaultOptions()) absPath := fmt.Sprintf("%s/deployment.yaml", t.TempDir()) err := copyFile(absPath, "testdata/artifact/deployment.yaml") diff --git a/oci/client/client.go b/oci/client/client.go index 69766dcaa..b5c5d6cc8 100644 --- a/oci/client/client.go +++ b/oci/client/client.go @@ -21,6 +21,7 @@ import ( "github.com/google/go-containerregistry/pkg/crane" gcrv1 "github.com/google/go-containerregistry/pkg/v1" + "github.com/google/go-containerregistry/pkg/v1/remote" "github.com/fluxcd/pkg/oci" ) @@ -40,17 +41,16 @@ func NewClient(opts []crane.Option) *Client { return &Client{options: options} } -// NewLocalClient returns an OCI client configured with the Docker keychain helpers. -func NewLocalClient() *Client { - options := []crane.Option{ - crane.WithUserAgent(oci.UserAgent), +// DefaultOptions returns an array containing crane.WithPlatform +// to set the platform to flux. +func DefaultOptions() []crane.Option { + return []crane.Option{ crane.WithPlatform(&gcrv1.Platform{ Architecture: "flux", OS: "flux", OSVersion: "v2", }), } - return &Client{options: options} } // GetOptions returns the list of crane.Option used by this Client. @@ -65,3 +65,10 @@ func (c *Client) optionsWithContext(ctx context.Context) []crane.Option { } return append(options, c.options...) } + +// WithRetryBackOff returns a function for setting the given backoff on crane.Option. +func WithRetryBackOff(backoff remote.Backoff) crane.Option { + return func(options *crane.Options) { + options.Remote = append(options.Remote, remote.WithRetryBackoff(backoff)) + } +} diff --git a/oci/client/delete_test.go b/oci/client/delete_test.go index 9aab91f4e..aed4c839b 100644 --- a/oci/client/delete_test.go +++ b/oci/client/delete_test.go @@ -31,7 +31,7 @@ import ( func TestDelete(t *testing.T) { g := NewWithT(t) ctx := context.Background() - c := NewLocalClient() + c := NewClient(DefaultOptions()) repo := "test-delete" + randStringRunes(5) tags := []string{"v0.0.1", "v0.0.2", "v0.0.3", "latest"} source := "github.com/fluxcd/fluxv2" diff --git a/oci/client/diff_test.go b/oci/client/diff_test.go index 61acd945e..3f71dba66 100644 --- a/oci/client/diff_test.go +++ b/oci/client/diff_test.go @@ -30,7 +30,7 @@ import ( func TestClient_Diff(t *testing.T) { g := NewWithT(t) ctx := context.Background() - c := NewLocalClient() + c := NewClient(DefaultOptions()) tag := "v0.0.1" repo := "test-push" + randStringRunes(5) diff --git a/oci/client/list_test.go b/oci/client/list_test.go index 1e4dce011..8973809bb 100644 --- a/oci/client/list_test.go +++ b/oci/client/list_test.go @@ -33,7 +33,7 @@ import ( func Test_List(t *testing.T) { g := NewWithT(t) ctx := context.Background() - c := NewLocalClient() + c := NewClient(DefaultOptions()) repo := "test-list" + randStringRunes(5) tags := []string{"v0.0.1", "v0.0.2", "v0.0.3", "v6.0.0", "v6.0.1", "v6.0.2", "v6.0.2-rc.1", "v6.0.2-alpha", "staging-fb3355b"} source := "github.com/fluxcd/fluxv2" diff --git a/oci/client/login_test.go b/oci/client/login_test.go index a0fcf1e82..bb6e9d52e 100644 --- a/oci/client/login_test.go +++ b/oci/client/login_test.go @@ -60,7 +60,7 @@ func Test_Login(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { g := NewWithT(t) - c := NewLocalClient() + c := NewClient(DefaultOptions()) ctx := context.Background() err := c.LoginWithCredentials(tt.creds) g.Expect(err).ToNot(HaveOccurred()) diff --git a/oci/client/push_pull_test.go b/oci/client/push_pull_test.go index d89c31588..a2a407217 100644 --- a/oci/client/push_pull_test.go +++ b/oci/client/push_pull_test.go @@ -35,7 +35,7 @@ import ( func Test_Push_Pull(t *testing.T) { g := NewWithT(t) ctx := context.Background() - c := NewLocalClient() + c := NewClient(DefaultOptions()) testDir := "testdata/artifact" tag := "v0.0.1" source := "github.com/fluxcd/flux2" diff --git a/oci/client/tag_test.go b/oci/client/tag_test.go index 926be10b2..54fa61117 100644 --- a/oci/client/tag_test.go +++ b/oci/client/tag_test.go @@ -29,7 +29,7 @@ import ( func Test_Tag(t *testing.T) { g := NewWithT(t) ctx := context.Background() - c := NewLocalClient() + c := NewClient(DefaultOptions()) testRepo := "test-tag" url := fmt.Sprintf("%s/%s:v0.0.1", dockerReg, testRepo) img, err := random.Image(1024, 1)