Skip to content
Merged
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
2 changes: 1 addition & 1 deletion oci/client/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
17 changes: 12 additions & 5 deletions oci/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

Comment thread
darkowlzz marked this conversation as resolved.
"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"
)
Expand All @@ -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 {
Comment thread
darkowlzz marked this conversation as resolved.
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.
Expand All @@ -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 {
Comment thread
darkowlzz marked this conversation as resolved.
return func(options *crane.Options) {
options.Remote = append(options.Remote, remote.WithRetryBackoff(backoff))
}
}
2 changes: 1 addition & 1 deletion oci/client/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion oci/client/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion oci/client/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion oci/client/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion oci/client/push_pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion oci/client/tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down